fix: handle tool execution errors in AgentTools._process_tool#513
Open
YuemengZheng wants to merge 1 commit into
Open
fix: handle tool execution errors in AgentTools._process_tool#513YuemengZheng wants to merge 1 commit into
YuemengZheng wants to merge 1 commit into
Conversation
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
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue Link (REQUIRED)
Fixes #250
Summary
Changes
AgentTools._process_toolonly caughtStopIteration(the missing-tool case) and let any exception raised by the tool's ownfuncpropagate, crashing the whole request flow. This brings the Python behavior in line with the TypeScriptprocessTool, which already returns an error string when a tool errors:Tool '<name>' not found(unchanged behavior, rewritten withnext(..., None)so aStopIterationraised inside a tool can't be mislabeled as "not found").Error processing tool '<name>': <error>(previously uncaught).Also fixed the existing
test_tool_not_found, which asserted inside anexceptblock that never executed (the function returns rather than raises), and addedtest_tool_processing_errorfor 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