-
Notifications
You must be signed in to change notification settings - Fork 421
Fix OpenAI Agents SDK guardrail span classification #1096
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
base: main
Are you sure you want to change the base?
Fix OpenAI Agents SDK guardrail span classification #1096
Conversation
- Add GuardrailSpanData handling to get_span_kind() function - Add get_guardrail_span_attributes() function with proper GUARDRAIL span kind - Add GUARDRAIL_SPAN_ATTRIBUTES mapping for consistent attribute extraction - Add GuardrailSpanData case to get_span_attributes() dispatcher Fixes issue where GuardrailSpanData spans were falling through to generic classification instead of being properly mapped to GUARDRAIL span type. Co-Authored-By: Alex <[email protected]>
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
Co-Authored-By: Alex <[email protected]>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Vibe coded but looks good? Can you test @fenilfaldu ? |
- Add test_guardrail_span_attributes() to test main functionality - Add test_guardrail_span_attributes_without_optional_fields() for edge cases - Add GuardrailSpanData test case to test_span_attributes_dispatcher() - Import get_guardrail_span_attributes in test imports Addresses codecov/patch failure by adding comprehensive test coverage for the new guardrail span handling code. Co-Authored-By: Alex <[email protected]>
Apply automatic formatting changes from ruff-format to resolve pre-commit check failure. Adds blank line after docstring. Co-Authored-By: Alex <[email protected]>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Fix OpenAI Agents SDK guardrail span classification
Problem
The OpenAI Agents SDK integration was incorrectly classifying guardrail events as generic events or agent spans instead of properly mapping them to
GUARDRAIL
span types. This prevented proper observability and tracing of guardrail events in the AgentOps platform.Root Cause
Two functions in the OpenAI Agents SDK instrumentation were missing handlers for
GuardrailSpanData
:get_span_kind()
inexporter.py
- didn't handleGuardrailSpanData
, causing it to fall through to defaultSpanKind.INTERNAL
get_span_attributes()
inattributes/common.py
- didn't have a case forGuardrailSpanData
, so these spans didn't get proper AgentOps span kind attributesSolution
Added proper
GuardrailSpanData
handling following the established patterns in the codebase:Changes Made
Updated
get_span_kind()
function inexporter.py
:GuardrailSpanData
to theHandoffSpanData
case forSpanKind.INTERNAL
Added
GUARDRAIL_SPAN_ATTRIBUTES
mapping inattributes/common.py
:Added
get_guardrail_span_attributes()
function inattributes/common.py
:GuardrailSpanData
objectsAGENTOPS_SPAN_KIND
toGUARDRAIL
valuename
andtriggered
Updated
get_span_attributes()
dispatcher inattributes/common.py
:GuardrailSpanData
case to route to the new handler functionTesting
✅ Verified with OpenAI Agents SDK guardrail example:
examples/openai_agents/agent_guardrails.py
✅ Lint checks: Pre-commit hooks passed with automatic formatting applied
Impact
GUARDRAIL
spansLink to Devin run
https://app.devin.ai/sessions/0764439e61a6472fa04739fd1db8fb08
Requested by: Alex ([email protected])