fix: insert retrieved LTM before last user message to avoid prefill error#271
Merged
fix: insert retrieved LTM before last user message to avoid prefill error#271
Conversation
493da1e to
4dd7162
Compare
|
If I'm reading this correctly:
Is there a potential issue with the role not being consistent here? |
…rror on Claude 4.6+
4dd7162 to
1c82c35
Compare
Contributor
Author
You're right, there could be. I've jsut updated it to always inline as a content block in the last user message so the role is consistent. |
Contributor
Author
|
Related issue: strands-agents/sdk-python#1736 |
3 tasks
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
Fixes assistant-prefill error on Claude 4.6+ models (Opus 4.6, Sonnet 4.6) when using
AgentCoreMemorySessionManagerwith LTM retrievalPreviously, retrieved memory was appended as an
assistantmessage after the last user message, making it the final message sent to the model. Claude 4.6 rejects this with:"This model does not support assistant message prefill. The conversation must end with a user message."Now inserts the
assistantmemory message before the last user message, keeping the user's query lastFor the first message in a conversation (where prepending an assistant message would violate Bedrock's "must start with user" rule), injects memory as a content block within the user message instead
Renames
<user_context>tag to<retrieved_memory>for semantic accuracyCloses #191
Related issue strands-agents/sdk-python#1694
Testing
ValidationException: does not support assistant message prefill)AgentCoreMemorySessionManager+ Opus 4.6 — no prefill error<user_context>→<retrieved_memory>)