Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ async def add_memory(
) -> str:
"""Add (remember) memories/details/information about the user or other facts or entities. Run when explicitly asked or when the user mentions any information generalizable beyond the context of the current conversation."""
try:
# No custom_id: each remembered fact is its own document. A shared id would
# make every call update one document, replacing the previous memory and
# colliding with the conversation transcript saved under connection.custom_id.
response = await self._client.add(
content=memory,
container_tag=self._connection.container_tag,
custom_id=self._connection.custom_id,
)
result: MemoryAddResult = {
"success": True,
Expand Down
28 changes: 28 additions & 0 deletions packages/agent-framework-python/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,31 @@ def test_shares_custom_id_with_connection(self) -> None:
conn = _make_conn(conversation_id="conv-123")
tools = SupermemoryTools(conn)
assert tools._connection.custom_id == "conversation_conv-123"


class _RecordingClient:
def __init__(self) -> None:
self.add_calls: list[dict] = []

async def add(self, **kwargs):
self.add_calls.append(kwargs)
return {"id": f"doc-{len(self.add_calls)}", "status": "queued"}


class TestAddMemoryDocumentIdentity:
@pytest.mark.asyncio
async def test_add_memory_does_not_reuse_conversation_document_id(self) -> None:
conn = _make_conn(conversation_id="conv-123")
tools = SupermemoryTools(conn)
client = _RecordingClient()
tools._client = client

await tools.add_memory("The user likes green tea.")
await tools.add_memory("The user lives in Lisbon.")

assert len(client.add_calls) == 2
# A shared custom_id makes Supermemory treat every call as an update of one
# document, so the second memory replaces the first and both collide with the
# conversation transcript saved under the same id.
assert all(call.get("custom_id") != conn.custom_id for call in client.add_calls)
assert all(call["container_tag"] == "msft_agent_chat" for call in client.add_calls)