OpenAI Agents SDK Tracing

Trace OpenAI Agent calls using OpenInference and view traces in Arize.

Openai-agents is an AI agent framework developed by OpenAI, designed for easy agent orchestration and tool use. You can view two examples below! To get started, sign up for a free Arize account and get your Space ID and API Key.

Example
Links

Tracing

Full Cookbook

Install

pip install openinference-instrumentation-openai-agents openai-agents arize-otel

API Key Setup

Add your OpenAI API key as an environment variable. The OpenAI Agents SDK will use this to interact with OpenAI models.

export OPENAI_API_KEY='your_openai_api_key'

Setup

Use the register function to connect your application to Arize and instrument the OpenAI Agents.

# Import open-telemetry dependencies
from arize.otel import register

# Setup OTel via our convenience function
tracer_provider = register(
    space_id = "your-space-id",    # in app space settings page
    api_key = "your-api-key",      # in app space settings page
    project_name="agents"          # As used in the example, or your preferred project name
)

from openinference.instrumentation.openai_agents import OpenAIAgentsInstrumentor
OpenAIAgentsInstrumentor().instrument(tracer_provider=tracer_provider)

Run your Agent

Now you can run your openai-agents code as usual.

from agents import Agent, Runner # Assuming 'agents' package provides these

# Ensure OPENAI_API_KEY is set in your environment

agent = Agent(name="Assistant", instructions="You are a helpful assistant")
result = Runner.run_sync(agent, "Write a haiku about recursion in programming.")
if result:
    print(result.final_output)
else:
    print("Agent execution did not produce a result or failed.")

Observe

Once you've started your instrumentation, all invocations and steps of your Agent will be sent to your Arize account for observability and evaluation.

Resources

Last updated

Was this helpful?