Skip to content

Python docs for the openai-agents integration #14113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions docs/platforms/python/integrations/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra

### AI

| | **Auto-enabled** |
| ------------------------------------------------------------------------------------------------------------------------------------ | :--------------: |
| <LinkWithPlatformIcon platform="anthropic" label="Anthropic" url="/platforms/python/integrations/anthropic" /> | ✓ |
| <LinkWithPlatformIcon platform="huggingface" label="Huggingface Hub" url="/platforms/python/integrations/huggingface_hub" /> | ✓ |
| <LinkWithPlatformIcon platform="langchain" label="Langchain" url="/platforms/python/integrations/langchain" /> | ✓ |
| <LinkWithPlatformIcon platform="openai" label="OpenAI" url="/platforms/python/integrations/openai" /> | ✓ |
| | **Auto-enabled** |
| -------------------------------------------------------------------------------------------------------------------------------------- | :--------------: |
| <LinkWithPlatformIcon platform="anthropic" label="Anthropic" url="/platforms/python/integrations/anthropic" /> | ✓ |
| <LinkWithPlatformIcon platform="huggingface" label="Huggingface Hub" url="/platforms/python/integrations/huggingface_hub" /> | ✓ |
| <LinkWithPlatformIcon platform="langchain" label="Langchain" url="/platforms/python/integrations/langchain" /> | ✓ |
| <LinkWithPlatformIcon platform="openai" label="OpenAI" url="/platforms/python/integrations/openai" /> | ✓ |
| <LinkWithPlatformIcon platform="openai-agents" label="OpenAI Agents SDK" url="/platforms/python/integrations/openai-agents" /> | |

### Data Processing

Expand Down
115 changes: 115 additions & 0 deletions docs/platforms/python/integrations/openai-agents/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
title: OpenAI Agents
description: "Learn about using Sentry for OpenAI Agents SDK."
---

<Alert title="Beta">

The support for **OpenAI Agents SDK** is in its beta phase. Please test locally before using in production.

</Alert>

This integration connects Sentry with the [OpenAI Python SDK](https://openai.github.io/openai-agents-python/).
The integration has been confirmed to work with OpenAI Agents version 0.0.19.

Once you've installed this SDK, you can use [Sentry AI Agents Insights](https://sentry.io/orgredirect/organizations/:orgslug/insights/agents/), a Sentry dashboard that helps you understand what's going on with your AI agents.

Sentry AI Agents monitoring will automatically collect information about agents, tools, prompts, tokens, and models.

## Install

Install `sentry-sdk` from PyPI:

```bash {tabTitle:pip}
pip install "sentry-sdk"
```

```bash {tabTitle:uv}
uv add "sentry-sdk"
```

## Configure

Add `OpenAIAgentsIntegration()` to your `integrations` list:

```python
import sentry_sdk
from sentry_sdk.integrations.openai_agents import OpenAIAgentsIntegration

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Add data like inputs and responses to/from LLMs and tools;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
integrations=[
OpenAIAgentsIntegration(),
],
)
```

## Verify

Verify that the integration works by running an AI agent. The resulting data should show up in your AI Agents Insights dashboard.

```python
import asyncio
import random

import sentry_sdk
from sentry_sdk.integrations.openai_agents import OpenAIAgentsIntegration

import agents
from pydantic import BaseModel # installed by openai-agents

@agents.function_tool
def random_number(max: int) -> int:
return random.randint(0, max)

class FinalResult(BaseModel):
number: int

random_number_agent = agents.Agent(
name="Random Number Agent",
instructions="Generate a random number.",
tools=[random_number, ],
output_type=FinalResult,
model="gpt-4o-mini",
)

async def main() -> None:
sentry_sdk.init(
dsn="...", # same as above
# Add data like LLM and tool inputs/outputs;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
integrations=[
OpenAIAgentsIntegration(),
],
)

await agents.Runner.run(
random_number_agent,
input=f"Generate a random number between 0 and {10}.",
)

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

It may take a couple of moments for the data to appear in [sentry.io](https://sentry.io).

## Behavior

Data on the following will be collected:

- AI agents invocations
- execution of tools
- number of input and output tokens used
- LLM models usage

Sentry considers LLM and tool inputs/outputs as PII and doesn't include PII data by default. If you want to include the data, set `send_default_pii=True` in the `sentry_sdk.init()` call.

## Supported Versions

- OpenAI Agents SDK: 0.0.19+
- Python: 3.9+