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) -&gt; str: ”’Does something.”’ return x

@tool(name=”custom_name”, description=”Custom description”) def my_func(x: str) -&gt; str: return x

@tool(availability=lambda: (bool(os.getenv(“API_KEY”)), “API_KEY missing”)) def my_func(x: str) -&gt; str: return x

@tool(retry_policy=RetryPolicy(max_attempts=5)) def my_func(x: str) -&gt; str: return x

@tool(approval=True) def delete_account(user_id: str) -&gt; str: return “deleted”

@tool(approval=”critical”) def deploy(env: str) -&gt; str: return “deployed”

@tool(input_guardrails=[internal_only], output_guardrails=[no_secrets]) def send_email(to: str, body: str) -&gt; str: return “sent”

Diagram

uses

returns

Agent

Tool: tool

Result

Signature

python
def tool(func: Optional[Callable]) -> Union[FunctionTool, Callable[[Callable], FunctionTool]]

Parameters

ParamField Optional[Callable]

The function to wrap (when used without parentheses)

Returns

ResponseField 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 257


Related Documentation