Skip to main content

OpenAI Agents SDK

Two pieces in adapters/openai_agents/vigil_tracing.py, both built on vigil-sdk:

  • VigilTracingProcessor: a TracingProcessor that emits on on_span_end. Agent spans become output_generated (content_length of the output when the span has one). Function (tool) spans become file_operation when the tool name says it moves data (write, copy, move, delete, transfer, rm, mv, cp) and output_generated otherwise. Every event is source: platform_hook, actor: agent:<agent_id>. Emission failures go to on_error and never interrupt the run; every gate goes to on_gate and processor.last_gate.
  • vigil_gate_guardrail(client, agent_id): an output guardrail that emits output_generated for the final output and trips the tripwire on hold, alert or collapse, so the Agents SDK raises OutputGuardrailTripwireTriggered instead of returning the output. Works with Vigil or AsyncVigil.

openai-agents is imported lazily: the module imports and the tests run without it.

Wire it

import os
from agents import Agent, Runner, add_trace_processor
from vigil import Vigil
from adapters.openai_agents.vigil_tracing import VigilTracingProcessor, vigil_gate_guardrail

vg = Vigil(api_key=os.environ["VIGIL_API_KEY"])
vg.register_agent("triage", "Triage", exist_ok=True)

add_trace_processor(VigilTracingProcessor(vg, agent_id="triage"))
agent = Agent(
name="Triage",
instructions="Route the request.",
output_guardrails=[vigil_gate_guardrail(vg, agent_id="triage")],
)
result = await Runner.run(agent, "Hello")

Try it

adapters/openai_agents/example.py drives the processor with synthetic spans (an agent span, a copy_file tool span, a get_weather tool span) and calls the guardrail directly against VIGIL_API_URL, so it runs with only a VIGIL key. With openai-agents and OPENAI_API_KEY present it also runs a real agent.

VIGIL_API_KEY=vg_... python -m adapters.openai_agents.example

The two events the processor sends for the copy_file and get_weather spans, as raw HTTP:

curl -sf -X POST "$VIGIL_URL/agents/" -H "Authorization: Bearer $VIGIL_KEY" -H "Content-Type: application/json" \
-d '{"agent_id":"docs-openai-agents","name":"Docs OpenAI Agents"}' > /dev/null || true
curl -sf -X POST "$VIGIL_URL/events/" -H "Authorization: Bearer $VIGIL_KEY" -H "Content-Type: application/json" \
-d '{"agent_id":"docs-openai-agents","event_type":"file_operation","source":"platform_hook","actor":"agent:docs-openai-agents",
"payload":{"operation":"copy","tool_name":"copy_file","asset_type":"data"}}'
curl -sf -X POST "$VIGIL_URL/events/" -H "Authorization: Bearer $VIGIL_KEY" -H "Content-Type: application/json" \
-d '{"agent_id":"docs-openai-agents","event_type":"output_generated","source":"platform_hook","actor":"agent:docs-openai-agents",
"payload":{"tool_name":"get_weather","content_length":13}}'