fix: delete agent-source mapping on detachment and add test (#1862)

This commit is contained in:
Sarah Wooders
2024-10-09 17:26:28 -07:00
committed by GitHub
parent 1673e66211
commit 828aae8d6e
2 changed files with 7 additions and 0 deletions

View File

@@ -1623,6 +1623,11 @@ class SyncServer(Server):
agent = self._get_or_load_agent(agent_id=agent_id)
archival_memory = agent.persistence_manager.archival_memory
archival_memory.storage.delete({"source_id": source_id})
# delete agent-source mapping
self.ms.detach_source(agent_id=agent_id, source_id=source_id)
# return back source data
return source
def list_attached_sources(self, agent_id: str) -> List[Source]:

View File

@@ -395,10 +395,12 @@ def test_sources(client: Union[LocalClient, RESTClient], agent: AgentState):
print(sources)
# detach the source
assert len(client.get_archival_memory(agent_id=agent.id)) > 0, "No archival memory"
deleted_source = client.detach_source(source_id=source.id, agent_id=agent.id)
assert deleted_source.id == source.id
archival_memories = client.get_archival_memory(agent_id=agent.id)
assert len(archival_memories) == 0, f"Failed to detach source: {len(archival_memories)}"
assert source.id not in [s.id for s in client.list_attached_sources(agent.id)]
# delete the source
client.delete_source(source.id)