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

# Trace AutoGen with BotGauge

> Trace AutoGen AgentChat agents with BotGauge in code or zero-code. Verified version, install line, and a tested AssistantAgent sample.

Records AutoGen AgentChat agent runs.

| | |
| - | - |
| Extra | `[autogen-agentchat]` |
| Verified framework versions | autogen-agentchat 0.7.5 |
| Instrumentor installed by the extra | `openinference-instrumentation-autogen-agentchat 0.1.22` |
| Zero-code run | Traced |

Also verified: autogen-agentchat 0.7.5 with instrumentor 0.1.18. The extra no longer installs that older instrumentor. See [supported frameworks](https://www.botgauge.com/docs/integrations/overview.md) for how verification works.

## In code

Call `tracing.init()`, attach the framework instrumentor to the provider it returns, and wrap the work in `tracing.turn()` and `tracing.agent()`.

**1. Install**

```bash terminal theme={null}
pip install "botgauge[autogen-agentchat]" autogen-agentchat==0.7.5 "autogen-ext[openai]==0.7.5"
```

**2. Add the code**

```python app.py theme={null}
import asyncio
import os

from botgauge import tracing
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
from openinference.instrumentation.autogen_agentchat import AutogenAgentChatInstrumentor

provider = tracing.init()
AutogenAgentChatInstrumentor().instrument(tracer_provider=provider)

client = OpenAIChatCompletionClient(
    model=os.environ["OPENAI_MODEL"],
    base_url=os.environ["OPENAI_BASE_URL"],
    api_key=os.environ["OPENAI_API_KEY"],
    model_info={
        "vision": False,
        "function_calling": True,
        "json_output": False,
        "family": "unknown",
        "structured_output": False,
    },
)

async def main():
    with tracing.turn(session_id="ses_autogen"), tracing.agent("autogen-agent"):
        agent = AssistantAgent(name="assistant", model_client=client)
        result = await agent.run(task="In one sentence, what is OpenTelemetry?")
    print(result.messages[-1].content)

asyncio.run(main())

tracing.shutdown()
```

**3. Run**

```bash terminal theme={null}
python app.py
```

Needs `BOTGAUGE_API_KEY`, `OPENAI_MODEL`, `OPENAI_BASE_URL`, `OPENAI_API_KEY`.

## Zero-code

Leave your app unchanged and start it with `botgauge instrument`. The sample still wraps the work in `tracing.turn()` and `tracing.agent()` so spans carry session and agent ids.

**1. Install**

```bash terminal theme={null}
pip install "botgauge[autogen-agentchat]" autogen-agentchat==0.7.5 "autogen-ext[openai]==0.7.5"
```

**2. Add the code**

```python app.py theme={null}
import asyncio
import os

from botgauge import tracing
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient

client = OpenAIChatCompletionClient(
    model=os.environ["OPENAI_MODEL"],
    base_url=os.environ["OPENAI_BASE_URL"],
    api_key=os.environ["OPENAI_API_KEY"],
    model_info={
        "vision": False,
        "function_calling": True,
        "json_output": False,
        "family": "unknown",
        "structured_output": False,
    },
)

async def main():
    with tracing.turn(session_id="ses_autogen"), tracing.agent("autogen-agent"):
        agent = AssistantAgent(name="assistant", model_client=client)
        result = await agent.run(task="In one sentence, what is OpenTelemetry?")
    print(result.messages[-1].content)

asyncio.run(main())
```

**3. Run**

```bash terminal theme={null}
botgauge instrument python app.py
```

Needs `BOTGAUGE_API_KEY`, `OPENAI_MODEL`, `OPENAI_BASE_URL`, `OPENAI_API_KEY`.

View AutoGen spans liveWatch your AutoGen AgentChat runs appear in [BotGauge](https://cloud.botgauge.com).

[Try BotGauge →](https://cloud.botgauge.com)

## Related

See [versions not verified](https://www.botgauge.com/docs/integrations/versions-not-verified.md) if you run a different version, [capture and redaction](https://www.botgauge.com/docs/tracing/capture-and-redaction.md) to control exported content, and [troubleshooting](https://www.botgauge.com/docs/tracing/troubleshooting.md) if spans are missing.


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