Microsoft Agent Framework + ACP: Policy & Audit Install Guide
Microsoft Agent Framework (MAF) is Microsoft’s successor to AutoGen and Semantic Kernel, GA since April 2026, for building agents and multi-agent workflows in Python and .NET. It has three middleware scopes (agent run, chat, function). The function scope wraps every tool call with a call_next delegate, and that is where ACP hooks in.
acp-governance gives you one middleware class. Pass it when you build the agent and every tool call goes through ACP. Before the tool runs, ACP checks policy. After it runs, ACP scans the output for PII and secrets and writes an audit row with the end user’s identity.
It uses the same /govern/tool-use endpoint and the same workspace policies as Claude Code. Two differences. An ask comes back to the model as a denied tool call, so you approve it on the console and re-run. And the shell-command safety floor applies only to tools that carry a shell command.
Starter, 5-minute install.
pip install acp-governance agent-framework-core agent-framework-anthropic, add one middleware, bind the JWT per request. See the runnable starter, the policy model, or the frameworks index.
Install
pip install acp-governance agent-framework-core agent-framework-anthropic
Minimal agent, fully covered
import json
from typing import Any, Awaitable, Callable
from pydantic import BaseModel
from acp_governance import configure, post_tool_output, pre_tool_use, set_context
from agent_framework import Agent, FunctionInvocationContext, FunctionMiddleware
from agent_framework.anthropic import AnthropicClient
configure(base_url="https://api.agenticcontrolplane.com")
class ACPFunctionMiddleware(FunctionMiddleware):
"""One instance governs every tool the agent owns."""
async def process(
self,
context: FunctionInvocationContext,
call_next: Callable[[], Awaitable[None]],
) -> None:
tool_name = context.function.name
args = context.arguments
tool_input = args.model_dump() if isinstance(args, BaseModel) else dict(args or {})
allowed, reason = pre_tool_use(tool_name, tool_input)
if not allowed:
# Never call call_next(): the tool function does not execute.
context.result = f"tool_error: {reason or 'denied by policy'}"
return
await call_next()
output = context.result
serialized = output if isinstance(output, str) else json.dumps(output, default=str)
verdict = post_tool_output(tool_name, tool_input, serialized)
if verdict:
if verdict.get("action") == "redact":
context.result = verdict.get("modified_output", "[ACP] Redacted")
elif verdict.get("action") == "block":
context.result = f"[ACP] Blocked: {verdict.get('reason', 'policy')}"
def lookup_record(id: str) -> str:
"""Look up a record by ID."""
return json.dumps(db.records.find_one({"id": id}))
def send_email(to: str, subject: str, body: str) -> str:
"""Send an email."""
return mailer.send(to=to, subject=subject, body=body)
agent = Agent(
client=AnthropicClient(model_id="claude-sonnet-4-6"),
instructions="You are an ACP-governed agent. Use the tools available.",
tools=[lookup_record, send_email],
middleware=ACPFunctionMiddleware(),
)
For each request, bind the end user’s identity before the agent runs:
@app.post("/run")
async def run(prompt: str, authorization: str = Header(...)):
set_context(
user_token=authorization.removeprefix("Bearer ").strip(),
agent_name="my-maf-agent",
agent_tier="interactive",
)
response = await agent.run(prompt)
return {"result": response.text}
What happens on every tool call
- MAF resolves the model’s function call and enters the middleware chain. ACP POSTs to
/govern/tool-usewith the tool name, the validated input and the user JWT bound byset_context. - Deny: the middleware skips
call_next(), so your function never runs. The model getstool_error: <reason>as the tool output. - Allow:
call_next()runs your function. - After the call, ACP scans the output for PII and secrets.
redactswaps in the redacted version andblockreplaces the output. The audit row is written under the end user’s identity.
One middleware instead of per-tool decorators
With decorators, coverage is opt-in. Forget the decorator on tool #7 and it runs unchecked. MAF’s function middleware flips that: coverage belongs to the agent. Add plain functions, @tool-decorated functions or tools added at runtime, and the middleware wraps all of them. To limit it to specific runs, pass it per run with agent.run(..., middleware=...).
Per-tier policy
set_context(agent_tier="...") controls the policy tier:
interactive: a human is at the keyboard. The default is permissive.subagent: another agent invoked it, with no human in the immediate loop.background: it runs on its own. This is the most restrictive tier.api: your backend calls it programmatically.
MAF-specific notes
- Package layout.
agent-frameworkon PyPI is a meta-package that pulls in every connector.agent-framework-corecovers agents, tools and middleware. Provider chat clients install separately (agent-framework-anthropic,agent-framework-openai,agent-framework-azure-ai) underagent_framework.<provider>, so swapping providers doesn’t touch the middleware. - Native approvals work alongside ACP. MAF has
approval_modeon tools andToolApprovalMiddlewarefor in-process human sign-off. ACP leaves that alone and adds the workspace layer: standing rules, per-user policy and one audit trail across every framework you run. - AutoGen and Semantic Kernel migrations. If you’re moving agents onto MAF, the middleware travels with the agent definition, so you set up control once instead of per ported tool.
- Exceptions. An ordinary exception in function middleware becomes a tool-error result and the run continues.
MiddlewareFailureaborts the run. ACP’s middleware setscontext.resultinstead, so the model can read the denial.
Limitations
- Tool calls only. Model calls go straight to your provider with your own key. Route model traffic through the ACP proxy separately if you want per-user cost metering.
- Python only on this page. The .NET middleware surface is equivalent (
IFunctionMiddleware), but there is no .NET example here. - Pre-release SDK.
acp-governanceis on 0.x. The class above is about 30 lines and yours to own. - Asks become blocks. There is no inline approval prompt in this SDK. An
askis returned to the model as a denied call, approved on the console, then retried.
Related
- MAF docs: middleware
- MAF docs: function tools
acp-governance(core SDK)- Pydantic AI integration
- LangChain / LangGraph integration