Skip to main content
AG2 (formerly AutoGen) is an open-source Python framework for building multi-agent LLM applications. It centers on the ConversableAgent, which agents use to chat with one another, call tools, and coordinate through group chats and sequential conversations. Phoenix instruments AG2 through the openinference-instrumentation-ag2 package. Calling AG2Instrumentor().instrument() patches ConversableAgent and emits spans for chats, replies, and tool executions, nesting them correctly through group chat orchestration.
This instrumentor supports AG2 0.14, which is imported as autogen. AG2 1.0 uses a new middleware architecture that is not covered yet.

Install

AG2 delegates its LLM calls to the underlying model client. Pair the AG2 instrumentor with the instrumentor for that provider — openinference-instrumentation-openai in the examples below — so the LLM spans appear nested under the agent spans. If your agents call a different provider, install and register that provider’s OpenInference instrumentor instead.

Setup

Use the register function to connect your application to Phoenix. Because AG2 relies on a separate model instrumentor for LLM visibility, keep auto_instrument=True so both the AG2 and model instrumentors are activated from your installed dependencies. Connect your application to Phoenix with the register function:

Run AG2

From here you can use AG2 as normal, and Phoenix will trace each agent chat, reply, and tool call. The example below runs a single agent with the quickstart run() API:

What gets traced

The instrumentor patches ConversableAgent and produces three span kinds: Tool spans carry tool.name, tool_call.id, tool_call.function.arguments, and tool.parameters with resolved parameter types. The instrumentor also supports suppressing tracing, propagating context attributes (using_session, using_user, using_attributes), and masking sensitive data with a TraceConfig.

Examples

Tool calling

An LLM-driven tool call, split across an agent that decides to call the tool and a user proxy that executes it — the registration split AG2 uses throughout its tools guide.

Group chat

An AutoPattern group chat where a manager routes between specialist agents. The trace shows the manager’s speaker-selection decisions interleaved with each specialist’s reply:

Sequential chats

initiate_chats runs a queue of chats in order, passing each chat’s summary into the next as carryover. Each chat in the queue gets its own AGENT span, so the trace shows the whole pipeline:

Structured outputs

Passing a pydantic model as response_format on LLMConfig makes the agent reply with JSON matching that schema. The agent span’s output value is the serialized model, so the trace shows exactly what downstream code will parse:

Observe

Now that you have tracing set up, all AG2 agent chats, replies, and tool calls are streamed to Phoenix for observability and evaluation. Each ConversableAgent chat and reply appears as an AGENT span, with tool executions nested underneath as TOOL spans.

An AG2 trace in Phoenix

Migrating from openinference-instrumentation-autogen

openinference-instrumentation-ag2 replaces openinference-instrumentation-autogen. The autogen package is now a thin, deprecated compatibility facade that delegates to AG2Instrumentor. Move to openinference-instrumentation-ag2 and use AG2Instrumentor directly.

Resources