feat(autogen-ext): add OPA tool-call authorization#7524
Open
Prithvi1994 wants to merge 1 commit intomicrosoft:mainfrom
Open
feat(autogen-ext): add OPA tool-call authorization#7524Prithvi1994 wants to merge 1 commit intomicrosoft:mainfrom
Prithvi1994 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Introduces OPAAuthorizedTool, a BaseTool wrapper that intercepts every tool call (and agent handoff) before execution and evaluates it against an Open Policy Agent (OPA) policy via the REST API. - Zero changes to autogen-core or autogen-agentchat - Covers regular tool calls AND agent-to-agent handoffs (transfer_to_X) - fail_open option for graceful degradation when OPA is unavailable - Async-native via httpx, call_id forwarded correctly - Sample Rego policies: RBAC, argument-level constraints, handoff whitelist - Full pytest suite using mocked httpx (no real OPA server needed) Addresses the tool-level authorization gap raised in community discussions around sandboxing, RBAC, and policy enforcement for multi-agent deployments.
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
autogen_ext.tools.opa, a new module inautogen-extthat wraps anyBaseToolwith Open Policy Agent (OPA) authorization, intercepting tool calls before execution.Motivation
Enterprise multi-agent deployments need declarative, auditable access control over which tools agents can invoke — and which agents can hand off to which other agents. Currently AutoGen has no built-in policy enforcement layer at the tool-execution boundary.
With OWASP LLM Top 10 (2025) listing Excessive Agency and Insecure Tool Use as critical vulnerabilities, a policy-as-code solution that integrates with the OPA ecosystem enterprises already use for Kubernetes is a natural fit.
Design
OPAAuthorizedTool(inner_tool, opa_url, policy_path, context)— wraps anyBaseToolrun_json()— the single dispatch point for all tool calls, including agent-to-agent handoff tools (transfer_to_<AgentName>)httpxbefore delegating to inner toolfail_open=True/Falsecontrols behaviour when OPA is unreachable (default: deny)opa_authorize_tools(tools, ...)factory for wrapping tool lists — drop-in replacementUsage
OPA request body sent for every call:
{ "input": { "tool": "delete_file", "args": {"path": "/data/report.csv"}, "context": {"user": "alice", "role": "analyst"} } }Sample Rego policy (bundled in
policies/autogen_tools.rego):adminroledelete_fileonly permitted under/tmp/)transfer_to_X) restricted to a whitelist of approved agentsFiles Changed
python/packages/autogen-ext/src/autogen_ext/tools/opa/__init__.pypython/packages/autogen-ext/src/autogen_ext/tools/opa/_opa_tool.pypython/packages/autogen-ext/src/autogen_ext/tools/opa/_exceptions.pypython/packages/autogen-ext/src/autogen_ext/tools/opa/policies/autogen_tools.regopython/packages/autogen-ext/src/autogen_ext/tools/opa/README.mdpython/packages/autogen-ext/tests/tools/opa/test_opa_tool.pyNo Breaking Changes
Zero modifications to
autogen-coreorautogen-agentchat. Pure extension — anyAssistantAgentacceptingtools=works transparently withOPAAuthorizedTool.Test Plan
Full pytest suite using mocked
httpx(no real OPA server needed):truefalse→OPAAuthorizationErrorfail_open=Trueallows when OPA is unreachablefail_open=FalseraisesOPAConnectionErrorwhen OPA is unreachableopa_authorize_tools()wraps multiple tools correctlytransfer_to_X) intercepted identically to regular toolscall_idforwarded correctly to inner tool