Description
get_response_output_message_attributes() uses the index within message.content when extracting ResponseOutputText, instead of the message's index within response.output.
This mis-associates message text whenever another output item (commonly a reasoning item) precedes the message. The message metadata is emitted under gen_ai.completion.1.*, while its content is emitted under gen_ai.completion.0.content and can overwrite attributes belonging to the reasoning item.
Reproduced on current main at f8e907b92dabe47232978023fdcb01e2a7d4b752.
Minimal reproduction
from openai.types.responses import (
ResponseOutputMessage,
ResponseOutputText,
ResponseReasoningItem,
)
from agentops.instrumentation.providers.openai.attributes.response import (
get_response_output_attributes,
)
reasoning = ResponseReasoningItem(
id="reasoning_1", summary=[], type="reasoning", status="completed"
)
message = ResponseOutputMessage(
id="msg_1",
content=[ResponseOutputText(annotations=[], text="answer", type="output_text")],
role="assistant",
status="completed",
type="message",
)
print(get_response_output_attributes([reasoning, message]))
Relevant current output:
gen_ai.completion.0.id = reasoning_1
gen_ai.completion.0.content = answer
gen_ai.completion.1.id = msg_1
# gen_ai.completion.1.content is missing
Expected behavior
The text content should use the parent output message's completion index:
gen_ai.completion.0.id = reasoning_1
gen_ai.completion.1.id = msg_1
gen_ai.completion.1.content = answer
Suggested fix
Pass the outer response.output index through to get_response_output_text_attributes() instead of replacing it with the inner content-list index. Add a regression using actual OpenAI response types with a reasoning item before the message.
I can submit a focused fix with regression coverage.
Description
get_response_output_message_attributes()uses the index withinmessage.contentwhen extractingResponseOutputText, instead of the message's index withinresponse.output.This mis-associates message text whenever another output item (commonly a reasoning item) precedes the message. The message metadata is emitted under
gen_ai.completion.1.*, while its content is emitted undergen_ai.completion.0.contentand can overwrite attributes belonging to the reasoning item.Reproduced on current
mainatf8e907b92dabe47232978023fdcb01e2a7d4b752.Minimal reproduction
Relevant current output:
Expected behavior
The text content should use the parent output message's completion index:
Suggested fix
Pass the outer
response.outputindex through toget_response_output_text_attributes()instead of replacing it with the inner content-list index. Add a regression using actual OpenAI response types with a reasoning item before the message.I can submit a focused fix with regression coverage.