Call-owning middleware · PyPI 0.1.0 · Alpha · Apache-2.0

ag2-acgs for AG2 (AutoGen).

Package Specification · Inspected HEAD bbc8d87

Framework maintainer
AG2 · ag2.ai
Upstream repository
ag2ai/ag2
PyPI release
ag2-acgs==0.1.0
Python requirement
>=3.10
Framework constraint
ag2>=1.2.0,<2
Governance engine pin
acgs-lite>=3.0.1,<4
Integration mechanic
Call-owning middleware (wraps tool call)
Hook entry point
ACGSMiddleware.on_tool_execution

01 · Local Setup & Quickstart

Attach governance to one tool-calling agent.

Install the pinned release from PyPI alongside acgs-lite>=3.0.1,<4. Rule evaluation uses deterministic keyword and regex matching locally in Python—no external model or network call is made by the governance check.

Caveat: Independent community package; confirm tool registration routes through the middleware on your target AG2 version.

Shell · PyPI installation

pip install "ag2-acgs==0.1.0"

Python · AG2 (AutoGen) integration

src/ag2_acgs/middleware.py#L140
from ag2 import Agent
from ag2_acgs import ACGSGuard

guard = ACGSGuard()
agent = Agent(
    "assistant",
    config=config,
    tools=[send_email],
    middleware=[guard.middleware],
)

02 · Verdict & Review Mapping

How ACGS-Lite verdicts map to AG2 (AutoGen).

When a tool call is proposed, the adapter formats the tool name and arguments via format_tool_call and evaluates them against the configured Constitution. Blocking rules always take precedence over review rules.

Verdict.ALLOW

Calls matching no blocking or review rules run through BaseMiddleware.on_tool_execution.

Verdict.DENY

Skips execution and returns the ACGS violation message to the agent as the tool output.

Verdict.REVIEW

Prompts human input via context.ask(ToolApprovalRequest(...)); runs only on 'yes', 'y', or '1'.

03 · Public API Surface

Exported symbols and source entry points.

Each adapter keeps its public surface minimal and re-exports the shared GovernanceDecision, Verdict, and ToolCallFormatter types alongside the framework-specific hook or middleware class.

__all__ exports · ag2-acgs

src/ag2_acgs/middleware.py#L140 ↗
ACGSGuardACGSMiddlewareACGSConfigurationErrorUngovernedToolsErrorAPPROVALSDECISION_METADATA_KEYGovernanceDecisionToolCallFormatterVerdictformat_tool_call

Primary hook surface: ACGSMiddleware.on_tool_execution. Custom ToolCallFormatter functions may be supplied if your tool arguments require custom canonical serialization before rule matching.

04 · Scope & Bypass Boundaries

What this adapter does and does not cover.

Verify these framework-specific boundaries when integrating ag2-acgs into an evaluation workflow.

  1. 01

    Fails with UngovernedToolsError before the turn starts if provider-hosted tools, TaskConfig sub-tasks, or sub-agents without ACGS are detected.

  2. 02

    Invalid JSON tool arguments or human-input timeouts fail closed and deny the call.

  3. 03

    In the current 0.1.x adapter series, rule evaluation runs through acgs-lite's ToolCallGovernor path. If your workflow requires SignedReceipt, ExecutionGrant, or SQLite EffectStore reservations, wire those contracts explicitly at the tool executor boundary.

Put one real workflow under your control.

Choose one tool. Define what it may do. Inspect what happens when a request crosses the boundary.