Skip to main content

tool

Function
This function is defined in the decorator module.
Decorator to convert a function into a tool. Can be used with or without arguments: @tool def my_func(x: str) -> str: '''Does something.''' return x @tool(name=“custom_name”, description=“Custom description”) def my_func(x: str) -> str: return x @tool(availability=lambda: (bool(os.getenv(“API_KEY”)), “API_KEY missing”)) def my_func(x: str) -> str: return x @tool(retry_policy=RetryPolicy(max_attempts=5)) def my_func(x: str) -> str: return x @tool(approval=True) def delete_account(user_id: str) -> str: return “deleted” @tool(approval=“critical”) def deploy(env: str) -> str: return “deployed”

Signature

Parameters

Optional[Callable]
The function to wrap (when used without parentheses)

Returns

Union[FunctionTool, Callable[[Callable], FunctionTool]]
FunctionTool instance that wraps the function

Uses

  • FunctionTool
  • add_approval_requirement
  • RuntimeError
  • tool_instance.validate
  • tool_instance.validate_schema_roundtrip
  • logging.warning
  • logging.debug
  • get_registry
  • registry.register
  • decorator

Source

View on GitHub

praisonaiagents/tools/decorator.py at line 232

Tools Concept

Create Custom Tools

Tool Development