Added implementations for get_agents_session, delete_agents_session and delete_agents

This commit is contained in:
Sarthak Deshpande 2024-10-18 12:44:42 +05:30
parent be3c5c034d
commit 9bcd03fe2a

View file

@ -152,10 +152,43 @@ class MetaReferenceAgentsImpl(Agents):
session_id: str,
turn_ids: Optional[List[str]] = None,
) -> Session:
raise NotImplementedError()
session = await self.persistence_store.get(f"session:{agent_id}:{session_id}")
try:
session = Session(**json.loads(session))
except json.JSONDecodeError as e:
raise ValueError(
f"Could not JSON decode session for {agent_id} and {session_id}"
) from e
turns = []
for turn_id in turn_ids:
turn = await self.persistence_store.get(f"session:{agent_id}:{session_id}:{turn_id}")
try:
turn = json.loads(turn)
except json.JSONDecodeError as e:
raise ValueError(
f"Could not JSON decode session for {agent_id} and {session_id}"
) from e
try:
turn = Turn(**turn)
except Exception as e:
raise ValueError(
f"Could not validate(?) Turns for {turn_id}"
) from e
turns.append(turn)
return Session(
session_name=session.session_name,
session_id=session_id,
turns=turns if turns else [],
started_at=session.started_at
)
async def delete_agents_session(self, agent_id: str, session_id: str) -> None:
raise NotImplementedError()
try:
await self.persistence_store.delete(f"session:{agent_id}:{session_id}")
except:
raise ValueError("Session Key Not Found")
async def delete_agents(self, agent_id: str) -> None:
raise NotImplementedError()
try:
await self.persistence_store.delete(f"agent:{agent_id}")
except:
raise ValueError("Agent Key not found")