fix: use correct format when adding memory to mem0 (#6831)

Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
This commit is contained in:
Saverio Murgia
2025-07-24 00:46:59 +02:00
committed by GitHub
parent 7c536a8c95
commit e26bb1c850
3 changed files with 12 additions and 3 deletions

1
.gitignore vendored
View File

@@ -202,3 +202,4 @@ registry.json
# files created by the gitty agent in python/samples/gitty
.gitty/
.aider*

View File

@@ -257,7 +257,7 @@ class Mem0Memory(Memory, Component[Mem0MemoryConfig], ComponentBase[Mem0MemoryCo
# Suppress warning messages from mem0 MemoryClient
kwargs = {} if self._client.__class__.__name__ == "Memory" else {"output_format": "v1.1"}
with redirect_stdout(io.StringIO()), redirect_stderr(io.StringIO()):
self._client.add(message, user_id=user_id, metadata=metadata, **kwargs) # type: ignore
self._client.add([{"role": "user", "content": message}], user_id=user_id, metadata=metadata, **kwargs) # type: ignore
except Exception as e:
# Log the error but don't crash
logger.error(f"Error adding to mem0 memory: {str(e)}")

View File

@@ -103,7 +103,11 @@ async def test_basic_workflow(mock_mem0_class: MagicMock, local_config: Mem0Memo
# Verify add was called correctly
mock_mem0.add.assert_called_once()
call_args = mock_mem0.add.call_args[0]
assert call_args[0] == "Paris is known for the Eiffel Tower and amazing cuisine."
# Extract content from the list of dict structure: [{'content': '...', 'role': 'user'}]
actual_content = call_args[0][0]["content"]
assert actual_content == "Paris is known for the Eiffel Tower and amazing cuisine."
call_kwargs = mock_mem0.add.call_args[1]
assert call_kwargs["metadata"] == {"category": "city", "country": "France"}
@@ -173,7 +177,11 @@ async def test_basic_workflow_with_cloud(mock_memory_client_class: MagicMock, cl
# Verify add was called correctly
mock_client.add.assert_called_once()
call_args = mock_client.add.call_args
assert test_content in str(call_args[0][0]) # Check that content was passed
# Extract content from list of dict structure: [{'content': '...', 'role': 'user'}]
actual_content = call_args[0][0][0]["content"] # call_args[0][0] gets the first positional arg (the list)
assert test_content in actual_content
assert call_args[1]["user_id"] == cloud_config.user_id
assert call_args[1]["metadata"]["test"] is True