ai newsMi., 25. Nov.
EilmeldungYale’s Sonnenfeld: Nvidia is a ‘detriment’ to U.S. industrial might — not a champion

OpenAI Agents SDK im Production-Betrieb ueberwachen

Der eingebaute Trace des SDK bleibt aktiviert, und die Spans werden per OpenTelemetry an ein Tool exportiert, das ganze Konversationen bewertet. Agnost AI gruppiert Runs nach Nutzer und Session und prueft jede Konversation gegen Regeln in natuerlicher Sprache.

dev.toDienstag 07:19 · 24.11.DE11 Min. Lesezeit
Bild: dev.to

Veröffentlicht am 24. Nov • Ursprünglich veröffentlicht auf agnost.ai

Um einen Agenten des OpenAI Agents SDK in Produktion zu überwachen, sollte man das eingebaute Tracing des SDKs aktiviert lassen und dieselben Spans über OpenTelemetry an ein Tool exportieren, das ganze Konversationen beurteilt. Agnost AI wurde genau für diese Aufgabe gebaut: Es gruppiert Runs nach Nutzer und Session, beurteilt jede Konversation anhand von Regeln in einfacher Sprache, warnt über Slack oder E-Mail und öffnet bei wiederkehrenden Fehlern einen Pull Request mit einem getesteten Fix.

Offenlegung: Wir entwickeln Agnost AI. Fakten zum Agents SDK und anderen Tools stammen aus deren eigenen Dokumentationen, geprüft am 21. November 2026.

Das OpenAI Agents SDK verfolgt standardmäßig jeden Run und sendet ihn an das Traces-Dashboard in der OpenAI-Plattform. Um eine andere Observability-Plattform zu nutzen, registriert man einen Trace Processor: add_trace_processor() fügt ein Ziel hinzu und behält das von OpenAI bei, während set_trace_processors() es ersetzt. Die Tracing-Dokumentation des SDKs listet fertige Processors für Langfuse, LangSmith, Braintrust, Arize Phoenix, Weights & Biases, Pydantic Logfire, AgentOps, MLflow, Datadog, PostHog und weitere. Jedes OpenTelemetry-Backend, einschließlich Agnost, kann dieselben Spans über den OpenAIAgentsInstrumentor von OpenInference empfangen.

Traces zeigen, was gelaufen ist. Sie zeigen nicht, ob das Problem des Nutzers gelöst wurde. Ein Agent, der eine Anfrage an einen Spezialisten weitergibt, ist nicht dasselbe wie deren Lösung; eine Guardrail, die eine Aktion stoppt, ist nicht zwangsläufig ein Systemfehler, und ein abgeschlossener Run kann trotzdem eine falsche Antwort enthalten. Monitoring für das OpenAI Agents SDK sollte die öffentliche Anfrage, die Run-Ausführung, Handoffs, Tool-Ergebnisse und den beobachteten Ausgang miteinander verbinden.

Agnost AI unterstützt beide Ebenen in seiner Agents-SDK-Integration: den OpenTelemetry-Export der SDK-Spans sowie einen Konversations-Wrapper für die Anfragegrenze. Dieser Guide wurde im November 2026 mit openai-agents 0.24 und openinference-instrumentation-openai-agents 2.8 geprüft.

Für Monitoring in Produktion nutzt man Agnost AI neben dem Traces-Dashboard von OpenAI. Das Traces-Dashboard genügt, wenn man einzelne Runs nacheinander untersuchen möchte: dessen Agenten, Handoffs, Guardrails und Tool-Aufrufe, während der Entwicklung oder beim Debuggen eines gemeldeten Fehlers (unter einer Zero Data Retention Policy ist es nicht verfügbar). Es gruppiert Runs jedoch nicht zu Nutzergesprächen und zeigt nicht, welche Konversationen fehlgeschlagen sind. Agnost AI ergänzt genau diese Ebene:

Runs werden in Paketen beurteilt, sobald eine Konversation 15 Minuten inaktiv war; bestehende Fehler- und Latenz-Alerts für Echtzeit-Paging sollte man daher behalten.

Agnost zeigt die Traces ebenfalls. Agnost nimmt die OpenTelemetry-Traces selbst auf: Jede Konversation öffnet sich zu ihren Nachrichten, Spans und Fehlern, und jeder Tool-Aufruf zeigt Erfolg oder Fehlschlag, Latenz sowie seine Argumente und Ergebnisse, sofern Content-Erfassung aktiviert ist. Ein separates Tracing-Tool ist für die Nutzung von Agnost nicht nötig. OpenAIs Traces-Dashboard bleibt nützlich, um einzelne Runs während der lokalen Entwicklung und beim Debuggen zu prüfen. Teams, die Offline-Datensätze, Experimente oder CI-Gates wollen, ergänzen dafür LangSmith, Braintrust oder Langfuse.

Empfohlenes Setup. Installiere den OpenInference-Instrumentor und den OTLP-Exporter und richte den Exporter dann auf Agnost:

pip install openai-agents openinference-instrumentation-openai-agents opentelemetry-sdk opentelemetry-exporter-otlp-proto-http export OTEL_EXPORTER_OTLP_ENDPOINT = https://otel.agnost.ai export OTEL_EXPORTER_OTLP_HEADERS = "X-Agnost-Org-ID=<your-org-id>" Enter fullscreen mode Exit fullscreen mode Registriere einen TracerProvider mit einem OTLP BatchSpanProcessor, rufe OpenAIAgentsInstrumentor().instrument() auf und umschließe jeden Run mit using_attributes(session_id=..., user_id=...). Der vollständige Code steht weiter unten. Danach die ersten Regeln und Alerts in Agnost anlegen. Der Rest dieses Guides behandelt, was man überwachen sollte, sobald Traces ankommen.

Die Tracing-Dokumentation des SDKs listet insgesamt mehr als dreißig Processors, darunter AgentOps, Galileo, HoneyHive, Laminar und Maxim AI. Registriere einen mit add_trace_processor(), um OpenAIs Dashboard zu behalten, oder set_trace_processors(), um es zu ersetzen.

Runner.run, Runner.run_sync und Runner.run_streamed werden jeweils in einen Trace eingebettet. Darin erzeugt das SDK Spans für Agenten, LLM-Generierungen, Function-Tools, Guardrails und Handoffs, und custom_span() fügt eigene hinzu. Einige Einstellungen bestimmen, was man später sehen kann:

OpenAIs gehostetes Tracing steht Organisationen nicht zur Verfügung, die dessen APIs unter einer Zero Data Retention Policy nutzen.

Die Traces des SDKs sind nicht nativ OpenTelemetry. Der Instrumentor von OpenInference konvertiert sie, gemäß Agnosts OpenAI Agents Guide:

pip install openai-agents openinference-instrumentation-openai-agents \ opentelemetry-sdk opentelemetry-exporter-otlp-proto-http Enter fullscreen mode Exit fullscreen mode import os from agents import Runner, set_trace_processors from openinference. instrumentation import using_attributes from openinference. instrumentation. openai_agents import OpenAIAgentsInstrumentor 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" ] = f "X-Agnost-Org-ID={os.environ['AGNOST_ORG_ID']}" # Optional: replace the default processor so traces go only to Agnost. # Omit this line to keep sending traces to OpenAI's dashboard as well. set_trace_processors ( [ ] ) provider = TracerProvider ( ) provider. add_span_processor ( BatchSpanProcessor ( OTLPSpanExporter ( ) ) ) trace. set_tracer_provider ( provider ) OpenAIAgentsInstrumentor ( ). instrument ( tracer_provider = provider ) async def run_for_user ( agent, prompt, *, user_id, conversation_id ): with using_attributes ( session_id = conversation_id, user_id = user_id ): return await Runner. run ( agent, prompt ) Enter fullscreen mode Exit fullscreen mode Man erhält Agent-, Handoff- und Guardrail-Spans sowie die zugrunde liegenden LLM-Aufrufe mit Nachrichten- und Tool-Daten ( llm.input_messages.*, llm.output_messages.*, tool.name, tool.parameters, llm.token_count.* ). Rufe nicht set_tracing_disabled(True) auf, um den OpenAI-Export zu stoppen: Das entfernt die Trace-Objekte, die der Instrumentor liest, und Agnost empfängt nichts. Führe eine Anfrage aus und bestätige dann die Agent-, Handoff-, Guardrail- und LLM-Spans unter Events.

Monitoring-Modell für das OpenAI Agents SDK. Ein Handoff ist eine Routing-Entscheidung; eine Lösung erfordert Ausgangsnachweise.

In einer illustrativen Support-Anwendung nennt ein Nutzer eine Rechnungsreferenz und fragt, warum er doppelt belastet wurde. Ein Triage-Agent leitet die Anfrage an das Billing-Team weiter, aber der Spezialist fragt erneut nach der Rechnung.

