Fix/new mem mistaken for current fixing #2875
Enhance memory update prompt to handle empty memory case.
Description
PR Summary
Fixes handling of empty memory in the update memory prompt generation.
Changes
- Modified
mem0/configs/prompts.pyto handle cases whereretrieved_old_memory_dictis empty - Added conditional logic to display "Current memory is empty" when no existing memory is found
- Maintained existing prompt structure for non-empty memory cases
Impact
- Prevents potential formatting errors when memory is empty
- Improves clarity of memory update prompts
- Maintains backward compatibility with existing memory formats
Fixes #2875
Type of change
Please delete options that are not relevant.
- [x] Bug fix (non-breaking change which fixes an issue)
How Has This Been Tested?
Testing
- Verified prompt generation with both empty and non-empty memory cases
- Confirmed output formatting remains consistent with requirements
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Tested this with a basic chat with memory app. Entered a message with some new facts in them when there is no existing memories. It will properly identified that the current memory is empty and it emits an update that adds the new facts instead of setting their action to "NONE"
After these memories are added, following messages with new facts are added and existing memories are marked as NONE, UPDATE or DELETE as appropriate.
this is the llm config:
{
"model": "qwen/qwen3-30b-a3b:free",
"api_key": os.environ.get("OPENROUTER_API_KEY"),
"openrouter_base_url": "https://openrouter.ai/api/v1",
}
Please delete options that are not relevant.
- [x] Unit Test
Checklist:
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
- [x] Any dependent changes have been merged and published in downstream modules
- [x] I have checked my code and corrected any misspellings
Maintainer Checklist
- [ ] closes #xxxx (Replace xxxx with the GitHub issue number)
- [ ] Made sure Checks passed
Thx @johnwlockwood, I've faced the same issue and it would be a great improvement to include this behavior !
@johnwlockwood Thanks for the PR. Can you fix the failing tests?
@johnwlockwood Thanks for the PR. Can you fix the failing tests?
I merged in main and now the tests pass
@johnwlockwood thanks for this contribution!