Skip to main content
Agency Swarm supports multiple observability approaches to help you track and analyze your agent’s behavior and performance.

Usage Payload

When usage tracking is enabled, responses include a usage object with token counts and cost.
Fields:
  • request_count: Number of model requests
  • cached_tokens: Tokens served from cache (if available)
  • input_tokens: Tokens sent to the model
  • output_tokens: Tokens generated by the model
  • total_tokens: Total tokens for the request
  • total_cost: Estimated cost (USD)
  • reasoning_tokens (optional): Reasoning tokens (if available)
Where you’ll see it:
  • FastAPI Integration: POST /get_response returns JSON with usage, and the final event: messages in POST /get_response_stream includes usage.
  • Running an Agency: use /cost in the TUI to see session usage and cost.

Supported Observability Platforms

Agency Swarm supports three main observability approaches:

OpenAI Tracing

Built-in tracing using OpenAI’s native tools

Langfuse

Advanced tracing and debugging platform

AgentOps

Specialized agent monitoring and analytics

Getting Started

Let’s walk through setting up each tracing solution. You can use them individually or combine them for monitoring.
1

Basic Setup

OpenAI tracing is built into Agency Swarm and requires no additional packages.
2

Implementation

3

View Traces

After running your code, view your traces at platform.openai.com/traces

Custom Model Endpoints

When OPENAI_BASE_URL points anywhere other than api.openai.com, Agency Swarm stops the Agents SDK from uploading traces to OpenAI. The SDK sends traces to OpenAI with OPENAI_API_KEY, wherever your model calls go, and with a custom endpoint that key belongs to the endpoint. Langfuse, AgentOps and any processor you add still receive every trace.
  • Keep uploading traces to OpenAI: set OPENAI_AGENTS_DISABLE_TRACING=0 before you start your app, and give the exporter an OpenAI key with agents.set_tracing_export_api_key("sk-...").
  • Turn tracing off everywhere: set OPENAI_AGENTS_DISABLE_TRACING=1.
  • Send traces to your own collector: add a processor after you import Agency Swarm.
BackendSpanExporter sends the OpenAI trace format. For another format, write your own processor; see the Agents SDK tracing guide.
Agency Swarm checks OPENAI_BASE_URL once, when you import it, after it loads your .env file. These setups still upload traces to OpenAI with OPENAI_API_KEY:
  • OPENAI_BASE_URL set in your code after the import.
  • Tracing set up before the import, such as a processor added with agents.add_trace_processor(). Agency Swarm leaves that setup as it is.
  • An agent model built with its own AsyncOpenAI(base_url=...) client.
To stop those uploads, set OPENAI_AGENTS_DISABLE_TRACING=1 or replace the processors with agents.set_trace_processors().

Implementation Example

For a complete working example that demonstrates all three tracing methods with a multi-agent agency, see observability.py in the examples directory. The example shows:
  • How to set up a basic agency with CEO, Developer, and Data Analyst roles
  • Implementation of all three tracing methods (OpenAI, Langfuse, AgentOps)
  • A sample tool for data analysis
  • Error handling and proper tracing setup
You can run the example with:
For more information about each platform’s capabilities and configuration options, refer to their respective documentation: