Skip to main content

OpenInference AG2 Instrumentation

pypi

Python auto-instrumentation library for AG2 agents, capturing chats, agent replies, and synchronous or asynchronous tool execution.

The following instrumentation is fully OpenTelemetry-compatible and can be sent to an OpenTelemetry collector for monitoring, such as Arize Phoenix or Arize AX.

Installation

pip install openinference-instrumentation-ag2

PyPI package: openinference-instrumentation-ag2

This release supports the autogen API provided by AG2 0.14. AG2 1.0 uses a new middleware API and is not yet covered by this instrumentor.

Quickstart

This quickstart shows you how to instrument your AG2 application.

You've already installed openinference-instrumentation-ag2. Next is to install packages for AG2, Phoenix, and the exporter that sends traces to it.

pip install "ag2[openai]" arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp

Start the Phoenix app in the background as a collector:

phoenix serve

By default, it listens on http://localhost:6006. You can visit the app via a browser at the same address.

The Phoenix app does not send data over the internet. It only operates locally on your machine.

Create a simple AG2 agent:

import os

from autogen import ConversableAgent, LLMConfig
from opentelemetry import trace as trace_api
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk import trace as trace_sdk
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor

from openinference.instrumentation.ag2 import AG2Instrumentor

endpoint = "http://127.0.0.1:6006/v1/traces"
tracer_provider = trace_sdk.TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
# Optionally, you can also print the spans to the console.
tracer_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))

trace_api.set_tracer_provider(tracer_provider=tracer_provider)

# Start instrumenting AG2
AG2Instrumentor().instrument()

llm_config = LLMConfig(
    {"api_type": "openai", "model": "gpt-4o-mini", "api_key": os.environ["OPENAI_API_KEY"]}
)

agent = ConversableAgent(
    name="helpful_agent",
    system_message="You are a helpful assistant.",
    llm_config=llm_config,
)

response = agent.run(message="What is the capital of France?", max_turns=1, user_input=False)
response.process()

Finally, run the example:

python example.py

Finally, browse for your trace in Phoenix at http://localhost:6006!

Span kinds

AG2 method Span name OpenInference span kind
initiate_chat / a_initiate_chat (also used by run and initiate_chats) <agent>.initiate_chat AGENT
generate_reply / a_generate_reply <agent>.generate_reply AGENT
execute_function / a_execute_function <tool> TOOL

AG2Instrumentor().uninstrument() restores every patched AG2 method. The instrumentor also respects OpenTelemetry tracing suppression, OpenInference context attributes, and TraceConfig masking options.

Examples

More examples covering tool calling, group chats, sequential chats, structured outputs, and the async paths live in examples/. Two of them need no LLM API key, so they are the quickest way to confirm traces are reaching Phoenix.

More Info

Metadata

Release files for openinference-instrumentation-ag2 0.1.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openinference-instrumentation-ag2 0.1.11
File Size Uploaded
openinference_instrumentation_ag2-0.1.11.tar.gz 13.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openinference-instrumentation-ag2 0.1.11
File Interpreter ABI Platform
openinference_instrumentation_ag2-0.1.11-py3-none-any.whl Python 3 none any Details

Total release size: 27.3 kB

Release files / openinference_instrumentation_ag2-0.1.11.tar.gz

Download URL openinference_instrumentation_ag2-0.1.11.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
073d4755fc8f5fd73df7d73c52b12e5c0410c27a557091b148a27f7ba8a8e502
BLAKE2b-256 checksum
How to use checksums
2f99d6c561d2810e592f3613eecf12d1916f5d5442fd2f82cc2bedcd505e040f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / openinference_instrumentation_ag2-0.1.11-py3-none-any.whl

Download URL openinference_instrumentation_ag2-0.1.11-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0fde3972c7dc67145cfd9891af4a39a560dd9761716749f462d62c61ba41d44
BLAKE2b-256 checksum
How to use checksums
364cd5caa0c804ef7e5edd85dc6777d1a3975901656fac44cbab63a3e1ecf9a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.11 This release

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page