-
Notifications
You must be signed in to change notification settings - Fork 1.2k
return proper error from agent instance to the client #493
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
Conversation
03bdc3b
to
7edc683
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is actually not what we want. Because this would mean we are potentially exposing private server-side state (could be something sensitive too) directly to the user. The best you can do is log the exception (which I believe is already logged?)
Agree that reporting all exceptions in http 500 response is too much and might include some sensitive info from the server. We have a bunch of asserts in I have updated to catch the |
2230e28
to
2082c21
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think assertions are still internal. They should be translated into appropriate ValueErrors at the place where you are throwing that assert -- if you think there is no internal state being divulged. The assertion message can then be approrpiately changed to indicate that this is a user-facing message (and would be nicer.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was tempted to change those assert
to raise exception
. Is there any reason why we are using assert
? Usually assert is for fatal issue and we need to shutdown the application as I know?
Let me change those assert to raise value exception then, if appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chuenlok Indeed, the assert may be inappropriate and perhaps we should introduce a specific UnexpectedModelOutputError
which we then explicitly handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a friendly list of what generic Exceptions could be caught at the highest level and potentially exposed to the user: https://gist.github.com/ashwinb/8f2ced735408774f6bd41b5188ae974c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a friendly list of what generic Exceptions could be caught at the highest level and potentially exposed to the user: https://gist.github.com/ashwinb/8f2ced735408774f6bd41b5188ae974c
This is really useful! I am still new to the stack and might not be able to use the correct exception. Let me give it a try based on your list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converted some assert to exceptions and leave the internal one untouched.
2082c21
to
7d968de
Compare
undo the linter changes catch the assert error and report to the client fix linter issue convert asserts to raise exception for better error hanlding translate assert to exception accordingly
7d968de
to
663f222
Compare
@ashwinb Can you review this PR please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think several of these changes are not quite correct
) -> AsyncGenerator: | ||
assert request.stream is True, "Non-streaming not supported" | ||
if not request.stream: | ||
raise NotImplementedError("Non-streaming not supported") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is good
assert ( | ||
len(result_messages) == 1 | ||
), "Currently not supporting multiple messages" | ||
if len(result_messages) != 1: |
There was a problem hiding this comment.
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
memory = self._memory_tool_definition() | ||
assert memory is not None, "Memory tool not configured" | ||
if memory is None: | ||
raise KeyError("Memory tool not configured") |
There was a problem hiding this comment.
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
# 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or this
name = tool_call.tool_name | ||
assert isinstance(name, BuiltinTool) | ||
|
||
if not isinstance(name, BuiltinTool): |
There was a problem hiding this comment.
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.") |
There was a problem hiding this comment.
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
What does this PR do?
The assert errors are not returned to the client and hid by the 500 internal server error. Append the real error in the error message so the client can show it. Updates on the python client llamastack/llama-stack-client-python#44
Test Plan
Please describe:
llama stack run /Users/henrytai/.llama/distributions/llamastack-ollama/ollama-run.yaml --port 5050
PYTHONPATH=. python -m examples.agents.client localhost 5050
from thellama-stack-apps
repo. The issue details: "This is a known issue with Llama3.2-3B-Instruct on ollama, where the model produces bad tool calling outputs. In this case, the server agent fails due to assert error that "code_interpreter" is not in the AgentConfig's tools field" but the code_interpreter is not really necessary as it is not needed in Llama3.1-8B.client log:
Showing the real error in the client: Tool code_interpreter not found
Sources
Please link relevant resources if necessary.
Before submitting
Pull Request section?