Skip to main content
  1. Sign up — Create an account at platform.respan.ai
  2. Create an API key — Generate one on the API keys page
  3. Add credits or a provider key — Add credits on the Credits page or connect your own provider key on the Integrations page

What is OpenAI Agents?

This integration is for agent tracing. For the OpenAI gateway integration, see OpenAI SDK.
The OpenAI Agents SDK is a lightweight framework for building multi-agent workflows with tools, handoffs, and guardrails. Respan captures every agent run as a trace so you can debug and optimize your workflows.
Agent tracing visualization

Setup

1

Install packages

pip install openai-agents respan-exporter-openai-agents
2

Set environment variables

OPENAI_API_KEY=your-openai-api-key
RESPAN_API_KEY=your-respan-api-key
RESPAN_OAIA_TRACING_ENDPOINT=https://api.respan.ai/api/openai/v1/traces/ingest
3

Initialize the exporter and run an agent

import asyncio
import os
from agents import Agent, Runner
from agents.tracing import set_trace_processors, trace
from respan_exporter_openai_agents import RespanTraceProcessor

set_trace_processors([
    RespanTraceProcessor(
        api_key=os.getenv("RESPAN_API_KEY"),
        endpoint=os.getenv("RESPAN_OAIA_TRACING_ENDPOINT"),
    ),
])

async def main():
    agent = Agent(
        name="Assistant",
        instructions="You only respond in haikus.",
    )

    with trace("Hello world test"):
        result = await Runner.run(agent, "Tell me about recursion in programming.")
        print(result.final_output)

asyncio.run(main())
4

View your trace

Open the Traces page in the Respan dashboard. Your trace should appear within a few seconds.

Configuration

The Python exporter accepts these constructor parameters:
ParameterRequiredDescription
api_keyYesYour Respan API key. Falls back to RESPAN_API_KEY.
endpointYesIngest endpoint URL. Falls back to RESPAN_OAIA_TRACING_ENDPOINT.
The JavaScript exporter reads RESPAN_API_KEY and RESPAN_BASE_URL from environment variables. You can also pass metadata on a per-trace basis:
await withTrace("My Trace", async () => {
  return run(agent, "Hello");
}, {
  metadata: { foo: "bar" }
});

Tool calls

Agents can use tools to perform specific tasks. Tool calls are automatically captured in the trace.
import asyncio
import os
from agents import Agent, Runner, function_tool
from agents.tracing import set_trace_processors
from respan_exporter_openai_agents import RespanTraceProcessor

set_trace_processors([
    RespanTraceProcessor(
        api_key=os.getenv("RESPAN_API_KEY"),
        endpoint=os.getenv("RESPAN_OAIA_TRACING_ENDPOINT"),
    ),
])

@function_tool
def get_weather(city: str) -> str:
    return f"The weather in {city} is sunny."

agent = Agent(
    name="Hello world",
    instructions="You are a helpful agent.",
    tools=[get_weather],
)

async def main():
    result = await Runner.run(agent, input="What's the weather in Tokyo?")
    print(result.final_output)

asyncio.run(main())

Handoffs

Agents can hand off conversations to other specialized agents. Handoff events are captured in the trace.
import asyncio
import os
from agents import Agent, Runner
from agents.tracing import set_trace_processors
from respan_exporter_openai_agents import RespanTraceProcessor

set_trace_processors([
    RespanTraceProcessor(
        api_key=os.getenv("RESPAN_API_KEY"),
        endpoint=os.getenv("RESPAN_OAIA_TRACING_ENDPOINT"),
    ),
])

spanish_agent = Agent(
    name="Spanish agent",
    instructions="You only speak Spanish.",
)

english_agent = Agent(
    name="English agent",
    instructions="You only speak English",
)

triage_agent = Agent(
    name="Triage agent",
    instructions="Handoff to the appropriate agent based on the language of the request.",
    handoffs=[spanish_agent, english_agent],
)

async def main():
    result = await Runner.run(triage_agent, input="Hola, ¿cómo estás?")
    print(result.final_output)

asyncio.run(main())

Observability

With this integration, Respan auto-captures:
  • Agent runs — each agent execution as a span
  • LLM calls — model, input/output messages, token usage
  • Tool calls — function name, arguments, return value
  • Handoffs — which agent transferred control and to whom
  • Errors — failed runs and error details
View traces on the Traces page.
OpenAI Agents SDK trace in Respan