Skip to content

Fix for parallel tool calls summarization #126#127

Open
Mostafa Amin (mostafa-amin-dt) wants to merge 1 commit intolangchain-ai:mainfrom
mostafa-amin-dt:main
Open

Fix for parallel tool calls summarization #126#127
Mostafa Amin (mostafa-amin-dt) wants to merge 1 commit intolangchain-ai:mainfrom
mostafa-amin-dt:main

Conversation

@mostafa-amin-dt

Fix to bug in issue #126

@efealioksuz

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

I've submitted #141 which takes a more comprehensive approach — instead of only checking the last message, it iterates all AIMessages in the summarization range and appends any missing tool results. This handles the case where the cutoff lands on a ToolMessage mid-sequence (not just when it lands on an AIMessage), and also covers multiple AIMessages with tool calls in the same range.

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.

3 participants