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

# AG2 (AutoGen)

> Audit AG2/AutoGen chat completions and function calls

<Note>
  **Prefer zero setup?** Use `plog run` or `import provenlog.auto` instead. See [Auto-Instrumentation](/integrations/auto-instrumentation).
</Note>

## Setup

```python theme={null}
from provenlog.integrations.ag2 import Trail
import autogen

trail = Trail(agent_id="my-autogen-agent")
autogen.runtime_logging.start(logger=trail)
```

## What gets captured

| Event              | Action Type                 | Details                          |
| ------------------ | --------------------------- | -------------------------------- |
| Chat completions   | `LLM_CALL` / `LLM_RESPONSE` | Model, messages, token counts    |
| Function calls     | `TOOL_CALL` / `TOOL_RESULT` | Function name, arguments, output |
| Agent registration | `CUSTOM`                    | Agent name, configuration        |
| Cost tracking      | `CUSTOM`                    | Per-call and cumulative costs    |
| Cache status       | `CUSTOM`                    | Cache hits and misses            |

## How it works

The Trail hooks into AG2's runtime logging system via `autogen.runtime_logging.start`. It receives structured events for all agent activity across the AG2 framework.

## Configuration

```python theme={null}
# Simple — uses default embedded mode
trail = Trail(agent_id="my-autogen-agent")

# With explicit client for custom configuration
from provenlog import ProvenLogClient

client = ProvenLogClient("http://localhost:7600", agent_id="my-agent")
trail = Trail(client=client, agent_id="my-autogen-agent")
```
