Skip to content

feat(beta): add ToolPolicyMiddleware for tool access control#2533

Open
amabito wants to merge 2 commits intoag2ai:mainfrom
amabito:feat/tool-policy-middleware
Open

feat(beta): add ToolPolicyMiddleware for tool access control#2533
amabito wants to merge 2 commits intoag2ai:mainfrom
amabito:feat/tool-policy-middleware

Conversation

@amabito
Copy link
Copy Markdown
Contributor

@amabito amabito commented Mar 31, 2026

Why are these changes needed?

Pulls the tool allow/block list logic out of GovernanceMiddleware (#2501,
closed) into its own middleware. Sits on on_tool_execution, checks the
tool name against blocked and allowed lists, returns ToolErrorEvent if denied.

blocked_tools overrides allowed_tools. allowed_tools=None means no
restriction; allowed_tools=[] means deny all. Config is frozen after
construction.

Related issue number

Replaces the tool policy portion of #2501 (closed).
Related: #2531 (BudgetMiddleware), #2532 (CircuitBreakerMiddleware).

Checks

Single-responsibility middleware that blocks disallowed tool calls
based on configurable allow/block lists. Extracted from
GovernanceMiddleware to align with beta v2 composable middleware design.

- ToolPolicyConfig: blocked_tools, allowed_tools
- blocked_tools overrides allowed_tools
- allowed_tools=None means no restriction, [] means deny all
- Immutable config (lists frozen to tuples)
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
autogen/beta/middleware/builtin/__init__.py 93.33% <100.00%> (+0.47%) ⬆️
autogen/beta/middleware/builtin/tool_policy.py 100.00% <100.00%> (ø)

... and 13 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant