fix(llm): reposition mid-conversation instructions for Gemini gateway and Mistral - #6591
Open
L65FREAD wants to merge 1 commit into
Open
fix(llm): reposition mid-conversation instructions for Gemini gateway and Mistral#6591L65FREAD wants to merge 1 commit into
L65FREAD wants to merge 1 commit into
Conversation
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.
Summary
generate_reply(instructions=...)appends the per-turn instructions as a trailing system message. Two serialization paths mishandled it:instructionsrequest field, so the trailing per-turn message silently overwrote the agent's base prompt.Both now route through the SDK's existing
convert_mid_conversation_instructions(already used by the google/anthropic/aws serializers), which keeps the first system message as the base preamble and rewrites later ones as position-preserving<instructions>-wrapped user turns.Where the conversion happens:
LLMStream._runat serialization time — sostream.chat_ctxand thellm_requesttelemetry span keep the original roles, matching the plugins — gated by a model-prefix allowlist (currentlygoogle/). OpenAI-compatible gateway providers keep the system role untouched.AIPlatformLLM(Vertex AI Model Garden), which reuses the shared stream with the openai wire format, opts in unconditionally since self-deployed model templates commonly reject non-leading system roles.Helper hardening while touching it:
Testing