Wenn der Kontext beim Handoff verloren ging, kann ein Wechsel des Modells des Spezialisten das Problem nicht beheben. Wenn der Kontext ankam, aber dem Tool die Berechtigung fehlte, liegt der Fehler an einer anderen Grenze. Bewahre eine sichere Ressourcenreferenz, statt vollständige Abrechnungsdetails zu exportieren.

Die wiederholte Frage des Nutzers ist ein nützlicher Hinweis auf Reibung. Sie ist kein Beweis dafür, dass jeder Handoff schädlich ist. Vergleiche Anfragen, die wirklich einen Spezialisten brauchen, mit ähnlichen Anfragen, statt das Routing undifferenziert zu minimieren.

Prüfe in Agnost zuerst die Konversation; nutze die tiefergehende Instrumentierung, die du konfiguriert hast, um Handoff und Tool zu untersuchen. Der direkte Wrapper in diesem Guide erfasst den öffentlichen Run, nicht diese internen Schritte selbst.

Produkt-Demo · illustrative Daten. Die Konversationsprüfung zeigt, ob der Agent Details behalten hat, die der Nutzer bereits geliefert hat. Für eine Agents-SDK-Anwendung untersuche die Handoff-Nachweise separat, um zu lokalisieren, wo der Kontext verloren ging. Bild auswählen, um es in voller Größe zu prüfen.

Nutze diese Definitionen, um den Messplan zu entwerfen. Berechne sie aus den erforderlichen Anwendungs- oder Tracing-Nachweisen; es handelt sich nicht alles um vorberechnete Dashboard-Metriken.

Eine Nutzer-Konversation kann mehrere Runs enthalten. Ein Run kann Modell-Aufrufe, Tools und ein Handoff umfassen. Wer diese internen Operationen als neue Nutzeranfragen zählt, macht Volumen- und Abschlussmetriken irreführend.

Behalte eine stabile Konversations-ID, die von der Anwendung geliefert wird. Erfasse für jeden Aufruf eine eigene Attempt-ID. Wenn ein externes Tool etwas ändert, bewahre zusätzlich den eigenen Bezeichner der Aktion. Ein Retry sollte nicht zu einem neuen Kunden werden, und eine wiederholte Aktion sollte nicht in einer aggregierten Erfolgszahl verschwinden.

Die offizielle Observability-Dokumentation des Agents SDK beschreibt eingebautes Tracing für Modell-Aufrufe, Tools, Handoffs, Guardrails und eigene Spans im normalen serverseitigen Ablauf. Diese Ausführungsdetails und die Ausgangsdaten des Produkts beantworten unterschiedliche Fragen.

Installiere agnost neben dem bestehenden openai-agents-Paket. Dieser Adapter akzeptiert einen Agenten, den die Anwendung bereits konfiguriert hat; er ändert weder Modell, Tools noch Instructions.

Beispielumfang: Der folgende Code ist ein Integrations-Adapter für eine bestehende Anwendung. Konfiguriere Framework, Modell, Zugangsdaten und Output-Vertrag wie beschrieben; die Demo-Screenshots wurden nicht durch Ausführen dieser Snippets erzeugt.

import os from uuid import uuid4 import agnost from agents import Runner agnost. init ( os. environ [ "AGNOST_ORG_ID" ] ) async def observed_run ( agent, prompt, *, user_id, conversation_id, output_to_text ): interaction = agnost. begin ( user_id = user_id, conversation_id = conversation_id, agent_name = "openai-support", input = prompt, properties = { "framework": "openai-agents", "agent_version": "support-v1", "attempt_id": str ( uuid4 ( ) ), }, ) if interaction is None: raise RuntimeError ( "Call agnost.init() before observed_run()" ) try: result = await Runner. run ( agent, prompt ) safe_output = output_to_text ( result. final_output ) except Exception as exc: interaction. end ( output = type ( exc ). __name__, success = False ) raise else: interaction. end ( output = safe_output, success = True ) return result Vollbildmodus öffnen Vollbildmodus verlassen Setzen Sie AGNOST_ORG_ID auf dem Server. Übergeben Sie bereinigten Prompt-Text und einen Serializer, der ausschließlich freigegebene öffentliche Ausgaben auswählt. Wenn Ihr Agent ein strukturiertes Objekt zurückgibt, serialisieren Sie nicht ungefiltert alle Felder.

