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

# OpenAI Agents SDK

> Capture traces from the OpenAI Agents SDK over OTLP

## Choose a setup method

| Method              | Use it when                                                                    |
| ------------------- | ------------------------------------------------------------------------------ |
| **Agnost AI skill** | You want your coding agent to inspect the app, make the change, and verify it. |
| **Agnost AI SDK**   | You want explicit control over the interaction boundaries and fields.          |
| **OpenTelemetry**   | The framework already emits useful spans or you operate an OTel pipeline.      |

Start with one method for a call path. Combining SDK tracking with framework
OpenTelemetry on the same call can create duplicate interactions.

## Recommended: Agnost AI skill

<Note>
  **Recommended.** Choose this path when you want your coding agent to inspect the
  project, select a supported transport, make the smallest instrumentation change,
  send a test event, and verify that it reached Agnost AI.
</Note>

Install the skill once in your coding-agent environment:

```bash theme={null}
npx skills add AgnostAI/skills --skill agnost-ai
```

Run the framework-specific prompt below from the application root. Review the
resulting diff before deploying it.

```text theme={null}
Use the agnost-ai skill to add Agnost AI analytics to this OpenAI Agents application.
Org ID: your-org-id
Instrument the real Runner call and verify one fresh interaction.
```

## Manual setup: Agnost AI SDK

```bash theme={null}
pip install agnost
```

```python theme={null}
import agnost
from agents import Runner

agnost.init("your-org-id")
interaction = agnost.begin(user_id="u-42", agent_name="openai-agent", input=prompt)
try:
    result = Runner.run_sync(agent, prompt)
    interaction.end(output=str(result.final_output))
except Exception as exc:
    interaction.end(output=str(exc), success=False)
    raise
finally:
    agnost.shutdown()
```

## Manual setup: OpenTelemetry

### Install

```bash theme={null}
pip install openai-agents openinference-instrumentation-openai-agents \
            opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
```

### Setup

```python theme={null}
import os
from agents import set_tracing_disabled
from openinference.instrumentation.openai_agents import OpenAIAgentsInstrumentor
from openinference.instrumentation import using_attributes
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "https://otel.agnost.ai"
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = "X-Agnost-Org-ID=<your-org-id>"

set_tracing_disabled(True)  # turn off OpenAI's hosted trace backend

provider = TracerProvider()
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
trace.set_tracer_provider(provider)
OpenAIAgentsInstrumentor().instrument(tracer_provider=provider)

with using_attributes(session_id="sess-123", user_id="u-42"):
    await Runner.run(agent, "Hello")
```

You get agent / handoff / guardrail spans plus the underlying LLM call spans with full message and tool data (`llm.input_messages.*`, `llm.output_messages.*`, `tool.name`, `tool.parameters`, `llm.token_count.*`).

### Caveats

Without `set_tracing_disabled(True)`, traces also flow to OpenAI's hosted dashboard.

### Verify

Run one `Runner.run` call, then open **Events** in Agnost AI. Confirm agent, handoff, guardrail, and LLM spans are present.

### Troubleshooting

* Call `set_tracing_disabled(True)` if you do not want dual-send to OpenAI's hosted trace backend.
* Confirm `OTEL_EXPORTER_OTLP_HEADERS` contains `X-Agnost-Org-ID=<your-org-id>`.
* Confirm `using_attributes` wraps the call you want grouped.

### References

* [Enable OpenTelemetry export](https://openai.github.io/openai-agents-python/tracing/)
* [Add custom metadata](https://openai.github.io/openai-agents-python/tracing/#properties)

## Next steps

* [Conversations](/using-conversations): review the complete agent run.
* [Events](/using-events): inspect model calls, handoffs, guardrails, and tools.
* [Intents](/using-intents): organize production conversations by what users wanted.
