Skip to main content

Installation

pip install pandaprobe[openai-agents]

Setup

from pandaprobe.integrations.openai_agents import OpenAIAgentsAdapter

adapter = OpenAIAgentsAdapter(
    session_id="conversation-123",
    user_id="user-abc",
    tags=["production"],
)
adapter.instrument()
Unlike other integrations that use monkey-patching, the OpenAI Agents SDK integration registers a TracingProcessor via the SDK’s first-class callback interface. This is the cleanest integration pattern.

Usage

from agents import Agent, Runner

agent = Agent(
    name="my-assistant",
    instructions="You are a helpful assistant.",
    model="gpt-4o",
)

result = Runner.run_sync(agent, "What is PandaProbe?")
print(result.final_output)

What gets traced

SDK Span TypePandaProbe KindDescription
agentAGENTAgent execution with tools, handoffs, output_type metadata
handoffAGENTAgent handoff with from_agent / to_agent metadata
responseLLMResponses API call with input, output, model, usage, reasoning
generationLLMChat Completions call with messages, model, usage
functionTOOLFunction tool call with JSON-parsed input/output
guardrailOTHERGuardrail check with triggered metadata
customOTHERCustom span with custom_data metadata

I/O propagation

The adapter automatically propagates input/output from LLM spans to their parent agent and the root trace:
  • First LLM input becomes the agent span’s input
  • Last LLM output becomes the agent span’s output
  • Last user message becomes the trace input; last assistant message becomes the trace output

Example with tools

from agents import Agent, Runner, function_tool

@function_tool
def get_weather(city: str) -> str:
    """Get the weather for a city."""
    return f"Sunny, 72F in {city}"

agent = Agent(
    name="weather-assistant",
    instructions="Help users check the weather.",
    model="gpt-4o",
    tools=[get_weather],
)

result = Runner.run_sync(agent, "What's the weather in Tokyo?")
This produces: CHAIN (root) → AGENT (weather-assistant) → LLM (response) → TOOL (get_weather) → LLM (final response).

Token usage mapping

OpenAI Agents FieldPandaProbe Field
input_tokens / prompt_tokensprompt_tokens
output_tokens / completion_tokenscompletion_tokens
total_tokenstotal_tokens
input_tokens_details.cached_tokenscache_read_tokens
output_tokens_details.reasoning_tokensreasoning_tokens