Skip to Content

How do I see which step was slow in an agent built with AutoGen?

Rius records each agent run, model call and tool call in an AutoGen agent as its own timed span, so you open the trace and read which step took the longest. The framework’s own spans and the OpenAI integration supply the steps. One observe wrapper on your entrypoint groups them into a single trace. Open it in the waterfall to compare durations, or in the map view with the latency lens.

How it works

The AutoGen integration combines two sources, and neither needs wrappers from you:

  • AutoGen’s own spans. The framework emits create_agent, invoke_agent and execute_tool spans through the global tracer provider that rius.init() installs. Agent construction, each agent run and each tool call arrive with their own start and end times.
  • Model calls. AutoGen calls models through the OpenAI client, so the openai integration records each call as a ChatCompletion generation with model, tokens and cost.

The one thing you add is a single observe wrapper on your entrypoint, marked as an agent span. It gives the run a root, so agent creation and invocation land in one trace per unit of work instead of separate traces.

Do not wrap your AutoGen tool functions with observe. The framework runs tools in a detached context, so the wrapper’s span splits off as its own single-span trace. The execute_tool spans already cover every tool call, with a duration.

This is how a run that calls one tool looks in the trace:

handle-ticket AGENT 2.8s ├─ create_agent support_agent 0ms └─ invoke_agent support_agent 2.8s ├─ ChatCompletion LLM 2.6s └─ execute_tool account_status 0ms

Here the model call accounts for almost all of the 2.8 seconds, so that is the slow step.

Set it up

  1. Install the SDK with the OpenAI extra, then initialize it and wrap your entrypoint once. Leave the tool function plain. The full install and init options are on the integrations page.
pip install "glassflow-rius[openai]" "autogen-agentchat" "autogen-ext[openai]"
import rius from autogen_agentchat.agents import AssistantAgent from autogen_ext.models.openai import OpenAIChatCompletionClient from rius import SpanKind rius.init(api_key="ri_...", service_name="my-agent") def lookup(email: str) -> str: return "active" # replace with your own account lookup def account_status(email: str) -> str: """Fetch a customer's account standing by email.""" return lookup(email) @rius.observe(name="handle-ticket", kind=SpanKind.AGENT) async def handle_ticket(ticket: str) -> str: agent = AssistantAgent( name="support_agent", model_client=OpenAIChatCompletionClient(model="gpt-5-mini"), tools=[account_status], system_message="Answer support questions; check accounts with the tool.", ) result = await agent.run(task=ticket) return str(result.messages[-1].content)
  1. Run one request that calls a tool.
  2. Open the trace on the Traces page and find the slow step, as described in Exploring traces:
    • In the waterfall, read the duration of each span along the timeline. Spans are badged by kind, so the model call, the tool call and the agent run are easy to tell apart.
    • In the Map tab, switch to the latency lens to see which node holds the time. Clicking a node opens the tree filtered to that node’s spans.
    • To compare steps across many runs, open the Spans tab, pick a kind in the All kinds menu, and sort by the Duration header.
  3. If a step in your own code runs inside the entrypoint and AutoGen does not record it, such as a lookup you make before agent.run, wrap that function with rius.observe. It appears in the trace as its own span named after the function.

What you get

  • A timed span for agent creation, every agent run, every model call and every tool call, with no wrappers beyond the entrypoint.
  • Tokens and cost on each model call, so a slow call also shows how large it was.
  • The waterfall, map and Spans views to find the slowest step in one run or across many.
  • Your own steps, when you wrap them, in the same trace as the framework’s spans.

Two things to know when reading the trace. Model call spans are all named ChatCompletion, so tell them apart by their position in the tree and by the model and tokens on the span. Framework spans arrive with an unset status rather than OK on success, and the trace status still reads Ok.

To set up alerts on slow runs and the other ways to watch agents in production, see Monitor AI agents in production.

When something else fits

  • If your agents mix AutoGen with other frameworks or client libraries, the integrations page lists what each one records on its own.
  • If you need a slow tool call grouped under a span you control, rely on the framework’s execute_tool spans rather than wrapping the tool, since a wrapper splits into its own trace.

Still stuck? Get help

Last updated on