Die offizielle Quickstart-Dokumentation beschreibt Runner.run und final_output.

Initialisieren Sie das Agnost SDK einmal und leeren Sie die Puffer beim Prozessende mit agnost.shutdown(). Belassen Sie die bestehenden Provider-Zugangsdaten und die Agent-Konfiguration an ihrem gewohnten ort serverseitig. Keine Zugangsdaten gehören in den Artikel oder in aufgezeichnete Prompts.

Das success-Flag des Wrappers bedeutet lediglich, dass der Lauf regulär zurückkehrte. Es bedeutet nicht, dass eine externe Aktion abgeschlossen wurde oder ein Nutzer die Antwort akzeptiert hat. Der Konversations-Bezeichner konfiguriert zudem kein Modell-Gedächtnis; behalten Sie die eigene Sitzungs- und Historieverwaltung Ihrer Anwendung bei.

Ein Handoff kann genau das richtige Verhalten sein. Ein allgemeiner Assistent kann beispielsweise eine Rechnungsfrage an einen Abrechnungsspezialisten weiterleiten. Überwachen Sie, ob die Anfrage den passenden Spezialisten erreichte und ob der Spezialist ausreichend Kontext erhielt.

Erfassen Sie stabile Agent-Identitäten und, wo verfügbar, Routing-Nachweise. Eine höhere Handoff-Rate ist nicht per se schlechter; sie kann darauf hindeuten, dass mehr Anfragen eine Spezialistenbearbeitung erfordern. Vergleichen Sie dieselben Aufgabenkategorien, bevor Sie Schlüsse ziehen.

Ein Guardrail, der eine unsichere oder nicht unterstützte Aktion blockiert, kann korrektes Produktverhalten sein. Ein Guardrail, der eine legitime Anfrage fälschlicherweise blockiert, ist ein Qualitätsproblem. Ein ausgefallener Guardrail-Dienst ist ein Betriebsproblem. Wenn Sie alle drei als "Agent-Fehler" zusammenfassen, verschleiern Sie die Maßnahme, die Sie ergreifen müssen.

Pflegen Sie eine Ursachenkategorie sowie einen überprüfbaren, angemessen bereinigten Datensatz. Der generische Exception-Zweig im Beispiel erhält Ausführungsfehler, klassifiziert aber nicht jedes Guardrail-Ergebnis. Ergänzen Sie eine anwendungsspezifische Klassifizierung anhand der Exception- und Ergebnistypen Ihres installierten SDK. Leiten Sie nicht allein aus dem Vorhandensein eines Blocks ab, ob er korrekt war.

Ein Function-Tool, das Text zurückgibt, ist kein ausreichender Nachweis dafür, dass eine Zahlung, Buchung oder Aktualisierung erfolgreich war. Erfassen Sie das maßgebliche Ergebnis der Operation in der Tool-Implementierung. Halten Sie ausstehende und unbekannte Ergebnisse explizit.

Wenn die Antwort "erledigt" sagt, während der Dienst eine Ablehnung zurückgegeben hat, untersuchen Sie, wie das Tool-Ergebnis zum Agent gelangte. Wenn dieselbe Aktion zweimal ausgeführt wird, prüfen Sie Retries und Idempotenz-Bezeichner. Wenn ein Tool langsam ist, unterscheiden Sie die Wartezeit auf das Tool von der Zeit, die das Modell für die Generierung benötigt.

Für die Ausführungsnachweise hinter einem Tool oder Handoff verwenden Sie den oben gezeigten OpenTelemetry-Export. Vergewissern Sie sich vor dem ersten Lauf, dass der Instrumentor aktiv ist, und untersuchen Sie einen realen Lauf, um die Abdeckung festzustellen.

Ein Streaming-Ergebnisobjekt ist keine abgeschlossene Antwort. Beenden Sie die Interaktion, nachdem Sie den Stream vollständig verarbeitet oder das entsprechende Abschluss-Signal erhalten haben. Erfassen Sie Fehler und Abbrüche und verhindern Sie, dass der Terminal-Handler zweimal aufgerufen wird.

Die Fertigstellung der Generierung auf dem Server ist etwas anderes als die Auslieferung im Browser. Wenn der Nutzer die Verbindung trennt, läuft das Backend möglicherweise weiter. Verknüpfen Sie Client- und Serverbeobachtungen über eine Anwendungs-Request-ID, wenn Sie messen möchten, was tatsächlich angezeigt wurde.

