Fix for parallel tool calls summarization #126#127
Open
Mostafa Amin (mostafa-amin-dt) wants to merge 1 commit intolangchain-ai:mainfrom
Open
Fix for parallel tool calls summarization #126#127Mostafa Amin (mostafa-amin-dt) wants to merge 1 commit intolangchain-ai:mainfrom
Mostafa Amin (mostafa-amin-dt) wants to merge 1 commit intolangchain-ai:mainfrom
Conversation
|
I have also validated that this fixes the problem we are experiencing, can we get this merged? William FH (@hinthornw) |
kfirco-jit
pushed a commit
to kfirco-jit/langmem
that referenced
this pull request
Feb 11, 2026
…ssages When the token cutoff in `_preprocess_messages` lands on a ToolMessage mid-sequence (rather than on the AIMessage itself), the existing handler at lines 204-207 never fires because it only checks whether the *last* message in `messages_to_summarize` is an AIMessage. This leaves subsequent tool results excluded from the summarization range, producing orphaned `tool_use` blocks that cause provider-level validation errors (Bedrock `ValidationException`, OpenAI `BadRequestError`). The fix replaces the single-message check with a loop over ALL AIMessages in the summarization range, appending any missing corresponding ToolMessages from the pre-built lookup dictionary. Fixes langchain-ai#126 Fixes langchain-ai#112 Supersedes langchain-ai#127 Supersedes langchain-ai#100
|
I've submitted #141 which takes a more comprehensive approach — instead of only checking the last message, it iterates all |
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.
Fix to bug in issue #126