OpenInference AG2 Instrumentation
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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openinference_instrumentation_ag2-0.1.2.tar.gz.
File metadata
- Download URL: openinference_instrumentation_ag2-0.1.2.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96ab297ebaccbb7a91347b0ae371b842a9f6b651c90d7914d6368f5beabfc8f6
|
|
| MD5 |
296539e71da3a0cca7e31504625c8768
|
|
| BLAKE2b-256 |
0e6574498730cb5caddece188a0da91c2f5c3769d17d95cdbbb5b38b86ed991c
|
Provenance
The following attestation bundles were made for openinference_instrumentation_ag2-0.1.2.tar.gz:
Publisher:
publish.yaml on Arize-ai/openinference
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openinference_instrumentation_ag2-0.1.2.tar.gz -
Subject digest:
96ab297ebaccbb7a91347b0ae371b842a9f6b651c90d7914d6368f5beabfc8f6 - Sigstore transparency entry: 2371567786
- Sigstore integration time:
-
Permalink:
Arize-ai/openinference@290d8c71081b3219667f9f5698a5683619597d19 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Arize-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@290d8c71081b3219667f9f5698a5683619597d19 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file openinference_instrumentation_ag2-0.1.2-py3-none-any.whl.
File metadata
- Download URL: openinference_instrumentation_ag2-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e07b6af644ed5b7a4379197b53822c7943616802a6375850ee9d47152844bec
|
|
| MD5 |
cd200c1ace0b49f9c6f86308fbc41653
|
|
| BLAKE2b-256 |
322fa8cbfc3563cfaba416f85ae592ac819d930e99cdbf00e97f1f98f91637d7
|
Provenance
The following attestation bundles were made for openinference_instrumentation_ag2-0.1.2-py3-none-any.whl:
Publisher:
publish.yaml on Arize-ai/openinference
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openinference_instrumentation_ag2-0.1.2-py3-none-any.whl -
Subject digest:
8e07b6af644ed5b7a4379197b53822c7943616802a6375850ee9d47152844bec - Sigstore transparency entry: 2371567880
- Sigstore integration time:
-
Permalink:
Arize-ai/openinference@290d8c71081b3219667f9f5698a5683619597d19 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Arize-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@290d8c71081b3219667f9f5698a5683619597d19 -
Trigger Event:
workflow_dispatch
-
Statement type: