Skip to content

feat(tool): tool_error_notifier #1177

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Lin-Nikaido
Copy link

@Lin-Nikaido Lin-Nikaido commented Jun 5, 2025

A decorator that wraps a tool function and catches a specific exception.
If the specified exception occurs, it returns True, signaling an error back to the LLM agent.

Expample

import tool_error_notifier


@tool_error_notifier(KeyError)
function your_tool(arg1, arg2):
  ...
  retrun {
    "key1": "value1"
  }

More useful.

import tool_error_notifier


class BaseToolException(Exception):
    pass


class ToolIndexError(IndexError, BaseToolException):
    pass


class ToolNameError(NameError, BaseToolException):
    pass



@tool_error_notifier(BaseToolException)
function your_tool(arg1, arg2):
  ...
  if is_unexpected_occur():
    raise ToolNameError("something wrong!")
  ...
  retrun {
    "key1": "value1"
  }

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.

2 participants