Verwenden Sie Users, um zusammengehörige Interaktionen zu verfolgen, und Events, um erhaltene Datensätze zu prüfen. Ordnen Sie wiederkehrende Anfragen nach konfigurierter Intention und prüfen Sie dann die Nachweise hinter Korrekturen, wiederholten Handoffs oder fehlgeschlagenen Aktionen.

Beginnen Sie mit einer konkreten, umsetzbaren Frage, etwa ob Abrechnungsanfragen den richtigen Spezialisten erreichen. Ergänzen Sie die Nachweise, die zur Beantwortung nötig sind, statt jeden verfügbaren Payload zu sammeln. Request-Dauer, Tool-Status, Routing und beobachtetes Ergebnis sind zusammen oft nützlicher als eine große Anzahl unverbundener Spans.

Für Fragen der Validierung typisierter Ausgaben fahren Sie mit dem Pydantic AI-Monitoring fort. Für die Integration selbst nutzen Sie den OpenAI-Agents-Guide von Agnost.

Stöbern Sie in allen Leitfäden zur Agent-Observability nach Frameworks.

Lassen Sie das eingebaute Tracing des SDK aktiviert und exportieren Sie dieselben Spans über OpenTelemetry in ein Tool, das ganze Konversationen überwacht. Mit Agnost AI installieren Sie openinference-instrumentation-openai-agents und den OpenTelemetry-OTLP-Exporter, richten den Exporter auf https://otel.agnost.ai mit Ihrem X-Agnost-Org-ID-Header und übergeben bei jedem Lauf session_id und user_id. Agnost gruppiert Läufe nach Nutzer und Sitzung, beurteilt jede Konversation anhand von Regeln in natürlicher Sprache, erkennt Fehler, Frustration, Tool-Aufruf-Fehler und Schleifen, warnt in Slack oder per E-Mail und kann einen Pull Request mit einem Fix öffnen, der gegen frühere Läufe getestet wurde.

OpenAI's eigenes Traces-Dashboard genügt, um einzelne Läufe, Handoffs und Guardrails zu untersuchen.

Das SDK sendet seine Traces standardmäßig an OpenAI's eigenes Traces-Dashboard. Seine Tracing-Dokumentation listet Processors für viele Drittanbieter-Plattformen auf, darunter Langfuse, LangSmith, Braintrust, Arize Phoenix, Weights & Biases, Pydantic Logfire, AgentOps, MLflow, Datadog und PostHog. Jedes OpenTelemetry-Backend, einschließlich Agnost, kann dieselben Agent-, Handoff-, Guardrail-, Tool- und LLM-Spans über OpenInference's OpenAIAgentsInstrumentor empfangen.

Nicht nativ; die Traces nutzen die eigene Processor-Schnittstelle des SDK. Das Paket openinference-instrumentation-openai-agents von OpenInference wandelt sie in OpenTelemetry-Spans um, die Sie über OTLP an jedes Backend exportieren können. Lassen Sie das SDK-Tracing aktiviert, da der Instrumentor die Trace-Objekte des SDK beobachtet.

Setzen Sie OPENAI_AGENTS_DISABLE_TRACING=1, rufen Sie set_tracing_disabled(True) auf oder setzen Sie für einen einzelnen Lauf tracing_disabled=True in RunConfig. Wenn Sie lediglich die Übermittlung der Traces an OpenAI stoppen, sie aber anderweitig exportieren möchten, rufen Sie stattdessen set_trace_processors() mit Ihren eigenen Processors auf; das Deaktivieren von Tracing stoppt auch Drittanbieter-Processors und Instrumentors, die darauf angewiesen sind.

Nein. add_trace_processor() behält den OpenAI-Export bei und ergänzt ein weiteres Ziel, und ein Konversations-Wrapper kann mit beidem koexistieren. Entscheiden Sie bewusst, wohin tiefergehende Traces exportiert werden und welcher Datensatz in Ihren Metriken eine Anfrage repräsentiert.

Es bedeutet, dass der Lauf eine finale Ausgabe erzeugt hat. Für eine abschließende Bewertung brauchen Sie ein aufgabenangemessenes Signal, etwa ein maßgebliches Aktionsergebnis oder eine explizite Prüfung.

Automatisch übersetzt. Das Original auf Englisch ist unten aufklappbar.

Original (Englisch) anzeigen

Posted on Nov 24 • Originally published at agnost.ai

