-
Notifications
You must be signed in to change notification settings - Fork 288
Description
Description
After PR #417 (refactor: Remove message processor), we're experiencing validation errors when tool results are not completed by Bedrock and the agent receives a message end event, followed by a customer asking another question.
Root Cause
The removal of clean_orphaned_empty_tool_uses(agent.messages)
from the event loop cycle has eliminated the cleanup mechanism for orphaned empty tool uses. This function was responsible for handling cases where Bedrock doesn't complete tool results.
Error Details
❌ Error: An error occurred (ValidationException) when calling the ConverseStream operation: The model returned the following
errors: messages.8: `tool_use` ids were found without `tool_result` blocks immediately after: tooluse_p5c8yrxwSXOO-FOx6CBC_A.
Each `tool_use` block must have a corresponding `tool_result` block in the next message.
Steps to Reproduce
- Start an agent conversation
- Have Bedrock not complete tool results (this happens often)
- Agent receives message end event from Bedrock
- Customer asks another question
- ValidationException occurs due to orphaned tool_use blocks
Expected Behavior
Orphaned empty tool uses should be cleaned up automatically to prevent validation errors, allowing the conversation to continue smoothly.
Actual Behavior
ValidationException is thrown, breaking the conversation flow.
Proposed Solution
Reintroduce the clean_orphaned_empty_tool_uses
function or implement an equivalent mechanism to handle orphaned tool_use blocks that don't have corresponding tool_result blocks.
Related PR
- refactor: Remove message processor #417 - refactor: Remove message processor (where the cleanup function was removed)
Impact
- Severity: High - Breaks conversation flow
- Frequency: Often (happens when Bedrock doesn't complete tool results)
- User Experience: Poor - Users encounter validation errors mid-conversation
Additional Context
This is a regression introduced by the message processor removal. The cleanup mechanism was essential for handling Bedrock's inconsistent tool result completion behavior.