Skip to content

fix: ensure complete tool call sequences and prevent duplication in summarization#100

Open
Yashwanth (yash025) wants to merge 2 commits into
langchain-ai:mainfrom
yash025:main
Open

fix: ensure complete tool call sequences and prevent duplication in summarization#100
Yashwanth (yash025) wants to merge 2 commits into
langchain-ai:mainfrom
yash025:main

Conversation

@yash025

@yash025 Yashwanth (yash025) commented Jul 17, 2025

Copy link
Copy Markdown

fix for issue: #98

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
@kfirco-jit

Copy link
Copy Markdown

I've submitted #141 which addresses this more comprehensively — it checks all AIMessages in the summarization range for missing tool results (not just walking backwards from the last message), covering cases where the token cutoff falls on a ToolMessage mid-sequence.

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.

2 participants