OpenInference Autogen-Agentchat Instrumentation
OpenTelelemetry instrumentation for Autogen AgentChat, enabling tracing of agent interactions and conversations.
The traces emitted by this instrumentation are fully OpenTelemetry compatible and can be sent to an OpenTelemetry collector for viewing, such as Arize Phoenix or Arize AX.
Installation
pip install openinference-instrumentation-autogen-agentchat
Quickstart
In this example we will instrument a simple Autogen AgentChat application and observe the traces via arize-phoenix.
Install required packages.
pip install openinference-instrumentation-autogen-agentchat autogen-agentchat arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp
Start the phoenix server so that it is ready to collect traces. The Phoenix server runs entirely on your machine and does not send data over the internet.
phoenix serve
Here's a simple example using a single assistant agent:
import asyncio
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
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.autogen_agentchat import AutogenAgentChatInstrumentor
# Set up the tracer provider
endpoint = "http://127.0.0.1:6006/v1/traces"
tracer_provider = trace_sdk.TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
# Instrument AutogenAgentChat
AutogenAgentChatInstrumentor().instrument(tracer_provider=tracer_provider)
async def main():
model_client = OpenAIChatCompletionClient(
model="gpt-3.5-turbo",
)
def get_weather(city: str) -> str:
"""Get the weather for a given city."""
return f"The weather in {city} is 73 degrees and Sunny."
# Create an assistant agent with tools
agent = AssistantAgent(
name="weather_agent",
model_client=model_client,
tools=[get_weather],
system_message="You are a helpful assistant that can check the weather.",
reflect_on_tool_use=True,
model_client_stream=True,
)
result = await agent.run(task="What is the weather in New York?")
await model_client.close()
print(result)
if __name__ == "__main__":
asyncio.run(main())
For a more complex example using multiple agents in a team:
import asyncio
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import TextMentionTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models.openai import OpenAIChatCompletionClient
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk import trace as trace_sdk
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from openinference.instrumentation.autogen_agentchat import AutogenAgentChatInstrumentor
# Set up the tracer provider
endpoint = "http://127.0.0.1:6006/v1/traces"
tracer_provider = trace_sdk.TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
# Instrument AutogenAgentChat
AutogenAgentChatInstrumentor().instrument(tracer_provider=tracer_provider)
async def main():
model_client = OpenAIChatCompletionClient(
model="gpt-4",
)
# Create two agents: a primary and a critic
primary_agent = AssistantAgent(
"primary",
model_client=model_client,
system_message="You are a helpful AI assistant.",
)
critic_agent = AssistantAgent(
"critic",
model_client=model_client,
system_message="""
Provide constructive feedback.
Respond with 'APPROVE' when your feedbacks are addressed.
""",
)
# Termination condition: stop when the critic says "APPROVE"
text_termination = TextMentionTermination("APPROVE")
# Create a team with both agents
team = RoundRobinGroupChat(
[primary_agent, critic_agent],
termination_condition=text_termination
)
# Run the team on a task
result = await team.run(task="Write a short poem about the fall season.")
await model_client.close()
print(result)
if __name__ == "__main__":
asyncio.run(main())
Since we are using OpenAI, we must set the OPENAI_API_KEY environment variable to authenticate with the OpenAI API.
export OPENAI_API_KEY=[your_key_here]
Now simply run the python file and observe the traces in Phoenix.
python your_file.py
More Info
Metadata
Release files for openinference-instrumentation-autogen-agentchat 0.1.21
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| openinference_instrumentation_autogen_agentchat-0.1.21.tar.gz | 15.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| openinference_instrumentation_autogen_agentchat-0.1.21-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.2 kB
Release files / openinference_instrumentation_autogen_agentchat-0.1.21.tar.gz
| Download URL | openinference_instrumentation_autogen_agentchat-0.1.21.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c710f80ac43f5fe88b570d32b6eb1b6a865da4fab4b04cef47a953242f681ff
|
|
BLAKE2b-256 checksum How to use checksums |
8af065dd29f7d14fb650db7f24f17480efafde503f9ae094819bb6a40f7cbca5
|
| 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 logRelease files / openinference_instrumentation_autogen_agentchat-0.1.21-py3-none-any.whl
| Download URL | openinference_instrumentation_autogen_agentchat-0.1.21-py3-none-any.whl |
|---|---|
| Size | 17.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8e573cd05ee8551eeb404ecaf380cd48a22b5dbed0be4658520c39a8819e4231
|
|
BLAKE2b-256 checksum How to use checksums |
7466339ba0851ed74b8807383ae9273f9394bc65e9df6697dc6260cfe8f03469
|
| 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