feat: preserve ToolMessage instances through conversation compaction - #414
Merged
Conversation
- Add ToolMessage case in callReactAgent message rebuild (lines 195-196) - Add ToolMessage case in callReactAgentStreaming message rebuild (lines 501-502) - Write tests verifying ToolMessage preservation in both paths - All 1178 tests pass, lint clean
Owner
Author
Implementation CompleteAll tasks have been implemented and verified:
The fix ensures ToolMessage instances are preserved during conversation compaction in both streaming and non-streaming modes. Previously, tool messages were incorrectly converted to AIMessage during compaction, causing tool results to be lost. Changes:
Archived: openspec/changes/archive/2026-06-22-fix-toolmessage-loss-compaction/ |
Owner
Author
Audit ResultsGoal Fulfillment
Spec Compliance
Task Completion
Quality Check
VerdictAll checks passed. Implementation is correct and complete. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes ToolMessage instances being incorrectly converted to AIMessage during conversation compaction in the ReAct agent.
Type of Change
What Was Implemented
ToolMessagecase in message rebuild logic for bothcallReactAgent(line 196) andcallReactAgentStreaming(line 502), ensuring tool messages survive compactionRoot Cause
When
compactConversationtriggered a context length error, the message rebuild logic only handledsystem,user, and fallback toAIMessage. Messages with role"tool"were incorrectly reconstructed asAIMessageinstances, causing tool results to be lost.Testing
Coverage
npm run lintpassesRelated
Addresses ToolMessage instances being incorrectly converted to AIMessage during conversation compaction.