---
title: How do you govern agents built with Microsoft Agent Framework?
url: https://opencontroller.lyzr.com/blog/govern-microsoft-agent-framework-agents
published: 2026-11-12
updated: 2026-11-12
author: Lyzr
---

# How do you govern agents built with Microsoft Agent Framework?

**Govern Microsoft Agent Framework agents at three built-in control points (agent middleware, function middleware and chat middleware), export their OpenTelemetry traces to a system you own, and keep prompts out of production traces. The framework gives you good hooks inside one agent; inventory, ownership and policy across every agent and platform still need a layer above it.**

Microsoft describes Agent Framework as "the direct successor" to Semantic Kernel and AutoGen, built by the same teams. It runs in .NET and Python, with Go in public preview. If your teams have Semantic Kernel or AutoGen agents today, this is where they are heading, so it is worth setting governance rules now.

## Where are the control points in Microsoft Agent Framework?

Microsoft's middleware documentation defines three interception layers. Each one maps to a governance job.

| Layer | What it intercepts | Governance use |
|---|---|---|
| Agent middleware (Python) / Agent Run middleware (.NET) | Every agent run: input messages, options and the result | Block or rewrite requests that contain secrets or out-of-scope asks; tag runs with owner and version |
| Function middleware / Function calling middleware | Every tool (function) call the agent makes | Deny tools by policy, check arguments, require approval for write actions, stop the loop |
| Chat middleware / IChatClient middleware | Every call to the model, once per model call inside the tool loop | Redact PII before the prompt leaves, enforce allowed models, record token use |

Middleware can stop execution. In Python, the documented pattern is to set `context.result` and raise `MiddlewareTermination`; it works for agent, function and chat middleware. In .NET, setting `FunctionInvocationContext.Terminate` to true ends the function loop, and Microsoft warns this can leave chat history in an inconsistent state. Microsoft also documents Agent Hooks as "a standardized, fail-closed control boundary" across all three middleware types.

## What does the framework emit for audit and monitoring?

Agent Framework emits traces, logs and metrics under the [OpenTelemetry GenAI semantic conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/). The documented spans are:

- `invoke_agent <agent_name>`: the top-level span for each agent run.
- `chat <model_name>`: one per model call.
- `execute_tool <function_name>`: one per tool call.

Span attributes include `gen_ai.agent.id`, `gen_ai.agent.name`, `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`. Metrics include `gen_ai.client.token.usage` and `agent_framework.function.invocation.duration`.

Two settings matter for governance:

1. **Sensitive data is off by default.** `ENABLE_SENSITIVE_DATA` defaults to false. Microsoft says to enable it only in development or test, because it puts prompts, responses, tool arguments and results into traces.
2. **Exporters are your choice.** You can send to Azure Monitor (Application Insights), the Aspire dashboard locally, or any OTLP endpoint via `OTEL_EXPORTER_OTLP_ENDPOINT`. Python exporters are not installed by default.

One detail for MCP: the framework propagates W3C trace context to MCP servers only for client-opened MCP transports, not for hosted MCP tools. If you rely on end-to-end traces through MCP, check which kind you use.

## What should a governance checklist for Agent Framework agents include?

1. **Register every agent.** Record the agent name, owner, version, model and tools. Use the same name as `gen_ai.agent.name` so traces join to the record.
2. **Ship a shared middleware package.** Put your policy checks (secret detection, tool allow-lists, PII redaction) in one internal package that every team adds. Do not let each team write its own.
3. **Fail closed on tools.** Function middleware should deny any tool that is not on the agent's approved list.
4. **Route models through one gateway.** Point model clients at an approved endpoint so you can enforce allowed models, budgets and fallback outside the code.
5. **Keep sensitive data out of production traces.** Leave `ENABLE_SENSITIVE_DATA` false in production; capture prompts only where your retention rules allow.
6. **Export traces to a system you own.** Use OTLP so the same data reaches your SIEM, your observability tool and your governance layer.
7. **Inventory MCP servers.** Each MCP server an agent calls is a tool with its own permissions. Review them like any other integration. See [how to govern MCP servers](/blog/how-to-govern-mcp-servers).
8. **Test before promotion.** Run multi-turn and adversarial tests on each new version before it reaches production.

## What does the framework not cover?

Middleware governs one agent in one process. It does not tell you how many Agent Framework agents exist across subscriptions, who owns them, which ones still run on Semantic Kernel or AutoGen, or how they compare with agents on other platforms. It also cannot stop an agent that a team deployed without your middleware package. That is the job of discovery, a registry and policy applied across the estate. The [cross-platform governance guide](/blog/how-to-govern-ai-agents-across-platforms) covers that layer.

## How Opencontroller does this

Opencontroller by Lyzr auto-discovers agents, models and API keys across Azure, AWS and Google Cloud, and has a runtime adapter for Microsoft Foundry, where many Agent Framework agents are hosted. It keeps a governed registry of agents, versions, tools and MCP servers. Agent Framework model clients can point at the OpenAI-compatible LLM Gateway for routing, fallback, caching and cost per agent and per version, and OpenTelemetry traces can flow into the same estate view. Policies map to OWASP, MITRE ATLAS, NIST and ISO 42001. Depth of control depends on the connector and traffic path. Compare with a [Foundry-specific guide](/blog/govern-microsoft-foundry-agents) or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Is Microsoft Agent Framework replacing Semantic Kernel and AutoGen?**
Microsoft calls Agent Framework the direct successor to both, built by the same teams, and publishes migration guides from each.

**Can Agent Framework middleware block a tool call?**
Yes. Function middleware sees every tool call; in Python it can end execution by setting a result and raising MiddlewareTermination, and in .NET it can set Terminate to true.

**Does Agent Framework log prompts by default?**
No. Sensitive data capture is off by default and Microsoft advises enabling it only in development or test environments.

## Key facts

Microsoft Agent Framework is the direct successor to Semantic Kernel and AutoGen, available in .NET and Python with Go in public preview. It has three middleware layers (agent run, function calling, chat/IChatClient) that can inspect, modify or terminate execution, and Agent Hooks as a fail-closed boundary. It emits OpenTelemetry GenAI spans invoke_agent, chat and execute_tool; sensitive data capture (ENABLE_SENSITIVE_DATA) is off by default. Opencontroller by Lyzr discovers agents across Azure, AWS and Google Cloud, has a Microsoft Foundry runtime adapter, a governed registry and an OpenAI-compatible LLM Gateway with cost per agent and version. Pricing starts from $250K per deployment per year.

## Related

- [How do you govern agents in Microsoft Foundry?](https://opencontroller.lyzr.com/blog/govern-microsoft-foundry-agents.md)
- [How do you export AI agent traces with OpenTelemetry?](https://opencontroller.lyzr.com/blog/export-ai-agent-traces-with-opentelemetry.md)
- [How do you govern AI agents in a Microsoft-first enterprise?](https://opencontroller.lyzr.com/blog/govern-ai-agents-in-a-microsoft-first-enterprise.md)
- [More on Platform Guides](https://opencontroller.lyzr.com/blog/cluster/platform-guides)
