fix: ensure complete tool call sequences and prevent duplication in summarization#100
Open
Yashwanth (yash025) wants to merge 2 commits into
Open
fix: ensure complete tool call sequences and prevent duplication in summarization#100Yashwanth (yash025) wants to merge 2 commits into
Yashwanth (yash025) wants to merge 2 commits into
Conversation
added 2 commits
July 17, 2025 09:14
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 addresses this more comprehensively — it checks 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 for issue: #98