OpenAI Agents
Learn about using Sentry for OpenAI Agents SDK.
Beta
The support for OpenAI Agents SDK is in its beta phase. Please test locally before using in production.
This integration connects Sentry with the OpenAI Python SDK. 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, 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 sentry-sdk
from PyPI:
pip install "sentry-sdk"
Add OpenAIAgentsIntegration()
to your integrations
list:
import sentry_sdk
from sentry_sdk.integrations.openai_agents import OpenAIAgentsIntegration
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
# 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 that the integration works by running an AI agent. The resulting data should show up in your AI Agents Insights dashboard.
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.
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.
- OpenAI Agents SDK: 0.0.19+
- Python: 3.9+
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").