Skip to content

fix(openai-agents): capture system instructions from Response object (#4188)#3

Closed
nagkumar91 wants to merge 1 commit into
mainfrom
fix/4188-system-instructions
Closed

fix(openai-agents): capture system instructions from Response object (#4188)#3
nagkumar91 wants to merge 1 commit into
mainfrom
fix/4188-system-instructions

Conversation

@nagkumar91

Copy link
Copy Markdown
Owner

Summary

Fixes open-telemetry#4188 - System prompt/instructions do not show in trace when using the Responses API.

Problem

When using the Responses API (default in OpenAI Agents SDK), agent instructions are passed as the instructions parameter to responses.create(), not as role: "system" messages in the input. The Response object has an .instructions attribute, but _collect_system_instructions() only looks for system/AI role messages in input, so instructions were never captured in the trace.

Fix

Added a fallback in _build_content_payload() for the ResponseSpanData branch: after the existing system instruction collection from input messages, if no instructions were found, read response.instructions and emit it as gen_ai.system_instructions.

Changes

  • span_processor.py: 7-line fallback in the ResponseSpanData branch of _build_content_payload()
  • test stubs: Added input field to ResponseSpanData stub and MCPListToolsSpanData stub (needed for test imports)
  • test_z_span_processor_unit.py: New test_response_span_instructions_fallback test verifying instructions from response.instructions appear in span attributes

…pen-telemetry#4188)

When using the Responses API, instructions are passed separately and
stored on response.instructions rather than as role="system" input
messages. This adds a fallback to read response.instructions for
gen_ai.system_instructions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nagkumar91 nagkumar91 force-pushed the fix/4188-system-instructions branch from efd0b89 to 13a0834 Compare March 3, 2026 17:52
@nagkumar91 nagkumar91 closed this Mar 3, 2026
@nagkumar91 nagkumar91 deleted the fix/4188-system-instructions branch March 3, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OpenAI Agents] System prompt/instructions do not show in trace

1 participant