Skip to content

Conversation

@crishoj
Copy link
Contributor

@crishoj crishoj commented Oct 24, 2025

summarizationMiddleware can lead to a message history where the first message is an AI message with tool calls.

Gemini isn't happy about this:

[GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-09-2025:generateContent: [400 Bad Request] Please ensure that function call turn comes immediately after a user turn or after a function response turn.

I propose to address this by adjusting isSafeCutoffPoint to avoid cutting off message history at an AI message with tool calls, effectively including the preceding message.

Fixes #9272

(Twitter handle @crishoj)

@changeset-bot
Copy link

changeset-bot bot commented Oct 24, 2025

🦋 Changeset detected

Latest commit: 4fd09b0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
langchain Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@crishoj crishoj force-pushed the fix/invalid-message-order-after-summarize branch from eae0ace to c1aa417 Compare October 28, 2025 11:08
@christian-bromann christian-bromann self-requested a review November 7, 2025 20:08
Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

@christian-bromann christian-bromann merged commit b401680 into langchain-ai:main Nov 7, 2025
33 checks passed
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.

summarizationMiddleware leads message order unsupported by Gemini

2 participants