Skip to content

fix: handle tool execution errors in AgentTools._process_tool#513

Open
YuemengZheng wants to merge 1 commit into
2FastLabs:mainfrom
YuemengZheng:fix/process-tool-error-handling
Open

fix: handle tool execution errors in AgentTools._process_tool#513
YuemengZheng wants to merge 1 commit into
2FastLabs:mainfrom
YuemengZheng:fix/process-tool-error-handling

Conversation

@YuemengZheng

Copy link
Copy Markdown

Issue Link (REQUIRED)

Fixes #250

Summary

Changes

AgentTools._process_tool only caught StopIteration (the missing-tool case) and let any exception raised by the tool's own func propagate, crashing the whole request flow. This brings the Python behavior in line with the TypeScript processTool, which already returns an error string when a tool errors:

  • Missing tool → Tool '<name>' not found (unchanged behavior, rewritten with next(..., None) so a StopIteration raised inside a tool can't be mislabeled as "not found").
  • Tool raises during execution → Error processing tool '<name>': <error> (previously uncaught).

Also fixed the existing test_tool_not_found, which asserted inside an except block that never executed (the function returns rather than raises), and added test_tool_processing_error for the new error path.

User experience

Before: a tool that raised an exception (or a prompt referencing a mistyped tool name) surfaced as an unhandled error that aborted route_request. After: the error is returned as a tool result string, so the agent loop can see it and respond gracefully instead of crashing.

Checklist

  • I have performed a self-review of this change
  • Changes have been tested
  • Changes are documented
  • I have linked this PR to an existing issue (required)

Only StopIteration (missing tool) was caught; exceptions raised by a tool's
own func propagated and aborted the request flow. Catch execution errors and
return them as a result string, matching the TypeScript processTool behavior.
Also fix the vacuous test_tool_not_found assertion and cover the error path.

Closes 2FastLabs#250
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Handling missing or erroring tools

1 participant