-
Notifications
You must be signed in to change notification settings - Fork 62
fix: surface Desktop Agent OS errors to the agent instead of crashing #305
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 5 additions & 1 deletion
6
src/askui/tools/askui/askui_ui_controller_grpc/desktop_agent_os_error.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| class DesktopAgentOsError(BaseException): | ||
| class DesktopAgentOsError(Exception): | ||
| """Base class for Desktop Agent OS errors. | ||
|
|
||
| This error is raised when an error occurs in the Desktop Agent OS. | ||
|
|
||
| Inherits from `Exception` (not `BaseException`) so that the standard | ||
| `except Exception` handlers in the tool-calling loop can catch it and | ||
| surface it to the agent as a tool error result instead of crashing. | ||
| """ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """Tests that tool failures are surfaced to the agent instead of crashing. | ||
|
|
||
| When a tool raises, the tool-calling loop is expected to catch the error and | ||
| return a `ToolResultBlockParam` with `is_error=True` so the agent can react to | ||
| it. This only works if the raised exception derives from `Exception`; a | ||
| `BaseException` subclass would slip past the `except Exception` handler and | ||
| crash the run instead. `DesktopAgentOsError` (raised e.g. when reading a remote | ||
| file/directory that does not exist) must therefore behave like a regular | ||
| `Exception`. | ||
| """ | ||
|
|
||
| from askui.models.shared.agent_message_param import ( | ||
| ToolResultBlockParam, | ||
| ToolUseBlockParam, | ||
| ) | ||
| from askui.models.shared.tools import Tool, ToolCollection | ||
| from askui.tools.askui.askui_ui_controller_grpc.desktop_agent_os_error import ( | ||
| DesktopAgentOsError, | ||
| ) | ||
|
|
||
|
|
||
| class _RaisingTool(Tool): | ||
| """A tool whose `__call__` always raises a `DesktopAgentOsError`.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| super().__init__( | ||
| name="raising_tool", | ||
| description="Always raises a DesktopAgentOsError.", | ||
| ) | ||
|
|
||
| def __call__(self) -> str: | ||
| raise DesktopAgentOsError(self._error_message) | ||
|
|
||
| _error_message = ( | ||
| "directory_iterator::directory_iterator: The system cannot find the " | ||
| 'path specified.: "FrontEnd\\Traces"' | ||
| ) | ||
|
|
||
|
|
||
| class TestDesktopAgentOsErrorHandling: | ||
| def test_desktop_agent_os_error_is_an_exception(self) -> None: | ||
| assert issubclass(DesktopAgentOsError, Exception) | ||
|
|
||
| def test_raising_tool_returns_error_result_instead_of_crashing(self) -> None: | ||
| tool = _RaisingTool() | ||
| collection = ToolCollection(tools=[tool]) | ||
| tool_use = ToolUseBlockParam( | ||
| id="tool_use_1", | ||
| input={}, | ||
| name=tool.name, | ||
| ) | ||
|
|
||
| results = collection.run([tool_use]) | ||
|
|
||
| assert len(results) == 1 | ||
| result = results[0] | ||
| assert isinstance(result, ToolResultBlockParam) | ||
| assert result.is_error is True | ||
| assert result.tool_use_id == "tool_use_1" | ||
| assert "FrontEnd\\Traces" in str(result.content) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thought we wanted to have two types: DesktopAgentOsError for errors that aren’t fixable, and DesktopAgentOsException for errors that are recoverable by the agent.
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.
You are right. I guess then I'll just close this PR?