Skip to content
Judgment Labs
Esc
↑↓navigate↵open⌘Jpreview
On this page

OpenAI Agents SDK Tracing

Automatically trace OpenAI Agents SDK executions, handoffs, and agent interactions.

OpenAI Agents SDK integration captures traces from your OpenAI Agents applications, including agent execution flow, handoffs between agents, and individual agent calls.

Quickstart

Install Dependencies

uv add openai-agents-sdk judgeval openinference-instrumentation-openai-agents python-dotenv
pip install openai-agents-sdk judgeval openinference-instrumentation-openai-agents python-dotenv

Initialize Integration

from judgeval import Tracer
from openinference.instrumentation.openai_agents import OpenAIAgentsInstrumentor

Tracer.init(project_name="openai_agents_project")
Tracer.registerOTELInstrumentation(OpenAIAgentsInstrumentor())

Add to Existing Code

Add these lines to your existing OpenAI Agents application:

import dotenv
import os

dotenv.load_dotenv()

from judgeval import Tracer  
from openinference.instrumentation.openai_agents import OpenAIAgentsInstrumentor  

Tracer.init(project_name="openai_agents_project")  
Tracer.registerOTELInstrumentation(OpenAIAgentsInstrumentor())  

from agents import Agent, Runner
import asyncio

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
)

async def main():
    result = await Runner.run(agent, input="Hello, how are you?")
    print(result.final_output)

if __name__ == "__main__":
    asyncio.run(main())

All agent executions and handoffs are automatically traced.

Example: Multi-Agent Triage System


dotenv.load_dotenv()

from judgeval import Tracer
from openinference.instrumentation.openai_agents import OpenAIAgentsInstrumentor

Tracer.init(project_name="openai_agents_project")
Tracer.registerOTELInstrumentation(OpenAIAgentsInstrumentor())

from agents import Agent, Runner

# Define specialized agents
spanish_agent = Agent(
    name="Spanish Agent",
    instructions="You only speak Spanish. Answer all questions in Spanish.",
)

english_agent = Agent(
    name="English Agent",
    instructions="You only speak English. Answer all questions in English.",
)

french_agent = Agent(
    name="French Agent",
    instructions="You only speak French. Answer all questions in French.",
)

# Define triage agent with handoffs
triage_agent = Agent(
    name="Triage Agent",
    instructions="Determine the language of the user's request and handoff to the appropriate language-specific agent.",
    handoffs=[spanish_agent, english_agent, french_agent],
)

@Tracer.observe(span_type="function")  
async def main():
    requests = [
        "Hola, ¿cómo estás?",
        "What is the weather like today?",
        "Bonjour, comment allez-vous?",
    ]

    for request in requests:
        result = await Runner.run(triage_agent, input=request)
        print(f"Request: {request}")
        print(f"Response: {result.final_output}\n")

if __name__ == "__main__":
    asyncio.run(main())

Next Steps

Was this page helpful?