Skip to main content
Automatically capture agent loops, message histories, and tool executions within the AutoGen framework.

Setup

To capture the complete picture—including both the agent orchestrations and the underlying token costs—we highly recommend initializing both the AutoGen integration and your specific LLM provider (e.g., Google GenAI, OpenAI, Anthropic).
import traceroot
from traceroot import Integration

# Initialize AutoGen alongside your LLM provider to capture tokens and costs
traceroot.initialize(integrations=[
    Integration.AUTOGEN,
    Integration.GOOGLE_GENAI  # Or OPENAI, ANTHROPIC, etc.
])

Usage

Once initialized, agent conversations and tool calls are captured automatically:
import os
import autogen
from typing import Annotated
from autogen import register_function

llm_config = {
    "config_list": [{
        "model": "gemini-2.5-flash",
        "api_key": os.environ["GEMINI_API_KEY"],
        "api_type": "google"
    }]
}

assistant = autogen.AssistantAgent(
    name="assistant",
    llm_config=llm_config
)
user_proxy = autogen.UserProxyAgent(
    name="user_proxy",
    human_input_mode="NEVER",
    max_consecutive_auto_reply=5
)

def get_weather(city: Annotated[str, "City name"]) -> str:
    """Get current weather for a city."""
    return f"The weather in {city} is 72 degrees and sunny."

def get_forecast(city: Annotated[str, "City name"], days: Annotated[int, "Number of days"]) -> str:
    """Get a multi-day weather forecast for a city."""
    return f"{days}-day forecast for {city}: mostly sunny with highs around 70-75°F."

# Register tools — caller decides when to use them, executor runs the function
register_function(
    get_weather,
    caller=assistant,
    executor=user_proxy,
    name="get_weather",
    description="Get current weather for a city",
)
register_function(
    get_forecast,
    caller=assistant,
    executor=user_proxy,
    name="get_forecast",
    description="Get a multi-day weather forecast for a city",
)

# The entire conversation hierarchy is automatically traced
user_proxy.initiate_chat(
    assistant,
    message="What's the weather in Tokyo today, and what does the 3-day forecast look like?",
)

What Gets Captured

AttributeDescription
Conversation LoopThe overarching initiate_chat session
Agent StepsIndividual spans for each AssistantAgent or UserProxyAgent turn
MessagesFull chat history, input messages, and agent replies
Tool callsFunction names, input arguments, and execution outputs
LLM callsRaw completion requests to the provider
Tokens & CostAggregated usage and pricing for the chat session

Run the example

Clone the repo and run a complete agent end-to-end.

Python

Run the Python example