decorator • AI Agent SDK
Tool decorator for converting functions into tools.
decorator
AI Agent
Tool decorator for converting functions into tools.
This module provides the @tool decorator for easily creating tools from functions.
Usage:
from praisonaiagents import tool
@tool
def search(query: str) -> list:
'''Search the web for information.'''
return [...]
# Or with explicit parameters:
@tool(name="web_search", description="Search the internet")
def search(query: str, max_results: int = 5) -> list:
return [...]
# With injected state:
from praisonaiagents.tools import Injected
@tool
def my_tool(query: str, state: Injected[dict]) -> str:
'''Tool with injected state.'''
return f"session={state.get('session_id')}"
# Requiring human approval (mirrors Agent(approval=...)):
@tool(approval=True)
def refund_order(order_id: str) -> str:
return "refunded"
# Guarding just this one tool's arguments and result:
def internal_only(arguments: dict):
if not arguments["to"].endswith("@corp.com"):
return False, "Recipient is outside the company domain."
return True, arguments
@tool(input_guardrails=[internal_only])
def send_email(to: str, body: str) -> str:
return "sent"Import
from praisonaiagents.tools import decoratorClasses
Functions
is_injected_type()
Function definition.
get_injected_params()Function definition.
inject_state_into_kwargs()Function definition.
tool()Decorator to convert a function into a tool.
is_tool()Check if an object is a tool (BaseTool instance or decorated function).
get_tool_schema()Get OpenAI-compatible schema for any tool-like object.
Constants
| Name | Value |
|---|---|
_VALID_RISK_LEVELS | ('critical', 'high', 'medium', 'low') |
_UNSET | object() |