To monitor an OpenAI Agents SDK agent in production, keep the SDK’s built-in tracing on and export the same spans over OpenTelemetry to a tool that judges whole conversations. Agnost AI is built for that job: it groups runs by user and session, judges each conversation against plain-language rules, alerts in Slack or email, and opens a pull request with a tested fix when a failure recurs.

Disclosure: We make Agnost AI. Facts about the Agents SDK and other tools come from their own docs, checked on November 21, 2026.

The OpenAI Agents SDK traces every run by default and sends it to the Traces dashboard in the OpenAI platform. To use another observability platform, register a trace processor: add_trace_processor() adds a destination and keeps OpenAI’s, while set_trace_processors() replaces it. The SDK’s tracing docs list ready-made processors for Langfuse, LangSmith, Braintrust, Arize Phoenix, Weights & Biases, Pydantic Logfire, AgentOps, MLflow, Datadog, PostHog, and others. Any OpenTelemetry backend, including Agnost, can receive the same spans through OpenInference’s OpenAIAgentsInstrumentor.

Traces show what ran. They do not show whether the user’s problem was solved. An agent handing a request to a specialist is not the same as resolving it, a guardrail stopping an action is not necessarily a system failure, and a completed run can still contain a wrong answer. OpenAI Agents SDK monitoring should connect the public request, run execution, handoffs, tool results, and observed outcome.

Agnost AI supports both levels in its Agents SDK integration: OpenTelemetry export of the SDK’s spans, and a conversation wrapper for the request boundary. This guide was checked against openai-agents 0.24 and openinference-instrumentation-openai-agents 2.8 in November 2026.

For production monitoring, use Agnost AI next to OpenAI’s Traces dashboard. The Traces dashboard is enough when you need to inspect one run at a time: its agents, handoffs, guardrails, and tool calls, during development or while debugging a reported bug (it is unavailable under a Zero Data Retention policy). It does not group runs into user conversations or tell you which conversations failed. Agnost AI adds that layer:

Judging runs in batches once a conversation has been idle for 15 minutes, so keep your existing error and latency alerts for real-time paging.

Agnost shows the traces too. Agnost ingests the OpenTelemetry traces itself: each conversation opens to its messages, spans and errors, and each tool call shows success or failure, latency, and its arguments and results when content capture is on. You do not need a separate tracing tool to use Agnost. OpenAI’s Traces dashboard stays useful for inspecting single runs during local development and debugging. Teams that want offline datasets, experiments or CI gates add LangSmith, Braintrust or Langfuse for that.

Recommended setup. Install the OpenInference instrumentor and the OTLP exporter, then point the exporter at Agnost:

pip install openai-agents openinference-instrumentation-openai-agents opentelemetry-sdk opentelemetry-exporter-otlp-proto-http export OTEL_EXPORTER_OTLP_ENDPOINT = https://otel.agnost.ai export OTEL_EXPORTER_OTLP_HEADERS = "X-Agnost-Org-ID=<your-org-id>" Enter fullscreen mode Exit fullscreen mode Register a TracerProvider with an OTLP BatchSpanProcessor, call OpenAIAgentsInstrumentor().instrument(), and wrap each run in using_attributes(session_id=..., user_id=...). The full code is below. Then write your first rules and alerts in Agnost. The rest of this guide covers what to monitor once traces arrive.

The SDK’s tracing docs list more than thirty processors in all, including AgentOps, Galileo, HoneyHive, Laminar, and Maxim AI. Register one with add_trace_processor() to keep OpenAI’s dashboard, or set_trace_processors() to replace it.

Runner.run, Runner.run_sync, and Runner.run_streamed are each wrapped in a trace. Inside it, the SDK creates spans for agents, LLM generations, function tools, guardrails, and handoffs, and custom_span() adds your own. A few settings decide what you can see later:

OpenAI’s hosted tracing is unavailable to organizations that use its APIs under a Zero Data Retention policy.

The SDK’s traces are not OpenTelemetry natively. OpenInference’s instrumentor converts them, following Agnost’s OpenAI Agents guide:

