> ## Documentation Index
> Fetch the complete documentation index at: https://developers.agentx.so/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Agents SDK

> Evaluate an agent built on the OpenAI Agents SDK (the `agents` / `openai-agents` package)

This is a different package from plain [`openai`](/sdk/evaluations/examples/openai): the Agents SDK (`import agents`) adds its own `Agent`/`Runner` abstraction, tool calling, and handoffs on top of the Chat Completions/Responses APIs. Use this page if your code imports from `agents`; use the OpenAI page if you're calling `openai.chat.completions.create()` directly.

Install:

```bash theme={null}
pip install agentx-python openai-agents
```

## Usage

```python theme={null}
from agentx import AgentX
from agents import Agent, Runner, function_tool

client = AgentX.from_env()

@function_tool
def get_policy(topic: str) -> str:
    """Look up a company policy by topic."""
    db = {
        "cancel": "Go to Account → Subscription → Cancel.",
        "refund": "Full refund within 30 days.",
    }
    return db.get(topic.lower(), "No policy found.")

agent = Agent(
    name="support-agent",
    instructions="You are a helpful support agent. Use get_policy to look up policies.",
    tools=[get_policy],
)

def openai_agents_eval(case):
    result = Runner.run_sync(agent, case.query)
    return {"output": result.final_output}

run_context = (
    client.evaluations
    # "openai-agents" isn't a valid EvaluationSubject.framework value (see note below), so "other"
    # is the correct value here, distinct from what you pass to tracer.trace(framework=...).
    .run(dataset_id="...", subject={"kind": "custom_agent", "displayName": "Support Agent", "framework": "other"})
    .execute(openai_agents_eval)
    .finalize()
)
print(f"Average rating: {run_context.average_rating:.2f}")
```

<Note>
  `EvaluationSubject.framework` only accepts a fixed set of values (`"raw_python"`, `"openai"`, `"anthropic"`, `"google"`, `"langchain"`, `"llamaindex"`, `"crewai"`, `"autogen"`, `"n8n"`, `"flowise"`, `"other"`). `"openai-agents"` isn't one of them, so `subject.framework` must be `"other"` here. This is unrelated to `tracer.trace(framework=...)` below, which accepts any string and does use `"openai-agents"`; the two `framework` fields are independent and differently constrained.
</Note>

## With tracing

Unlike Anthropic/LangChain/CrewAI, there's no way to get `trace_id` back from the Agents SDK's own tracing integration ([`AgentXTracingProcessor`](/sdk/integrations/openai-agents)). It's a processor you register once at startup and it reports on its own schedule as runs complete elsewhere in the SDK, not a span your eval function controls. To link a trace to an eval result, wrap `Runner.run_sync(...)` in `tracer.trace(..., sync=True)` directly instead, the same pattern as the [raw OpenAI example](/sdk/evaluations/examples/openai#with-tracing):

```python theme={null}
from agentx import AgentX
from agents import Agent, Runner

client = AgentX.from_env()

agent = Agent(name="support-agent", instructions="You are a helpful support agent.")

def openai_agents_eval(case):
    with client.tracer.trace(
        "openai-agents-call",
        input={"query": case.query},
        framework="openai-agents",
        sync=True,
        monitor=False,  # the run's judge already scores this case
    ) as span:
        result = Runner.run_sync(agent, case.query)
        span.output = result.final_output

    return {
        "output": result.final_output,
        "trace_id": span.trace_id,
    }
```

<Note>
  If you *also* want every other (non-eval) run of this agent traced automatically, not just the ones going through an evaluation, register [`AgentXTracingProcessor`](/sdk/integrations/openai-agents) globally in addition to the pattern above. The two don't conflict, but they are independent: the processor's traces are separate from, and won't be linked to, any eval result's `trace_id`.
</Note>

## `EvaluationCase` fields

Same contract as every other framework: see [Examples overview](/sdk/evaluations/examples/overview) for the full `EvaluationCase`/return-value reference. `case.query` is what you pass to `Runner.run_sync(agent, case.query)`.
