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

# AutoGen Integration

> Track Microsoft AutoGen multi-agent conversations with automatic message tracking and tool executions.

<Note>
  **Supported Versions:**

  * **autogen-agentchat >= 0.4.0** — Modern event-driven API (recommended)
  * **pyautogen >= 0.2.0** — Legacy API
</Note>

## What Gets Tracked Automatically

<CardGroup cols={2}>
  <Card title="Agent Messages">
    All agent-to-agent communications.
  </Card>

  <Card title="Tool Calls">
    Function and tool executions.
  </Card>

  <Card title="Model Responses">
    LLM responses with token usage.
  </Card>

  <Card title="Cost & Tokens">
    Estimated costs based on model.
  </Card>
</CardGroup>

## Installation

```bash theme={null}
# For AutoGen 0.4+ (recommended)
pip install sentrial autogen-agentchat>=0.4.0

# For legacy pyautogen
pip install sentrial pyautogen>=0.2.0
```

## AutoGen 0.4+ (autogen-agentchat)

```python theme={null}
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models.openai import OpenAIChatCompletionClient
from sentrial import SentrialClient
from sentrial.autogen import SentrialAutogenHandler

# Initialize
client = SentrialClient(api_key="sentrial_live_xxx")
session_id = client.create_session(
    name="Code Review Team",
    agent_name="autogen-review",
    user_id="user_123"
)

# Create handler
handler = SentrialAutogenHandler(client, session_id, verbose=True)

# Create model client
model_client = OpenAIChatCompletionClient(model="gpt-4o")

# Create agents
reviewer = AssistantAgent(
    name="CodeReviewer",
    model_client=model_client,
    system_message="You review code for bugs.",
)

security = AssistantAgent(
    name="SecurityExpert",
    model_client=model_client,
    system_message="You analyze security vulnerabilities.",
)

# Create team
team = RoundRobinGroupChat(
    participants=[reviewer, security],
    max_turns=4,
)

# Run with tracking
result = await handler.run_team(team, task="Review this code...")

# Finish
handler.finish(success=True)
```

## Legacy pyautogen

```python theme={null}
from autogen import AssistantAgent, UserProxyAgent
from sentrial import SentrialClient
from sentrial.autogen import SentrialAutogenHandler

client = SentrialClient(api_key="sentrial_live_xxx")
session_id = client.create_session(
    name="AutoGen Chat",
    agent_name="autogen-chat",
    user_id="user_123"
)

handler = SentrialAutogenHandler(client, session_id)

# Create agents
assistant = AssistantAgent("assistant", llm_config=llm_config)
user_proxy = UserProxyAgent("user_proxy")

# Register for tracking
handler.register_agents([assistant, user_proxy])

# Chat
user_proxy.initiate_chat(assistant, message="Hello!")

handler.finish(success=True)
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Python SDK Reference" icon="python" href="/sdk/python">
    Full SDK documentation.
  </Card>

  <Card title="CrewAI Integration" icon="users" href="/integrations/crewai">
    Track CrewAI multi-agent systems.
  </Card>
</CardGroup>
