-
Notifications
You must be signed in to change notification settings - Fork 1
Description
[FEATURE] Proxy-level Allowed Tools Control and Enforcement
Feature Description
Add a new proxy feature for user-configurable access control of tool calling, allowing users to define allowed/disallowed lists of tools that LLMs can use/execute. This should support per-model regex-based tool name matching, with both global proxy-wide policies and granular configuration on a per-(backend x modelname) level.
Problem Statement
Currently, models can call any tool without user control at the proxy level. As this proxy aims to enhance user experience in agentic coding workflows, we need configurable access control to let users decide which tools should be allowed, especially when the agent or LLM client doesn't provide precise control.
Proposed Solution
Implement a tiered configuration mechanism with two main components:
- Tool Definition Filtering: Strip disallowed tool definitions from requests sent to the LLM to reduce wasted turns.
- Tool Call Blocking: Use the existing Tool Call Reactor to block disallowed tool calls in LLM responses as a hard stop.
Configuration Architecture
- Global Overrides: Controlled by CLI params, taking precedence over backend-level configuration.
- Per-Backend/Model Settings: Custom configuration for specific (backend x modelname) pairs.
- Policy Modes:
- Allow, then deny (whitelist with exceptions)
- Deny, then allow (blacklist with exceptions)
- Matching: Case-insensitive string matching (including partial matches), with regex support for advanced patterns.
Implementation Approach
Recommended Path: Combine option 1 (reactor-based blocking) with option 2 (definition redaction) for comprehensive control.
Configuration:
- Extend
ToolCallReactorConfiginsrc/core/config/app_config.pywith anaccess_policieslist containing:model_pattern: Regex for matching model namesagent_pattern: Optional regex for agent matchingallowed_patterns: List of regex patterns for allowed toolsblocked_patterns: List of regex patterns for blocked toolsdefault_policy: "allow" or "deny"block_message: Custom message for blocked calls
- Mirror in
config/schemas/tool_call_reactor_config.schema.yamland add environment variable overrides.
Shared Evaluator Service:
- Create
src/core/services/tool_access_policy_service.py - Load policies once, compile regexes
- Expose methods:
filter_definitions(ChatRequest)andis_allowed(model, agent, tool_name)
Request Filtering:
- Add middleware in
RequestProcessorafter redaction - Clone
ChatRequest, drop disallowed tool definitions/tool_choice entries - Stash policy metadata in
request.extra_body["tool_access"]for observability
Reactor Enforcement:
- Register
ToolAccessControlHandlerwith high priority after dangerous-command handler in DI - In
handle(), use evaluator to decide; swallow blocked calls and return configured message with metadata
Context Hygiene:
- Ensure
ToolCallReactorMiddlewarecan derivemodel_name/agentbefore buildingToolCallContext(fallback tocontext["original_request"].modeland response metadata)
Telemetry & UX:
- Log redactions and blocks at info level with policy names
- Increment stats in
ToolCallReactorService - Optionally surface notices to users on first blocks
Use Cases
- Control behavior of closed-source agents or black-box LLM clients
- Set global or per-model allowed/disallowed tool lists
- Prevent specific tools from being used in sensitive workflows
- Override agent behavior when fine-grained control isn't available
Implementation Ideas
See configuration and service details above. Leverage existing Tool Call Reactor infrastructure.
Testing / Documentation
- Unit tests for evaluator (allowed/blocked/default policies) and request middleware
- Reactor handler tests for swallowing behavior
- Integration tests simulating disallowed tool calls
- Update README with sample policy configurations and precedence rules (allowed overrides blocked, global overrides per-model)
- Run focused tests and full pytest suite post-implementation
After wiring, execute: ./.venv/Scripts/python.exe -m pytest