Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added implementations for get_agents_session, delete_agents_session and delete_agents #267

Merged
merged 7 commits into from
Oct 22, 2024
Merged
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
6 changes: 2 additions & 4 deletions llama_stack/apis/agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,12 @@ def create_agent_turn(

@webmethod(route="/agents/turn/get")
async def get_agents_turn(
self,
agent_id: str,
turn_id: str,
self, agent_id: str, session_id: str, turn_id: str
) -> Turn: ...

@webmethod(route="/agents/step/get")
async def get_agents_step(
self, agent_id: str, turn_id: str, step_id: str
self, agent_id: str, session_id: str, turn_id: str, step_id: str
) -> AgentStepResponse: ...

@webmethod(route="/agents/session/create")
Expand Down
46 changes: 39 additions & 7 deletions llama_stack/providers/impls/meta_reference/agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,56 @@ async def _create_agent_turn_streaming(
async for event in agent.create_and_execute_turn(request):
yield event

async def get_agents_turn(self, agent_id: str, turn_id: str) -> Turn:
raise NotImplementedError()
async def get_agents_turn(
self, agent_id: str, session_id: str, turn_id: str
) -> Turn:
turn = await self.persistence_store.get(
f"session:{agent_id}:{session_id}:{turn_id}"
)
turn = json.loads(turn)
turn = Turn(**turn)
return turn

async def get_agents_step(
self, agent_id: str, turn_id: str, step_id: str
self, agent_id: str, session_id: str, turn_id: str, step_id: str
) -> AgentStepResponse:
raise NotImplementedError()
turn = await self.persistence_store.get(
f"session:{agent_id}:{session_id}:{turn_id}"
)
turn = json.loads(turn)
turn = Turn(**turn)
steps = turn.steps
for step in steps:
if step.step_id == step_id:
return AgentStepResponse(step=step)
raise ValueError(f"Provided step_id {step_id} could not be found")

async def get_agents_session(
self,
agent_id: str,
session_id: str,
turn_ids: Optional[List[str]] = None,
) -> Session:
raise NotImplementedError()
session = await self.persistence_store.get(f"session:{agent_id}:{session_id}")
session = Session(**json.loads(session))
turns = []
if turn_ids:
for turn_id in turn_ids:
turn = await self.persistence_store.get(
f"session:{agent_id}:{session_id}:{turn_id}"
)
turn = json.loads(turn)
turn = Turn(**turn)
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()
await self.persistence_store.delete(f"session:{agent_id}:{session_id}")

async def delete_agents(self, agent_id: str) -> None:
cheesecake100201 marked this conversation as resolved.
Show resolved Hide resolved
raise NotImplementedError()
await self.persistence_store.delete(f"agent:{agent_id}")