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

# AutoGen

> Observe AutoGen agent runs with Adaline.

# AutoGen

Use the Adaline AutoGen observer to send AutoGen runner activity into Adaline. The integration wraps an existing runner or agent and observes its run lifecycle without changing the task logic itself.

<Note>
  `adaline-autogen` is currently in early access and is not yet published on PyPI. Contact [support@adaline.ai](mailto:support@adaline.ai) to get access.
</Note>

## Prerequisites

Before you start, make sure you have:

* An [Adaline account](https://app.adaline.ai/sign-up?utm_source=adaline.ai).
* A **workspace API key** — create one under **Settings → API keys**.
* Your **project ID** — copy it from **Monitor → Copy Project ID**.

See [Integrate your AI Agent](/get-started/integrate-your-ai-agent) for a full walkthrough.

Set both as environment variables before running the examples on this page:

```bash theme={null}
export ADALINE_API_KEY="your-api-key"
export ADALINE_PROJECT_ID="your-project-id"
```

## Install

```bash theme={null}
pip install adaline-client adaline-autogen autogen-agentchat
```

Install the AutoGen packages your application already uses alongside the Adaline integration package. If you use the OpenAI model client shown below, make sure the corresponding AutoGen OpenAI extension package is also installed in your environment.

## Initialize Adaline

Create an Adaline client, then initialize a monitor for the target project.

```python theme={null}
import os

from adaline import Adaline

adaline = Adaline(api_key=os.environ["ADALINE_API_KEY"])
monitor = adaline.init_monitor(project_id=os.environ["ADALINE_PROJECT_ID"])
```

<Note>
  For production guidance — buffering, batching, retries, serverless flushing, and graceful shutdown — see [Instrument with the Adaline SDK](/instrument/with-adaline-sdks).
</Note>

## Wrap an AutoGen runner

Create an `AdalineAutoGenObserver`, then wrap the runner or agent you want to observe.

```python theme={null}
from adaline_autogen import AdalineAutoGenObserver

observer = AdalineAutoGenObserver(monitor=monitor)
wrapped_runner = observer.wrap_runner(runner)
```

## Basic example

This example keeps the integration intentionally small: one `AssistantAgent` run observed through `wrap_runner`.

```python theme={null}
import asyncio
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient

from adaline_autogen import AdalineAutoGenObserver

async def main():
    observer = AdalineAutoGenObserver(
        monitor=monitor,
        tags=["autogen"],
    )

    model_client = OpenAIChatCompletionClient(model="gpt-4o-mini")
    agent = AssistantAgent(name="support_agent", model_client=model_client)
    wrapped_runner = observer.wrap_runner(agent)

    items = [
        item async for item in wrapped_runner.run_stream(task="Say hello in one word.")
    ]

    await monitor.flush()


asyncio.run(main())
```

## Use an existing parent trace or span

The AutoGen observer accepts:

* `parent_trace`
* `parent_span`

Pass one or the other, but not both.

## What the observer captures

The AutoGen integration is designed to capture observed runner activity, including:

* runner-level roots created when a wrapped run starts
* task input passed into the observed runner
* child spans emitted during the wrapped run
* framework and runner metadata stored as Adaline attributes

This page focuses on how to wrap the runner. The exact span tree depends on the AutoGen runner behavior and the events emitted during the run.

## Next steps

<CardGroup cols={2}>
  <Card title="Instrument with the Adaline SDK" icon="code" href="/instrument/with-adaline-sdks">
    Monitor lifecycle, buffering and batching, retries, serverless flushing, and graceful shutdown.
  </Card>

  <Card title="SDK reference" icon="braces" href="/reference/sdk/v2/overview">
    Full class and type reference for the TypeScript and Python SDKs.
  </Card>

  <Card title="All integrations" icon="layout-grid" href="/integrations/introduction">
    Browse every framework and AI-provider integration Adaline supports.
  </Card>

  <Card title="View your logs" icon="line-chart" href="https://app.adaline.ai">
    Open Adaline to see traces and spans land in your project.
  </Card>
</CardGroup>
