diff --git a/letta/server/server.py b/letta/server/server.py index d9036f26a0..5088e9effc 100644 --- a/letta/server/server.py +++ b/letta/server/server.py @@ -1623,6 +1623,11 @@ def detach_source_from_agent( 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]: diff --git a/tests/test_client.py b/tests/test_client.py index b81a0acd51..58c7775ec6 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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)