AutoGen
Auto-instrumentation for AutoGen conversational agents.
Risicare provides deep integration with AutoGen for conversational agent observability.
Python only
Version Compatibility
autogen-agentchat >= 0.4.0 and autogen-ext[openai]. The v0.2 samples need pyautogen 0.2.x: they were run with pyautogen 0.2.35, which installs on Python 3.12 or earlier.Installation
# v0.4 (autogen-agentchat). The extra installs autogen-agentchat only.
pip install 'risicare[autogen]' 'autogen-ext[openai]'
# v0.2 (pyautogen), on Python 3.12 or earlier
pip install risicare 'pyautogen>=0.2,<0.3'Basic Usage
v0.2 (pyautogen)
import risicare
from autogen import AssistantAgent, UserProxyAgent
risicare.init()
# Define agents as usual - they're automatically traced
assistant = AssistantAgent(
name="assistant",
llm_config={"model": "gpt-4o"}
)
# code_execution_config=False: no code execution. The default needs Docker.
user_proxy = UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER",
code_execution_config=False
)
# Start conversation - fully traced.
# max_turns=1: one answer. Without a limit, the two agents continue until the
# assistant answers exactly "TERMINATE", for up to 100 model calls.
user_proxy.initiate_chat(
assistant,
message="Write a Python function to calculate fibonacci",
max_turns=1
)v0.4 (autogen-agentchat)
import risicare
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models.openai import OpenAIChatCompletionClient
risicare.init()
model_client = OpenAIChatCompletionClient(model="gpt-4o")
assistant = AssistantAgent(
name="assistant",
model_client=model_client,
)
# v0.4 uses an async, task-based API
team = RoundRobinGroupChat([assistant], max_turns=1)
result = await team.run(task="Write a Python function to calculate fibonacci")v0.4 spans
A v0.4 team run (team.run()) sends one autogen.agent/<name>/turn span for each agent turn, and the spans of the model calls. The fields under "What's Captured" below are for v0.2.
What's Captured
Agent Details
| Field | Description |
|---|---|
agent.role | Agent role |
agent.name | Agent name |
agent.type | "autogen" |
Conversation Flow
| Field | Description |
|---|---|
framework.autogen.sender | Sending agent |
framework.autogen.last_sender | Last sender |
framework.autogen.last_message | Last message |
framework.autogen.message_content | Message content |
framework.autogen.message_count | Number of messages |
framework.autogen.input_message_count | Input message count |
framework.autogen.total_messages | Total messages |
framework.autogen.max_turns | Max turns |
framework.autogen.reply | Generated reply (when content tracing is enabled) |
framework.autogen.response | Generated response (when content tracing is enabled) |
Code Execution
Limited Capture
Code execution appears in the span timeline as part of the conversation flow, but code-specific attributes (language, code content, output, exit code) are not captured by auto-instrumentation.
v0.2 samples
pyautogen 0.2.x).Group Chat
Multi-agent group chats are fully traced:
from autogen import GroupChat, GroupChatManager
coder = AssistantAgent(name="coder", llm_config={"model": "gpt-4o"})
reviewer = AssistantAgent(name="reviewer", llm_config={"model": "gpt-4o"})
agents = [user_proxy, coder, reviewer]
groupchat = GroupChat(
agents=agents,
messages=[],
max_round=10
)
manager = GroupChatManager(groupchat=groupchat)
# All agent interactions traced
user_proxy.initiate_chat(
manager,
message="Build a web scraper"
)Risicare captures:
- Turn-taking sequence
- Agent responses
Function Calling
Function/tool calls are traced.
v0.2 Syntax
tools parameter on AssistantAgent.def get_weather(location: str) -> str:
return f"Weather in {location}: Sunny"
assistant = AssistantAgent(
name="assistant",
llm_config={
"model": "gpt-4o",
"functions": [{
"name": "get_weather",
"parameters": {...}
}]
}
)
assistant.register_function(
function_map={"get_weather": get_weather}
)Code Execution
Code execution appears in the span timeline when agents run code:
from autogen.coding import LocalCommandLineCodeExecutor
executor = LocalCommandLineCodeExecutor(work_dir="coding")
user_proxy = UserProxyAgent(
name="user_proxy",
code_execution_config={"executor": executor}
)
# Code execution is visible in the span timeline,
# but code-specific attributes (content, language,
# output, errors) are not captured.Nested Chats
Nested conversations maintain trace hierarchy:
specialist = AssistantAgent(name="specialist", llm_config={"model": "gpt-4o"})
assistant.register_nested_chats(
# max_turns=1 limits the nested chat to one answer
[{"recipient": specialist, "message": "Help with this", "max_turns": 1}],
trigger=user_proxy # AutoGen calls a trigger function with the sending agent, not with the message
)
# Nested chats traced as child spansHuman-in-the-Loop
There is no dedicated span or event for human input. The human's answer is the
reply of the user proxy's autogen.agent/<name>/reply span (the text is recorded
only when content capture is on), and the wait is part of that span's duration.
Termination
The termination condition is not recorded. The chat span records the number of
messages in the chat (framework.autogen.total_messages).
Provider Spans
AutoGen instrumentation creates agent/framework-level spans. Underlying LLM calls (e.g., OpenAI, Anthropic) are traced separately by provider instrumentation, giving you both framework-level and LLM-level visibility.
Visualization
View AutoGen execution in the dashboard:
- The trace page: the span waterfall and the timeline of the run
- The Agents page: statistics for each agent