Skip to Content

How do I see retries and fallbacks in an agent built with AutoGen?

Rius shows each AutoGen model call and tool call as its own span, so a repeated call or a call to a second model appears as an extra row in the trace. A retry or fallback that your own code decides on gets a span only when you wrap it with observe. Failed attempts are highlighted in the trace, and a run that fails along the way and still finishes clean is badged recovered.

How it works

The AutoGen integration records the run’s structure on its own:

  • AutoGen emits create_agent, invoke_agent and execute_tool spans, and Rius shows them with no wrappers.
  • Each model call through the OpenAI client arrives as a ChatCompletion generation with model, tokens and cost.

So if the framework calls the model or a tool again, each call is its own span under invoke_agent. A fallback to a different model reads as a second generation whose Model section shows a different requested model.

The decision to retry or fall back lives in your code. A loop or try/except around agent.run leaves no span of its own, so the trace shows the calls but not the reason for them. Wrap each attempt in observe to give every attempt a named span that groups the framework spans beneath it.

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

On the trace page:

  • Failed spans are highlighted along the path from the root to the error.
  • Recovered runs. A failed trace whose root span finished without an error of its own is badged recovered. Child spans errored, the agent retried or fell back, and the run completed clean. The errors still count.
  • Retry chains. Back-to-back calls of the same tool or step with the same input collapse into one row, such as fetch_article · 3 attempts · recovered, when every attempt but the last failed. Expand the row for the individual attempts.

Framework span statuses arrive as UNSET rather than OK on success. The trace status still reads completed.

Two kinds of retry stay inside one span. The OpenAI client under OpenAIChatCompletionClient retries a failed request on its own (max_retries, 2 by default), so those attempts show as one ChatCompletion generation. And an exception in a tool is caught by AutoGen and returned to the model as an error result, so it does not reach your try/except; the model decides whether to call the tool again.

Set it up

  1. Install the SDK with the OpenAI integration and AutoGen. AutoGen covers the full setup.
pip install "glassflow-rius[openai]" "autogen-agentchat" "autogen-ext[openai]"
  1. Put one observe on the entrypoint, and one on the function that makes a single attempt. Your own retry or fallback logic sits between them. The names run_attempt and attempt are yours to choose.
import asyncio 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" # stand-in for your account lookup def account_status(email: str) -> str: """Fetch a customer's account standing by email.""" return lookup(email) @rius.observe(name="attempt") async def run_attempt(ticket: str, model: str) -> str: agent = AssistantAgent( name="support_agent", model_client=OpenAIChatCompletionClient(model=model), 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) @rius.observe(name="handle-ticket", kind=SpanKind.AGENT) async def handle_ticket(ticket: str) -> str: try: return await run_attempt(ticket, "gpt-5-mini") except Exception: # fallback: a second attempt with another model return await run_attempt(ticket, "gpt-5") print(asyncio.run(handle_ticket("Is the account for ana@example.com active?")))
  1. Run a request that fails on the first attempt. Each attempt span nests under handle-ticket, and the framework’s create_agent, invoke_agent, ChatCompletion and execute_tool spans nest under each attempt.

  2. Open the trace in Traces, as described in Exploring traces. Look for the highlighted failed span, the second attempt span, and the model name on each ChatCompletion generation.

To count retries of the same call, use the same pattern: one attempt span per try. Use observe on your own functions only, never on the tool functions AutoGen runs.

What you get

  • Every model call and tool call from AutoGen as its own span, with tokens and cost on the generations.
  • One named span per attempt, so a retry or fallback shows up as a sibling row instead of a gap in the trace.
  • The model on each generation, so you can see which model answered after a fallback.
  • Failed spans highlighted, and a recovered badge on runs that failed along the way and finished clean.
  • Collapsed retry rows with the attempt count, expandable to each attempt.
  • A way to find these runs across many traces: the Spans tab filters by kind, status and the other trace filters. The integrations overview lists the other frameworks Rius covers. For the wider picture, see Monitor AI agents in production.

When something else fits

  • If you only need to know whether a run ended clean, the trace status and the recovered badge already tell you, with no extra spans.
  • If your retry happens in code you do not control, you see only the extra framework spans it produces, not why they happened.

Still stuck? Get help

Last updated on