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:

python
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

python
from praisonaiagents.tools import decorator

Classes

Functions

Constants

NameValue
_VALID_RISK_LEVELS('critical', 'high', 'medium', 'low')
_UNSETobject()