pip install openai-agents openinference-instrumentation-openai-agents \ opentelemetry-sdk opentelemetry-exporter-otlp-proto-http Enter fullscreen mode Exit fullscreen mode import os from agents import Runner, set_trace_processors from openinference. instrumentation import using_attributes from openinference. instrumentation. openai_agents import OpenAIAgentsInstrumentor 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" ] = f "X-Agnost-Org-ID={os.environ['AGNOST_ORG_ID']}" # Optional: replace the default processor so traces go only to Agnost. # Omit this line to keep sending traces to OpenAI's dashboard as well. set_trace_processors ( [ ] ) provider = TracerProvider ( ) provider. add_span_processor ( BatchSpanProcessor ( OTLPSpanExporter ( ) ) ) trace. set_tracer_provider ( provider ) OpenAIAgentsInstrumentor ( ). instrument ( tracer_provider = provider ) async def run_for_user ( agent, prompt, *, user_id, conversation_id ): with using_attributes ( session_id = conversation_id, user_id = user_id ): return await Runner. run ( agent, prompt ) Enter fullscreen mode Exit fullscreen mode You get agent, handoff, and guardrail spans plus the underlying LLM calls with message and tool data ( llm.input_messages.*, llm.output_messages.*, tool.name, tool.parameters, llm.token_count.* ). Do not call set_tracing_disabled(True) to stop OpenAI export: it removes the trace objects the instrumentor reads, and Agnost receives nothing. Run one request, then confirm the agent, handoff, guardrail, and LLM spans in Events.

Monitoring model for OpenAI Agents SDK. A handoff is a routing decision; resolution requires outcome evidence.

In an illustrative support application, a user gives an invoice reference and asks why they were charged twice. A triage agent routes the request to billing, but the specialist asks for the invoice again.

If context was dropped at the handoff, changing the specialist’s model may not address the problem. If context arrived but the tool lacked access, the failure is at a different boundary. Preserve a safe resource reference instead of exporting full billing details.

The user’s repeated question is useful evidence of friction. It is not proof that every handoff is harmful. Compare requests that genuinely need a specialist with similar requests, rather than trying to minimize routing indiscriminately.

In Agnost, inspect the conversation first; use the deeper instrumentation you configured to inspect the handoff and tool. The direct wrapper in this guide captures the public run, not those internal steps by itself.

Product demo · illustrative data. Conversation review exposes whether the agent retained details the user already supplied. For an Agents SDK application, inspect the handoff evidence separately to locate where context was lost. Select the image to inspect it at full size.

Use these definitions to design your measurement plan. Calculate them from the required application or tracing evidence; they are not all precomputed dashboard metrics.

One user conversation can contain several runs. One run can involve model calls, tools, and a handoff. Counting those internal operations as new user requests makes volume and completion metrics misleading.

Keep a stable conversation ID supplied by your application. Record a distinct attempt ID for each invocation. If an external tool changes something, preserve the action’s own identifier as well. A retry should not become a new customer, and a repeated action should not disappear inside an aggregate success count.

The Agents SDK’s official observability documentation describes built-in tracing for model calls, tools, handoffs, guardrails, and custom spans in the normal server-side path. That execution detail and your product’s outcome data answer different questions.

Install agnost alongside the existing openai-agents package. This adapter accepts an agent your application already configures; it does not change the model, tools, or instructions.

Example scope: the code below is an integration adapter for an existing application. Configure its framework, model, credentials, and output contract as described; the demo screenshots were not generated by running these snippets.

import os from uuid import uuid4 import agnost from agents import Runner agnost. init ( os. environ [ "AGNOST_ORG_ID" ] ) async def observed_run ( agent, prompt, *, user_id, conversation_id, output_to_text ): interaction = agnost. begin ( user_id = user_id, conversation_id = conversation_id, agent_name = "openai-support", input = prompt, properties = { "framework": "openai-agents", "agent_version": "support-v1", "attempt_id": str ( uuid4 ( ) ), }, ) if interaction is None: raise RuntimeError ( "Call agnost.init() before observed_run()" ) try: result = await Runner. run ( agent, prompt ) safe_output = output_to_text ( result. final_output ) except Exception as exc: interaction. end ( output = type ( exc ). __name__, success = False ) raise else: interaction. end ( output = safe_output, success = True ) return result Enter fullscreen mode Exit fullscreen mode Set AGNOST_ORG_ID on the server. Supply sanitized prompt text and a serializer that selects approved public output. If your agent returns a structured object, do not indiscriminately serialize all fields.

The official quickstart documents Runner.run and final_output.

Initialize the Agnost SDK once and flush it at process exit with agnost.shutdown(). Keep the existing provider credentials and agent configuration in their normal server-side location. No credentials belong in the article or recorded prompts.

