tool • AI Agent SDK
tool: Decorator to convert a function into a tool.
tool
Function
</div>
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”
@tool(input_guardrails=[internal_only], output_guardrails=[no_secrets]) def send_email(to: str, body: str) -> str: return “sent”
Signature
def tool(func: Optional[Callable]) -> Union[FunctionTool, Callable[[Callable], FunctionTool]]Parameters
Optional[Callable]The function to wrap (when used without parentheses)
Returns
Union[FunctionTool, Callable[[Callable], FunctionTool]]FunctionTool instance that wraps the function
Uses
FunctionTooladd_approval_requirementRuntimeErrortool_instance.validatetool_instance.validate_schema_roundtriplogging.warninglogging.debugget_registryregistry.registerdecorator
Source
View on GitHubpraisonaiagents/tools/decorator.py at line 257