> ## 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.

# AutoGen

> Auto-instrument AutoGen multi-agent conversations and tool calls

Automatically capture agent loops, message histories, and tool executions within the AutoGen framework.

## Setup

To capture the complete picture—including both the agent orchestrations and the underlying token costs—we highly recommend initializing both the AutoGen integration and your specific LLM provider (e.g., Google GenAI, OpenAI, Anthropic).

```python theme={null}
import traceroot
from traceroot import Integration

# Initialize AutoGen alongside your LLM provider to capture tokens and costs
traceroot.initialize(integrations=[
    Integration.AUTOGEN,
    Integration.GOOGLE_GENAI  # Or OPENAI, ANTHROPIC, etc.
])
```

## Usage

Once initialized, agent conversations and tool calls are captured automatically:

```python theme={null}
import os
import autogen
from typing import Annotated
from autogen import register_function

llm_config = {
    "config_list": [{
        "model": "gemini-2.5-flash",
        "api_key": os.environ["GEMINI_API_KEY"],
        "api_type": "google"
    }]
}

assistant = autogen.AssistantAgent(
    name="assistant",
    llm_config=llm_config
)
user_proxy = autogen.UserProxyAgent(
    name="user_proxy",
    human_input_mode="NEVER",
    max_consecutive_auto_reply=5
)

def get_weather(city: Annotated[str, "City name"]) -> str:
    """Get current weather for a city."""
    return f"The weather in {city} is 72 degrees and sunny."

def get_forecast(city: Annotated[str, "City name"], days: Annotated[int, "Number of days"]) -> str:
    """Get a multi-day weather forecast for a city."""
    return f"{days}-day forecast for {city}: mostly sunny with highs around 70-75°F."

# Register tools — caller decides when to use them, executor runs the function
register_function(
    get_weather,
    caller=assistant,
    executor=user_proxy,
    name="get_weather",
    description="Get current weather for a city",
)
register_function(
    get_forecast,
    caller=assistant,
    executor=user_proxy,
    name="get_forecast",
    description="Get a multi-day weather forecast for a city",
)

# The entire conversation hierarchy is automatically traced
user_proxy.initiate_chat(
    assistant,
    message="What's the weather in Tokyo today, and what does the 3-day forecast look like?",
)
```

## What Gets Captured

| Attribute         | Description                                                         |
| ----------------- | ------------------------------------------------------------------- |
| Conversation Loop | The overarching `initiate_chat` session                             |
| Agent Steps       | Individual spans for each `AssistantAgent` or `UserProxyAgent` turn |
| Messages          | Full chat history, input messages, and agent replies                |
| Tool calls        | Function names, input arguments, and execution outputs              |
| LLM calls         | Raw completion requests to the provider                             |
| Tokens & Cost     | Aggregated usage and pricing for the chat session                   |

## Run the example

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

<Card title="Python" icon="python" href="https://github.com/traceroot-ai/traceroot/tree/main/examples/python/autogen-tool-agent">
  Run the Python example
</Card>
