Skip to content

Bedrock Agents replaces user message with duplicated tool_result after tool invocation

0

I’m experiencing a recurring issue with AWS Bedrock Agents where the user’s original message disappears from the conversation history and is replaced by the tool_result, which also gets duplicated.

✅ Expected behavior After a tool call, the user message should remain in the trace.

"messages": [
  {
    "role": "user",
    "content": "[{text='Hola buenas noches. Quisiera sacar cita con Adriana Gamarra.', type=text}]"
  },
  {
    "role": "assistant",
    "content": "[{text='<thinking>Verificar si la doctora existe</thinking>', type=text}, {input={gender='Femenino', full_names=['Adriana Gamarra']}, name='schedule__get_health_worker_ids', type='tool_use'}]"
  },
  {
    "role": "user",
    "content": "[{tool_use_id='toolu_bdrk_01Ah7KiyXfEwuDCnGZ3fwB9x', type='tool_result', content='[{\"id\":2,\"full_name\":\"Adriana Gamarra Luna\",\"specialty\":\"Dermatología\",\"consultation_fee\":\"S/ 250\"}]'}]"
  }
]

❌ Actual behavior After the tool_result, the original user message is replaced by the same tool_result, duplicated:

"messages": [
  {
    "role": "user",
    "content": "[{text='[{\"id\":164,\"full_name\":\"Adriana Gamarra Luna\",\"specialty\":\"Dermatologia\",\"consultation_fee\":\"S/ 250\"}]', type=text}]"
  },
  {
    "role": "assistant",
    "content": "[{text='<thinking>Voy a saludar y buscar el ID de la Dra. Adriana Gamarra...</thinking>', type=text}, {input={gender='Femenino', full_names=['Adriana Gamarra']}, name='schedule__get_health_worker_ids', type='tool_use'}]"
  },
  {
    "role": "user",
    "content": "[{tool_use_id='toolu_bdrk_01AGKbao3BvvXTjVhaVirjY7', type='tool_result', content='[{\"id\":164,\"full_name\":\"Adriana Gamarra Luna\",\"specialty\":\"Dermatologia\",\"consultation_fee\":\"S/ 250\"}]'}]"
  }
]

You can see that the first user message (the greeting and intent) was replaced by the tool_result JSON. As a result, the agent loses context and responds incoherently (it thinks the user sent structured data instead of text).

Environment

  • Models tested: Claude Sonnet 3.5 , 3.7 y 4.5
  • Regions: us-east-1 (Virginia)
  • Happens both in: Bedrock agent Console test chat and SDK (PHP)
  • Agent config: User input enabled, Action groups,1 Knowledge Bases, Orchestration strategy (only "Orchestration" default)
  • Started happening: October 23, 2025

Is anyone else experiencing this issue? It seems related to session state corruption, but there’s no report on AWS Health about it.

asked a year ago240 views

1 Answer
0

This issue you're experiencing with AWS Bedrock Agents appears to be a bug in how the conversation history is managed after tool calls, particularly with the Llama 3.1 models.

Based on similar reported issues, there seems to be a problem with how the agent handles the conversation state after tool invocations. The original user message is being incorrectly replaced with the tool_result content, which disrupts the conversation flow and causes the agent to lose context.

Here are some potential approaches to address this issue:

  1. Session Attributes Management: Try implementing better session attributes management to maintain the conversation state. The session attributes from Lambda functions called within action groups might not be properly visible to Lex/Bedrock.

  2. Version Control: Ensure you're testing with the correct version of your agent. When testing from the AWS Console UI, you're using the DRAFT version by default, while SDK calls use the version specified in the agent alias. This could explain different behaviors between testing environments.

  3. Force Agent Preparation: After creating a new agent version, force an agent "prepare" and then update the alias to target the new version. This has helped some users with similar issues.

  4. Context Management: Implement better context management to maintain the conversation state between turns.

  5. Report the Bug: Since this appears to be a bug with the Bedrock service, consider opening a support ticket with AWS Support with your detailed description of the issue. Service teams don't typically monitor re:Post for bug reports.

The issue seems particularly problematic with certain Claude models, as you've noted with Claude Sonnet 3.5, 3.7, and 4.5. This is likely a bug in how the Bedrock service manages conversation history and tool calls rather than an issue with your implementation.
Sources
Llama 3.1 Converse calls not properly escaping quotes in tool calls | AWS re:Post
Lex BedrockAgentIntent controlling Fulfilled | AWS re:Post
BedRock Agent ignoring lambda provided to answer questions | AWS re:Post

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.