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

Abierto
#723 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
ai, backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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).

Lenguaje dominante
Python
Estrellas
786
Forks
163
Merge medio
4 h
PR fusionados (30 d)
22

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de aws/bedrock-agentcore-sdk-python

Todos los issues de aws/bedrock-agentcore-sdk-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.