fix(memory): add Claude-compatible mode to ZepMemory #7808
+159
−28
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.
Fix System Messages with Anthropic's Claude in Zep Memory
Problem
When using Zep Memory with Anthropic's Claude models, the integration fails because Claude only permits system messages as the first message. This causes errors when the memory retrieval mechanism in
ZepMemory
returns aSystemMessage
containing summary content followed by other message types.Solution
This PR adds utility functions and a configuration option to handle Claude's limitation with system messages, similar to the solution already implemented in
ZepCloudMemory
:Added a new
separateMessages
option that controls how memory is returned:true
(default): Returns separate messages with proper types (SystemMessage, HumanMessage, AIMessage) - maintains backward compatibilityfalse
: Condenses all memory content into a single HumanMessage for Claude compatibilityAdded utility functions:
zepMemoryContextToSystemPrompt
: Extracts summary and facts as a system promptcondenseZepMemoryIntoHumanMessage
: Combines all memory into a formatted HumanMessagezepMemoryToMessages
: Preserves memory structure with proper message typesImplementation Details
separateMessages
istrue
to maintain backward compatibility with existing codeactualRole = roleType || role
ZepCloudMemory
but specifically for the open-source Zep integrationTesting Recommendations
separateMessages: true
andseparateMessages: false
to ensure both modes work as expectedRelated Issues
Fixes #7807 - System messages don't work with Anthropic's Claude