OpenAI Agents SDK monitoring that tells you which run to open
OpenAI Agents SDK monitoring with Amiril. Send the SDK's traces over OpenTelemetry, see every run ranked by rarity and hear about new issues in Slack.
OpenAI Agents SDK monitoring with Amiril. Send the SDK's traces over OpenTelemetry, see every run ranked by rarity and hear about new issues in Slack.
The OpenAI Agents SDK writes a trace of every run without being asked, so a busy agent soon has thousands for you to choose from. We build Amiril, which does OpenAI Agents SDK monitoring from those same traces, sent over OpenTelemetry. It ranks each run by how unusual it was for that agent and it posts to Slack when an issue forms at High severity or above. Sending the traces takes one pip install and about ten lines at startup.
Tracing is on by default in the Python SDK. Each Runner.run becomes a trace, and inside it the SDK opens a span for every model call, function tool call, handoff and guardrail, according to OpenAI's tracing docs. The spans go to OpenAI's backend in batches and show up in the Traces dashboard, under the name "Agent workflow" unless you give the trace one. Tool arguments and model inputs are recorded too, because trace_include_sensitive_data defaults to true. The same page notes that tracing is unavailable for organisations using OpenAI's APIs under Zero Data Retention.
A trace says what happened in one run. Knowing whether it was normal takes a baseline, and the one we chose for OpenAI Agents SDK monitoring is the same agent's earlier runs: a tool argument or a sequence of steps the agent rarely produces gets flagged. Nothing in that comparison depends on the Agents SDK, so our agent observability works the same way on traces from LangGraph or CrewAI.
The SDK keeps its spans in its own format. OpenInference, Arize's open-source set of OpenTelemetry instrumentations, has a trace processor that converts them to OpenTelemetry spans. Install it beside the OpenTelemetry SDK and an OTLP exporter:
pip install openinference-instrumentation-openai-agents opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
Run this once when the agent starts, before its first run:
from openinference.instrumentation.openai_agents import OpenAIAgentsInstrumentor from opentelemetry import trace from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor provider = TracerProvider() provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter())) trace.set_tracer_provider(provider) OpenAIAgentsInstrumentor().instrument(tracer_provider=provider, exclusive_processor=False) # keep OpenAI's Traces dashboard too
The exporter reads the standard OpenTelemetry variables. In Amiril, open the Data page and select Set up a new installation. Create a key in the panel that opens and copy the OpenTelemetry traces endpoint from the same place:
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="<OpenTelemetry traces endpoint>" export OTEL_EXPORTER_OTLP_TRACES_PROTOCOL="http/protobuf" export OTEL_EXPORTER_OTLP_TRACES_HEADERS="Authorization=Bearer <your API key>"
Runs appear on the Traces page under the name you passed to Agent, so Agent(name="support") becomes the support agent. TypeScript uses @arizeai/openinference-instrumentation-openai-agents instead, and both languages are in the OpenAI Agents SDK guide in our docs.
The instrument() call passes exclusive_processor=False because the default, True in the instrumentor's source, replaces the SDK's trace processors rather than adding one, and your runs would stop reaching OpenAI's Traces dashboard. With openinference-instrumentation-openai-agents 2.9.0 and openai-agents 0.26.2, the default leaves the OpenInference processor as the only one registered after instrument(), and False keeps both.
Take a shop's support agent with two tools, lookup_order and issue_refund. Amiril learns what this agent's calls usually look like from its own runs in the same environment, and from no other agent's. A refund far outside that shows on the run's page as a rarity factor:
args.amount was 640 on an issue_refund call, the largest of 900 observations
The order total was 64.00, and issue_refund returned success for 640, so the trace has no error span and its timings look like those of any other refund.
Each rarity factor is measured in bits, and a run's rarity is the bits of its three strongest added together. The run page shows where that puts it among every run in the environment over the last 30 days, such as Top 1%, and hovering shows the bits behind it. Rarity factors also cover the shape of a run: if the support agent nearly always calls lookup_order before issue_refund and this run skipped it, that is one too. A run that made far more calls than usual is filed as an unusual trajectory.
You set how many runs you want to review, as a number a week or a share of all runs, on the Review budget page in Settings. Amiril turns that budget into a bar for each agent, and runs that reach it wait on the Anomalies page with the rarest first. Mark a run as normal and Amiril learns that its rarity factors are noise for this agent. After two such reviews they stop counting toward the rarity.
Amiril groups runs that share one problem into an issue, which has a severity and a state such as Open or Resolved. Some issues need only one run to start. Every run gets a grounding check, which looks for a time, a date, a phone number or another number that the agent stated and that no tool result or earlier message contains. When the support agent tells a customer to call a number about their refund, and neither the customer nor any tool gave it that number, that run opens an issue at Critical.
Connect Slack on the Alerts page in Settings and choose a channel for the environment. An issue that forms at High or above is posted at once:
support has a new issue. Stated a phone number the user did not give. Severity Critical Runs 1 Environment production [Open issue]
At 08:00 UTC the channel also gets a digest of the open issues seen in the last seven days that came back after being resolved, grew after being ignored or are rising. An issue's Alerts menu can snooze it for a day, 7 days or 30 days to keep it out of the digest.
Anomalies are grouped too: once three of them share the same strongest rarity factor, a string of oversized refunds becomes one issue with a count beside it. On each issue's page Amiril's investigator reads a sample of the runs with an AI model and writes up what they have in common.
Amiril also writes a one-sentence summary of each run and groups runs with similar summaries into run topics, so you might find a topic whose runs all describe a customer promised a refund that was never issued. Label it Bad and every run that lands in it from then on joins one issue, at High, which is enough to reach Slack.
The issue's page may also carry a rule suggestion, a rule Amiril drafted from the issue's runs and tested on past ones. It keeps a draft only if it catches some of the issue's runs and fires on at most one in a hundred of the agent's other runs. For the refunds, it could read like this:
@id("refund-within-order")
@sentence("A refund of {amount} is more than the order total")
block (
agent == "support",
tool == "issue_refund"
)
unless {
order = call.args.order_id;
total = latest(lookup_order{ args.order_id == order }).result.total;
call.args.amount <= total
};Select Create rule and it opens in the editor as a draft. Published, it starts in Shadow. There it blocks nothing, and Amiril counts the calls it would have fired on from the traces you already send. Test on past calls replays it over the last 24 hours, 7 days or 30 days.
Blocking happens in the agent's own process, through the Amiril SDK and its plain module, which wraps tool functions directly instead of through a framework adapter. The OpenTelemetry setup above stays as it is, and nothing is sent twice. @sdk_agent.tool goes under the Agents SDK's @function_tool, and a run hook marks each model reply, so a rule that looks for an earlier lookup_order call finds it.
import amiril
from agents import Agent, RunHooks, Runner, function_tool
from amiril import plain
amiril.init()
sdk_agent = plain.Agent("support")
@function_tool
@sdk_agent.tool
def issue_refund(order_id: str, amount: float) -> dict:
"""Refund part or all of an order."""
return refunds.create(order_id, amount)
class MarkReplies(RunHooks):
def __init__(self, run):
self.run = run
async def on_llm_end(self, context, agent, response):
self.run.turn()
async def handle(message: str, conversation_id: str):
with sdk_agent.run(session_id=conversation_id) as run:
return await Runner.run(support, message, hooks=MarkReplies(run))Here support is your Agent(name="support", ...) with lookup_order wrapped the same way. Say the model looks up a 64.00 order and then asks for refunds of 640 and 64 in one reply. The 640 comes back to the model as a block message telling it not to retry, and the 64 goes through. The next guardrail we would give this agent is one refund per order per session, using count over earlier issue_refund calls with the same order_id.
The grounding check works from an agent's first run, and every run's rarity factors are measured against the runs before it. If your agent runs on the OpenAI Agents SDK, send its traces to Amiril and start with the Issues page.