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

# AutoGen

> Auto-track LLM calls in AutoGen multi-agent conversations

## Installation

```bash theme={null}
pip install meshai-sdk[autogen]
```

## Usage

```python theme={null}
from meshai import MeshAI
from meshai.integrations.autogen import track_autogen

client = MeshAI(api_key="msh_...", agent_name="my-autogen-team")
client.register(framework="autogen")

# Enable global tracking
track_autogen(client)

# Run AutoGen agents as normal
from autogen import AssistantAgent, UserProxyAgent

assistant = AssistantAgent("assistant", llm_config={"model": "gpt-4o"})
user_proxy = UserProxyAgent("user_proxy")
user_proxy.initiate_chat(assistant, message="Write a poem")
# All LLM calls tracked with model and token counts
```

## How It Works

AutoGen logs LLM calls via Python's `logging` module. MeshAI adds a custom handler that:

1. Captures `LLMCall` events from the `autogen_core` logger
2. Extracts **model**, **tokens**, and **provider** from each event
3. Sends to MeshAI (buffered, non-blocking)

## AG2 Compatibility

The integration also works with AG2 (AutoGen's fork). The logging interface is compatible.
