AgentOps-AI / AgentOps-AI/agentops

OpenAI Responses message content uses the wrong completion index

オープン
#1,436 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
5.8k
フォーク
619
PR マージ指標
30日以内にマージされた PR はありません

説明

## 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

```python
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:

```text
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:

```text
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.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。