feat: Add on_tool_not_found event (#107)#115
Open
esreekarreddy wants to merge 1 commit intoopenonion:mainfrom
Open
feat: Add on_tool_not_found event (#107)#115esreekarreddy wants to merge 1 commit intoopenonion:mainfrom
esreekarreddy wants to merge 1 commit intoopenonion:mainfrom
Conversation
Add event that fires when LLM requests a tool that doesn't exist, enabling custom error messages, fuzzy matching suggestions, and tool usage analytics.
6f413da to
fa33a07
Compare
Contributor
Author
|
Rebased onto upstream main (15 new commits merged, including PR-116 multimodal input support). No conflicts — upstream changes were in unrelated files (network, tool_approval refactor, file upload). All 83 tests still pass. |
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.
Summary
Add event that fires when the LLM requests a tool that doesn't exist, enabling better error messages and tool suggestions.
Closes #107
Motivation
Currently when the LLM calls a non-existent tool, the agent returns a generic
"Tool 'x' not found"message with no additional context. Plugins have no way to intercept this to provide fuzzy matching, dynamic tool loading, or better diagnostics.Changes
connectonion/core/events.py— Newon_tool_not_found()wrapper function (supports decorator + multi-arg syntax)connectonion/core/agent.py— Registeron_tool_not_foundin event registry; add_invoke_events_with_return()method that collects handler return valuesconnectonion/core/tool_executor.py— Storepending_toolin session before event fires; invokeon_tool_not_foundvia_invoke_events_with_return(); use handler's return value as error message if providedconnectonion/core/__init__.py— Exporton_tool_not_foundconnectonion/__init__.py— Exporton_tool_not_foundCLAUDE.md— Updated events listdocs/concepts/events.md— Added table row, lifecycle diagram entry, and usage exampletests/unit/test_tool_not_found.py— 15 new teststests/unit/test_events.py— Addedon_tool_not_foundto wrapper type assertiontests/unit/test_tool_executor.py— Added_invoke_events_with_returnstub to FakeAgenttests/unit/test_tool_executor_errors.py— Added_invoke_events_with_returnstub to mock agentsAPI
Handler returns a string to override the default error message. Return
None(or nothing) to keep the default"Tool 'x' not found"behavior.Tests
All 83 relevant tests pass (15 new + 68 existing). Zero regressions.
Edge cases tested:
pending_toolset in session before handler fires, cleared afternot_found_invoke_events_with_returnreturns first non-None result