Skip to main content
AG2 is an agent framework built on the autogen API. The AG2Instrumentor captures ConversableAgent chats, replies, and tool execution as OpenInference AGENT and TOOL spans in Arize AX. AG2 is a fork of the original 0.2-style AutoGen project. This integration is for AG2’s autogen module, not AG2 v1 or Microsoft’s separate autogen-agentchat package. See the Microsoft AutoGen AgentChat guide for the latter.

Prerequisites

  • Python 3.10+
  • An Arize AX account (sign up)
This guide uses AG2’s offline multi-agent and tool-call pattern, so it does not need an LLM provider key.

Launch Arize AX

  1. Sign in to your Arize AX account.
  2. From Space Settings, copy your Space ID and API Key. You will set them as ARIZE_SPACE_ID and ARIZE_API_KEY below.

Install

Configure credentials

Setup tracing

AG2 instrumentation supports the AG2 0.14.x autogen API. AG2 v1 uses a different middleware API and is not yet supported.

Spans and context captured

AG2 creates an AGENT span for each chat and agent reply. Reply spans nest under their chat span, and a function call made while producing a reply becomes a child TOOL span: Tool spans use the registered function name (for example, get_weather) and record tool.name, tool_call.id, tool_call.function.arguments, resolved tool.parameters, and the result. Agent spans record the input and output messages and the agent name. The instrumentor preserves the active OpenTelemetry context, so an AG2 chat started inside one of your application’s spans remains in that trace. Context also flows through nested replies and tool execution. Use using_attributes to propagate a session ID, user ID, metadata, and tags to all AG2 spans within a context block. Pair it with the OpenAIInstrumentor when an AG2 agent uses OpenAI: this adds LLM child spans below the AGENT spans. The standard OpenInference privacy controls apply. Use suppress_tracing around calls you do not want to trace. Set OPENINFERENCE_HIDE_INPUTS=true, OPENINFERENCE_HIDE_OUTPUTS=true, OPENINFERENCE_HIDE_INPUT_MESSAGES=true, or OPENINFERENCE_HIDE_OUTPUT_MESSAGES=true before starting your process to mask the corresponding captured values. For programmatic masking or image truncation, configure TraceConfig, which takes precedence over environment variables.

Run AG2

Expected output

More AG2 patterns

The quickstart above is deliberately offline. The following upstream-inspired patterns require OPENAI_API_KEY and the optional packages shown below. Add openai and openinference-instrumentation-openai to the install command, then instrument OpenAI before AG2:
Use a real model available to your account in config_list.

Group chat

Sequential chats

Structured outputs

These patterns follow the AG2 instrumentor examples.

Verify in Arize AX

  1. Open your Arize AX space and select project ag2-tracing-example.
  2. You should see a new trace within ~30 seconds with AGENT spans for the chat and reply, plus a TOOL span named get_weather.
  3. If no traces appear, see Troubleshooting.

Check from the skill, CLI, or SDK

Confirm spans are actually reaching your Arize AX project. Use whichever fits your workflow — the skill and CLI work for any framework; the SDK check is shown for each language.
Install the Arize Skills plugin and let your coding agent check for you:
Then prompt your agent:
Use the arize-trace skill to export and analyze recent traces from my project. Confirm spans are arriving, and summarize any errors or latency issues.

Troubleshooting

  • No traces in Arize AX. Call AG2Instrumentor().instrument(...) before starting a chat.
  • Import or instrumentation error. Install an AG2 0.14.x release; AG2 v1 is not supported by this instrumentor.
  • The example asks for an LLM key. Keep both agents’ llm_config=False; this offline example runs a local tool instead of calling a model.
  • LLM spans are missing. Install and initialize OpenAIInstrumentor before AG2 when your agents use OpenAI.

Resources

OpenInference AG2 Instrumentor

AG2 repository