Skip to content

fix: persist tool_result messages to storage during tool processing#445

Open
guoyangzhen wants to merge 8 commits intoawslabs:mainfrom
guoyangzhen:fix/missing-tool-results-storage
Open

fix: persist tool_result messages to storage during tool processing#445
guoyangzhen wants to merge 8 commits intoawslabs:mainfrom
guoyangzhen:fix/missing-tool-results-storage

Conversation

@guoyangzhen
Copy link
Copy Markdown

Problem

Only USER input and final ASSISTANT response were saved to chat storage. Tool_result messages created during tool processing were kept in-memory only, so subsequent requests loaded incomplete conversation history.

This caused Bedrock/Anthropic API errors:

tool_use ids found without tool_result blocks immediately after

Root Cause

The orchestrator's save_message only saves the user input and final agent response. The tool_response (USER role with tool results) created by _process_tool_block is added to the in-memory conversation for the next LLM call but never persisted to storage.

Fix

  1. Collect tool_response messages in Agent._pending_tool_responses during tool processing loops
  2. After the final response is saved, the orchestrator persists these tool_result messages to storage
  3. Applied to both Python and TypeScript, both streaming and non-streaming paths

Files changed: 8 files (+66 lines)

  • Agent base class (both languages): add pending tool responses array
  • BedrockLLMAgent + AnthropicAgent (both languages): collect in processing loops
  • Orchestrator (both languages): save pending tool responses after final message

Fixes #396

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug?: Missing Tool Results

1 participant