fix(community): add Claude-compatible mode to ZepMemory
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 a SystemMessage 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
separateMessagesoption that controls how memory is returned:- When
true(default): Returns separate messages with proper types (SystemMessage, HumanMessage, AIMessage) - maintains backward compatibility - When
false: Condenses all memory content into a single HumanMessage for Claude compatibility
- When
-
Added utility functions:
zepMemoryContextToSystemPrompt: Extracts summary and facts as a system promptcondenseZepMemoryIntoHumanMessage: Combines all memory into a formatted HumanMessagezepMemoryToMessages: Preserves memory structure with proper message types
Implementation Details
- The default for
separateMessagesistrueto maintain backward compatibility with existing code - Added type safety improvements to avoid "implicitly any" type errors
- Improved handling of role/roleType values with
actualRole = roleType || role - Added comprehensive JSDoc documentation for the new functions and options
- The implementation is almost identical to the one in
ZepCloudMemorybut specifically for the open-source Zep integration
Testing Recommendations
- Test with both
separateMessages: trueandseparateMessages: falseto ensure both modes work as expected - Specifically test with Claude models to verify the fix resolves the system message limitation
- Verify backwards compatibility by testing with existing code that expects the original behavior
Related Issues
Fixes #7807 - System messages don't work with Anthropic's Claude
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| langchainjs-docs | ✅ Ready (Inspect) | Visit Preview | Mar 13, 2025 4:40pm |
1 Skipped Deployment
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| langchainjs-api-refs | ⬜️ Ignored (Inspect) | Mar 13, 2025 4:40pm |
Looks fine to me, but CC @danielchalef for a final review!
Bump @danielchalef!
@jacoblee93 Hi, I'm an engineer at Zep, @danielchalef asked me to take a look at this one, looks good to me, @raffareis Appreciate the contribution!