The wrapper’s success flag means the run returned normally. It does not mean an external action completed or a user accepted the answer. The conversation identifier also does not configure model memory; retain your application’s own session/history handling.

A handoff can be exactly the right behavior. For example, a general assistant may route a billing question to a billing specialist. Monitor whether the request reached the appropriate specialist and whether the specialist received enough context.

Record stable agent identities and routing evidence where available. A higher handoff rate is not inherently worse; it may reflect more requests needing specialist handling. Compare the same task categories before drawing conclusions.

A guardrail blocking an unsafe or unsupported action may be correct product behavior. A guardrail incorrectly blocking a legitimate request is a quality issue. A failed guardrail service is an operational issue. Combining all three as “agent failures” obscures the action you need to take.

Keep a reason category and a reviewable, appropriately sanitized record. The generic exception branch in the sample preserves execution failure but does not classify every guardrail outcome. Add application-specific classification using the exception and result types of your installed SDK. Do not infer whether a block was correct just from its presence.

A function tool returning text is not sufficient evidence that a payment, booking, or update succeeded. Capture the authoritative operation result in the tool implementation. Keep pending and unknown outcomes explicit.

If the answer says “done” while the service returned a rejection, investigate how the tool result reached the agent. If the same action runs twice, inspect retries and idempotency identifiers. If a tool is slow, distinguish time spent waiting on it from time spent in model generation.

For the execution evidence behind a tool or handoff, use the OpenTelemetry export above. Confirm that the instrumentor is active before the first run, and inspect an actual run to establish coverage.

A streaming result object is not a completed answer. End the interaction after consuming the stream or receiving the appropriate terminal signal. Record failures and cancellations, and guard against calling the terminal handler twice.

A server’s generation completion is different from browser delivery. If the user disconnects, the backend may continue running. Link client and server observations through an application request ID when you need to measure what was actually displayed.

Use Users to follow related interactions and Events to inspect received records. Organize recurring requests by configured intent, then review the evidence behind corrections, repeated handoffs, or failed actions.

Start with one actionable question, such as whether billing requests reach the right specialist. Add the evidence required to answer it rather than collecting every available payload. Request duration, tool status, routing, and observed outcome are often more useful together than a large count of disconnected spans.

For typed-output validation concerns, continue with Pydantic AI monitoring. For the integration itself, use Agnost’s OpenAI Agents guide.

Browse all agent observability guides by framework.

Keep the SDK's built-in tracing on and export the same spans over OpenTelemetry to a tool that monitors whole conversations. With Agnost AI, install openinference-instrumentation-openai-agents and the OpenTelemetry OTLP exporter, point the exporter at https://otel.agnost.ai with your X-Agnost-Org-ID header, and pass session_id and user_id on each run. Agnost groups runs by user and session, judges each conversation against plain-language rules, detects failures, frustration, tool-call errors, and loops, alerts in Slack or email, and can open a pull request with a fix tested against past runs. OpenAI's own Traces dashboard is enough for inspecting individual runs, handoffs, and guardrails.

The SDK traces to OpenAI's own Traces dashboard by default. Its tracing docs list processors for many third-party platforms, including Langfuse, LangSmith, Braintrust, Arize Phoenix, Weights & Biases, Pydantic Logfire, AgentOps, MLflow, Datadog, and PostHog. Any OpenTelemetry backend, including Agnost, can receive the same agent, handoff, guardrail, tool, and LLM spans through OpenInference's OpenAIAgentsInstrumentor.

Not natively; its traces use the SDK's own processor interface. OpenInference's openinference-instrumentation-openai-agents package converts them to OpenTelemetry spans, which you can export over OTLP to any backend. Keep SDK tracing enabled, because the instrumentor observes the SDK's trace objects.

Set OPENAI_AGENTS_DISABLE_TRACING=1, call set_tracing_disabled(True), or set tracing_disabled=True in RunConfig for one run. If you only want to stop sending traces to OpenAI while exporting elsewhere, call set_trace_processors() with your own processors instead; disabling tracing also stops third-party processors and instrumentors that depend on it.

No. add_trace_processor() keeps OpenAI's export and adds another destination, and a conversation wrapper can coexist with either. Decide deliberately where deeper traces are exported and which record represents one request in your metrics.

It means the run produced a final output. Resolution needs a task-appropriate signal, such as an authoritative action result or explicit review.

Originaltitel: How to Monitor an OpenAI Agents SDK Agent in ProductionQuelle: dev.to (dev.to). Original öffnen