Skip to content

fix(crewai): align memory storage save with LongTermMemory contract#2232

Open
anxkhn wants to merge 4 commits into
kagent-dev:mainfrom
anxkhn:fix/crewai-memory-save-datetime-kwarg
Open

fix(crewai): align memory storage save with LongTermMemory contract#2232
anxkhn wants to merge 4 commits into
kagent-dev:mainfrom
anxkhn:fix/crewai-memory-save-datetime-kwarg

Conversation

@anxkhn

@anxkhn anxkhn commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

What

KagentMemoryStorage.save names its third parameter timestamp, but CrewAI's
LongTermMemory invokes its storage backend with that value passed as the
keyword argument datetime:

# crewai/memory/long_term/long_term_memory.py (LongTermMemory.save)
self.storage.save(
    task_description=item.task,
    score=metadata["quality"],
    metadata=metadata,
    datetime=item.datetime,
)

The reference backend LTMSQLiteStorage.save(self, task_description, metadata, datetime, score) names that parameter datetime, so any storage that plugs
into LongTermMemory has to use the same keyword. Because KagentMemoryStorage
uses timestamp instead, every long-term-memory write raises:

TypeError: KagentMemoryStorage.save() got an unexpected keyword argument 'datetime'

_executor.py wires KagentMemoryStorage as the crew's LongTermMemory
backend 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. The
exception propagates out of LongTermMemory.save after a MemorySaveFailedEvent
is emitted.

Fix

Rename the parameter from timestamp to datetime so the signature matches the
storage contract exactly. This is a two-line change and also aligns save with
the sibling load, which already reads and writes the datetime key.

Tests

Added packages/kagent-crewai/tests/test_memory.py:

  • test_save_signature_matches_crewai_storage_contract asserts
    KagentMemoryStorage.save's parameters match the reference
    LTMSQLiteStorage.save.
  • test_long_term_memory_save_posts_datetime drives a real
    LongTermMemory(KagentMemoryStorage(...)).save(LongTermMemoryItem(...)) with
    the HTTP client mocked and asserts the item's datetime is forwarded to the
    backend in memory_data["datetime"].

A new tests/conftest.py sets KAGENT_URL / KAGENT_NAME / KAGENT_NAMESPACE
defaults so the package imports without a running backend. Both tests fail on
main (the second with the exact upstream TypeError) and pass with the fix.

Run:

cd python
uv run pytest packages/kagent-crewai/tests/

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>
Copilot AI review requested due to automatic review settings July 13, 2026 23:40
@anxkhn
anxkhn requested a review from a team as a code owner July 13, 2026 23:40
@github-actions github-actions Bot added the bug Something isn't working label Jul 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 from timestamp to datetime and forwarded it as memory_data["datetime"].
  • Added unit tests to verify the storage signature matches CrewAI’s reference backend and that LongTermMemory.save() forwards datetime correctly.
  • Added a test conftest.py to provide default env vars needed for importing kagent.crewai in 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.

Comment thread python/packages/kagent-crewai/tests/conftest.py Outdated
peterj
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants