Skip to content

Commit

Permalink
fix: delete agent-source mapping on detachment and add test (#1862)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahwooders authored Oct 10, 2024
1 parent 6506a52 commit e3c22f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions letta/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e3c22f1

Please sign in to comment.