Skip to content
GitHubLog inStart free
cetra is not released yet. These docs describe the development version.

OpenAI Agents SDK

cetra traces OpenAI Agents SDK runs as a tree of agent, turn, model call and tool spans.

Terminal window
pip install "cetra-sdk[openai-agents]" openai-agents
import cetra
from agents import Agent, Runner, function_tool
cetra.init(instrument=["openai-agents"])
@function_tool
def get_weather(city: str) -> str:
return f"It is 18 degrees and sunny in {city}."
agent = Agent(
name="weather",
instructions="You are a weather assistant.",
tools=[get_weather],
)
Runner.run_sync(agent, "What is the weather in Paris?")
cetra.flush()

With the OpenInference instrumentation, one run with a function tool produces:

  • an agent span for the workflow and one for the agent;
  • one chain span per turn;
  • an llm span for each model call, with the provider, token counts and cost;
  • a tool span for the function tool.
  • The fixtures were captured with openai-agents 0.24.0, OpenInference 2.7.0 and OpenLLMetry 0.62.4.
  • The SDK’s own tracing to OpenAI is a separate feature. This page covers the OpenTelemetry instrumentation.