fix(crewai): align memory storage save with LongTermMemory contract#2232
Open
anxkhn wants to merge 4 commits into
Open
fix(crewai): align memory storage save with LongTermMemory contract#2232anxkhn wants to merge 4 commits into
anxkhn wants to merge 4 commits into
Conversation
CrewAI's LongTermMemory.save() calls its storage as save(task_description=..., score=..., metadata=..., datetime=...), passing the timestamp as the keyword argument 'datetime' (matching the reference LTMSQLiteStorage.save signature). KagentMemoryStorage named that parameter 'timestamp', so every long-term-memory write on a memory-enabled crew raised TypeError: got an unexpected keyword argument 'datetime'. Rename the parameter to 'datetime' so the signature matches the storage contract, and add a regression test that drives a save through crewai's LongTermMemory with the HTTP client mocked. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a runtime incompatibility between kagent-crewai’s KagentMemoryStorage and CrewAI’s LongTermMemory storage contract by aligning the save() method’s keyword argument name with what CrewAI passes (datetime), preventing TypeError during long-term memory persistence.
Changes:
- Renamed
KagentMemoryStorage.save’s third parameter fromtimestamptodatetimeand forwarded it asmemory_data["datetime"]. - Added unit tests to verify the storage signature matches CrewAI’s reference backend and that
LongTermMemory.save()forwardsdatetimecorrectly. - Added a test
conftest.pyto provide default env vars needed for importingkagent.crewaiin unit tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/packages/kagent-crewai/src/kagent/crewai/_memory.py | Aligns save() signature and payload field name with CrewAI’s datetime keyword contract. |
| python/packages/kagent-crewai/tests/test_memory.py | Adds regression tests for the signature mismatch and for correct datetime forwarding through LongTermMemory.save(). |
| python/packages/kagent-crewai/tests/conftest.py | Sets environment defaults so the package can be imported in tests without requiring external configuration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
peterj
previously approved these changes
Jul 14, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
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.
What
KagentMemoryStorage.savenames its third parametertimestamp, but CrewAI'sLongTermMemoryinvokes its storage backend with that value passed as thekeyword argument
datetime:The reference backend
LTMSQLiteStorage.save(self, task_description, metadata, datetime, score)names that parameterdatetime, so any storage that plugsinto
LongTermMemoryhas to use the same keyword. BecauseKagentMemoryStorageuses
timestampinstead, every long-term-memory write raises:_executor.pywiresKagentMemoryStorageas the crew'sLongTermMemorybackend when memory is enabled, so this fires on any memory-enabled CrewAI crew
(
crew.memory=True) the first time it persists a long-term-memory item. Theexception propagates out of
LongTermMemory.saveafter aMemorySaveFailedEventis emitted.
Fix
Rename the parameter from
timestamptodatetimeso the signature matches thestorage contract exactly. This is a two-line change and also aligns
savewiththe sibling
load, which already reads and writes thedatetimekey.Tests
Added
packages/kagent-crewai/tests/test_memory.py:test_save_signature_matches_crewai_storage_contractassertsKagentMemoryStorage.save's parameters match the referenceLTMSQLiteStorage.save.test_long_term_memory_save_posts_datetimedrives a realLongTermMemory(KagentMemoryStorage(...)).save(LongTermMemoryItem(...))withthe HTTP client mocked and asserts the item's datetime is forwarded to the
backend in
memory_data["datetime"].A new
tests/conftest.pysetsKAGENT_URL/KAGENT_NAME/KAGENT_NAMESPACEdefaults so the package imports without a running backend. Both tests fail on
main(the second with the exact upstreamTypeError) and pass with the fix.Run: