> ## Documentation Index
> Fetch the complete documentation index at: https://traceroot.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Microsoft Agent Framework

> Auto-instrument Microsoft Agent Framework agent runs, model calls, and tool executions

Automatically capture agent runs, model calls, and tool executions from [Microsoft Agent Framework](https://github.com/microsoft/agent-framework) through its built-in OpenTelemetry emission — no manual instrumentation of the framework required.

## Install

> [tab] Python
>
> ```bash theme={null}
> pip install "traceroot[agent-framework]" agent-framework-openai
> ```

## Set up

> [tab] Python
>
> ```python theme={null}
> import traceroot
> from traceroot import Integration
>
> traceroot.initialize(integrations=[Integration.AGENT_FRAMEWORK])
> ```

Initialize traceroot **before** importing `agent_framework`, so the OpenTelemetry instrumentation is wired up before the framework emits its first span.

## Usage

Once initialized, every agent invocation, model call, and tool execution is captured automatically:

```python theme={null}
import asyncio

import traceroot
from traceroot import Integration

traceroot.initialize(integrations=[Integration.AGENT_FRAMEWORK])

# Import after initialize() so tracing is already active.
from agent_framework import Agent
from agent_framework.openai import OpenAIChatClient


def get_weather(city: str) -> str:
    """Return a short weather forecast for a city."""
    return f"{city}: 18°C, partly cloudy."


agent = Agent(
    OpenAIChatClient(model="gpt-4o-mini"),
    "You are a helpful travel concierge. Use the weather tool when relevant.",
    name="Concierge",
    tools=[get_weather],
)


async def main():
    # The agent run, the model call, and the get_weather tool call are all traced.
    response = await agent.run("What's the weather in Tokyo?")
    print(response.text)


asyncio.run(main())
```

Tools are plain functions — Agent Framework already emits an `execute_tool` span for each call, so they don't need manual decoration.

## Verify

Run your code and confirm the trace arrives:

1. **In the traceroot UI**: Navigate to **Tracing > Traces** in [traceroot Cloud](https://app.traceroot.ai). You should see a trace with root span `invoke_agent Concierge` — Agent Framework names each agent span `invoke_agent <agent name>`.
2. **Via the CLI**: Run `traceroot traces list` to inspect your recent traces from the terminal.

## What gets captured

| Attribute | Description |
| - | - |
| Agent run | Each agent invocation as a span (nested for delegated agents) |
| Model | The chat model used for each call |
| Tool calls | An `execute_tool` span per tool execution, with arguments |
| Response | Generated text and tool outputs |
| Tokens | Input and output token counts |
| Cost | Calculated when the model ID matches traceroot's pricing table |
| Latency | Request duration |

## Limitations

* Requires installing the `agent-framework` extra via `pip install "traceroot[agent-framework]"`.
* traceroot must be initialized before importing `agent_framework` so that OpenTelemetry listeners are attached before spans are generated. Requires OpenTelemetry >= 1.39.

## Run the example

Clone the repo and run a complete multi-agent example end-to-end.

> [card] [Python](https://github.com/traceroot-ai/traceroot/tree/main/examples/python/microsoft-agent-framework)
>
> Run the Python example

## Next steps

> [card] [Python SDK Reference](https://traceroot.ai/docs/tracing/python-sdk.md)
>
> Explore the full Python SDK reference and instrumentation options.

> [card] [Cost Tracking](https://traceroot.ai/docs/tracing/cost-tracking.md)
>
> Learn how traceroot calculates token costs and tracks model spend.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.