> ## Documentation Index
> Fetch the complete documentation index at: https://arizeai-433a7140.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AutoGen AgentChat Tracing

> Auto-instrument your AgentChat application for seamless observability

[AutoGen AgentChat](https://microsoft.github.io/autogen/stable//user-guide/agentchat-user-guide/index.html) is the framework within Microsoft's AutoGen that enables robust multi-agent application.

## Launch Phoenix

> [card]
>
> > [tab] Local
> >
> > ```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> > uvx arize-phoenix serve
> > ```
> >
> > No [uv](https://docs.astral.sh/uv/)? `pip install arize-phoenix && phoenix serve` does the same thing. See [Terminal setup](https://arizeai-433a7140.mintlify.site/docs/phoenix/self-hosting/deployment-options/terminal.md) for customization.
>
> > [tab] Container
> >
> > ```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> > docker run -p 6006:6006 -p 4317:4317 arizephoenix/phoenix:latest
> > ```
> >
> > Images are published to [Docker Hub](https://hub.docker.com/r/arizephoenix/phoenix). See [Docker](https://arizeai-433a7140.mintlify.site/docs/phoenix/self-hosting/deployment-options/docker.md) for volumes, PostgreSQL, and other options.
>
> > [tab] Self-Host
> >
> > Run Phoenix on your own infrastructure, backed by PostgreSQL so traces persist beyond a single process. This is the option to reach for once Phoenix is shared across a team or environment.
> >
> > The [self-hosting guide](https://arizeai-433a7140.mintlify.site/docs/phoenix/self-hosting.md) covers [Kubernetes](https://arizeai-433a7140.mintlify.site/docs/phoenix/self-hosting/deployment-options/kubernetes.md), [Helm](https://arizeai-433a7140.mintlify.site/docs/phoenix/self-hosting/deployment-options/kubernetes-helm.md), [Railway](https://arizeai-433a7140.mintlify.site/docs/phoenix/self-hosting/deployment-options/railway.md), [AWS CloudFormation](https://arizeai-433a7140.mintlify.site/docs/phoenix/self-hosting/deployment-options/aws-with-cloudformation.md), [Google Cloud Run](https://arizeai-433a7140.mintlify.site/docs/phoenix/self-hosting/deployment-options/google-cloud-run.md), [Azure](https://arizeai-433a7140.mintlify.site/docs/phoenix/self-hosting/deployment-options/azure.md), and [Render](https://arizeai-433a7140.mintlify.site/docs/phoenix/self-hosting/deployment-options/render.md), plus authentication and configuration.
>
> Phoenix serves its UI and OTLP HTTP on port **6006**, and OTLP gRPC on port **4317**. For a local instance that's [http://localhost:6006](http://localhost:6006). Leave it running while you work.

**Install packages:**

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
pip install arize-phoenix-otel
```

Point your code at the Phoenix instance you started. The endpoint below is the default for a local `phoenix serve`; for a deployment running elsewhere, use its hostname instead.

```python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import os

os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = "http://localhost:6006"

# Only if the deployment has authentication enabled
# os.environ["PHOENIX_API_KEY"] = "your-api-key"
```

## Install

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
pip install openinference-instrumentation-autogen-agentchat \
  openinference-instrumentation-openai autogen-agentchat autogen_ext openai tiktoken
```

## Setup

Connect your application to Phoenix with the `register` function:

from phoenix.otel import register

&#x20; \# configure the Phoenix tracer
&#x20; tracer\_provider = register(
&#x20; project\_name="agentchat-agent", # Default is 'default'
&#x20; auto\_instrument=True # Auto-instrument your app based on installed OI dependencies
&#x20; )

## Run AutoGen AgentChat

We’re going to run an `AgentChat` example using a multi-agent team. To get started, install the required packages to use your LLMs with `AgentChat`. In this example, we’ll use OpenAI as the LLM provider.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
pip install autogen_ext openai
```

```python expandable theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import asyncio
import os
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import MaxMessageTermination, TextMentionTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models.openai._openai_client import OpenAIChatCompletionClient

async def main():
    model_client = OpenAIChatCompletionClient(
        model="gpt-5.6-sol",
        # AutoGen's built-in model table stops at GPT-5, so describe newer models yourself.
        model_info={"vision": True, "function_calling": True, "json_output": True, "structured_output": True, "family": "unknown"},
    )

    # Create two agents: a primary and a critic
    primary_agent = AssistantAgent(
        "primary",
        model_client=model_client,
        system_message="You are a helpful AI assistant.",
    )

    critic_agent = AssistantAgent(
        "critic",
        model_client=model_client,
        system_message="""
        Provide constructive feedback.
        Respond with 'APPROVE' when your feedbacks are addressed.
        """,
    )

    # Termination condition: stop when the critic says "APPROVE"
    text_termination = TextMentionTermination("APPROVE")

    # Create a team with both agents
    team = RoundRobinGroupChat(
        [primary_agent, critic_agent],
    termination_condition=text_termination | MaxMessageTermination(4)
    )

    # Run the team on a task
    result = await team.run(task="Write a short poem about the fall season.")
    await model_client.close()
    print(result)

if __name__ == "__main__":
    asyncio.run(main())
```

## Observe

Phoenix provides visibility into your AgentChat operations by automatically tracing all interactions.

![AutoGen AgentChat spans and model output in Phoenix](https://storage.googleapis.com/arize-phoenix-assets/assets/images/agentchat-phoenix.png)

## Resources

* [AutoGen AgentChat documentation](https://microsoft.github.io/autogen/stable//user-guide/agentchat-user-guide/index.html)

* [AutoGen AgentChat OpenInference Package](https://pypi.org/project/openinference-instrumentation-autogen-agentchat/)
