OpenAIConverseConverter drops all but the first toolResult of a parallel tool call, and json results

未關閉
#723 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
76/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
ai, backend

研究方向

Read memory/integrations/strands/converters/openai.py, especially _bedrock_to_openai and message_to_payload, then compare its behavior with AgentCoreMemoryConverter. Reproduce the round trip using parallel toolResult blocks and a JSON result. Done means every result and its content survive restoration, consecutive tool messages are merged for Converse history, and the described reproduction passes.

由索引模型根據 Issue 內容生成。

描述

bug

Describe the bug
With converter=OpenAIConverseConverter, a Strands agent that makes parallel tool calls stores only the first tool result. Strands puts every result of a parallel tool-use turn into one user message (strands/event_loop/event_loop.py:960), but _bedrock_to_openai (memory/integrations/strands/converters/openai.py, the if content and "toolResult" in content[0] branch) converts only content[0]. After restore, the assistant turn has N toolUse blocks and the next user turn has one toolResult, so the next Converse call fails the toolUse/toolResult pairing check (the same ValidationException class as #245).

It also keeps only text parts, so a tool result with a json block is restored as [{"text": ""}].

To Reproduce

from strands.types.session import SessionMessage
from bedrock_agentcore.memory.integrations.strands.converters.openai import OpenAIConverseConverter as C

def roundtrip(msg):
    payload = C.message_to_payload(SessionMessage(message=msg, message_id=0))
    events = [{"payload": [{"conversational": {"content": {"text": t}, "role": r.upper()}}]} for t, r in payload]
    return [m.message for m in C.events_to_messages(events)]

results = {"role": "user", "content": [
    {"toolResult": {"toolUseId": "t1", "status": "success", "content": [{"text": "sunny"}]}},
    {"toolResult": {"toolUseId": "t2", "status": "success", "content": [{"json": {"temp_c": 21}}]}},
]}
print([b["toolResult"]["toolUseId"] for m in roundtrip(results) for b in m["content"] if "toolResult" in b])
# ['t1']   (AgentCoreMemoryConverter returns ['t1', 't2'])

A single result whose content is only {"json": {...}} comes back as [{"text": ""}].

Expected behavior
Every toolResult survives the round trip with its content, as with the default AgentCoreMemoryConverter.

Suggested fix
Emit one OpenAI role: "tool" message per toolResult (message_to_payload already returns a list), serialize json parts with json.dumps, and in events_to_messages merge consecutive restored tool messages back into one user message so the history keeps the alternation Converse requires.

Additional context
Reproduced on main. Not covered by #245 (default converter, different cause) or #718 (reasoning bytes only).

主要語言
Python
星號
786
分支
163
平均合併
4 小時
30 天內合併 PR
22

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

aws/bedrock-agentcore-sdk-python 的其他 Issue

查看 aws/bedrock-agentcore-sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。