Skip to content
Closed
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
4 changes: 4 additions & 0 deletions llama_stack/distribution/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def translate_exception(exc: Exception) -> Union[HTTPException, RequestValidatio
)
elif isinstance(exc, ValueError):
return HTTPException(status_code=400, detail=f"Invalid value: {str(exc)}")
elif isinstance(exc, TypeError):
return HTTPException(status_code=400, detail=f"Type Error: {str(exc)}")
elif isinstance(exc, KeyError):
return HTTPException(status_code=400, detail=f"Key Error: {str(exc)}")
elif isinstance(exc, PermissionError):
return HTTPException(status_code=403, detail=f"Permission denied: {str(exc)}")
elif isinstance(exc, TimeoutError):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ async def create_session(self, name: str) -> str:
async def create_and_execute_turn(
self, request: AgentTurnCreateRequest
) -> AsyncGenerator:
assert request.stream is True, "Non-streaming not supported"
if not request.stream:
raise NotImplementedError("Non-streaming not supported")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is good


session_info = await self.storage.get_session_info(request.session_id)
if session_info is None:
Expand Down Expand Up @@ -561,9 +562,10 @@ async def _run(
self.tools_dict,
[message],
)
assert (
len(result_messages) == 1
), "Currently not supporting multiple messages"
if len(result_messages) != 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is still an assertion failure so this change is not good

raise ValueError(
"Currently not supporting multiple messages"
)
result_message = result_messages[0]

yield AgentTurnResponseStreamChunk(
Expand Down Expand Up @@ -682,7 +684,9 @@ async def _retrieve_context(
bank_ids = []

memory = self._memory_tool_definition()
assert memory is not None, "Memory tool not configured"
if memory is None:
raise KeyError("Memory tool not configured")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this is right either


bank_ids.extend(c.bank_id for c in memory.memory_bank_configs)

if attachments:
Expand Down Expand Up @@ -813,16 +817,19 @@ async def execute_tool_call_maybe(
# When this changes, we can drop this assert
# Whether to call tools on each message and aggregate
# or aggregate and call tool once, reamins to be seen.
assert len(messages) == 1, "Expected single message"
if len(messages) != 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or this

raise ValueError("Expected single message")
message = messages[0]

tool_call = message.tool_calls[0]
name = tool_call.tool_name
assert isinstance(name, BuiltinTool)

if not isinstance(name, BuiltinTool):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, this needs to be an assert

raise TypeError(f"Tool {name} is not an instance of BuiltinTool.")
name = name.value
if name not in tools_dict:
raise KeyError(f"Tool {name} not found in agent config.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems correct but I might call it a ValueError


assert name in tools_dict, f"Tool {name} not found"
tool = tools_dict[name]
result_messages = await tool.run(messages)
return result_messages
Expand Down