Overview
Decorators provide a clean, declarative way to define tool metadata, parameters, validators, and behavior.@tool
Mark a method as a plugin tool:Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
name | str | Yes | Unique tool name (lowercase, underscores) |
description | str | Yes | Clear description for AI and users |
Best Practices
- name: Use descriptive, lowercase names with underscores (
get_weather, notgetWeather) - description: Be specific and concise (AI uses this to decide when to call the tool)
@parameter
Define tool parameters:Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
name | str | Yes | Parameter name (must match function argument) |
type | str | Yes | Data type: string, number, boolean, array, object |
required | bool | No | Whether parameter is required (default: True) |
default | any | No | Default value if not provided |
description | str | No | Parameter description |
Parameter Types
Decorator Order
IMPORTANT: Stack parameters in reverse order (bottom-up):@validator
Validate parameter values:Validation Options
Allowed Values
Numeric Range
String Length
Pattern Matching
All Validator Parameters
| Parameter | Type | Description |
|---|---|---|
param_name | str | Parameter to validate |
allowed_values | list | List of allowed values |
min_value | float | Minimum numeric value |
max_value | float | Maximum numeric value |
min_length | int | Minimum string/array length |
max_length | int | Maximum string/array length |
pattern | str | Regex pattern (for strings) |
@validate_parameters
Advanced schema-based validation:Schema Format
@permission_required
Require specific permissions:Available Permissions
| Permission | Description |
|---|---|
llm_access | Invoke LLM models |
knowledge_access | Search knowledge bases |
storage_access | Use persistent storage |
tools_access | Invoke other tools |
network_access | Make external API calls |
@retry
Automatic retry on failure:Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
max_attempts | int | 3 | Maximum retry attempts |
delay | float | 1.0 | Initial delay between retries (seconds) |
backoff | float | 2.0 | Backoff multiplier for exponential delay |
Combining Decorators
Stack decorators for full functionality:Decorator Order
Correct order (top to bottom):@tool- Always first@parameter- Define parameters (reverse order)@validator- Validate parameters@permission_required- Check permissions@retry- Retry logic (if needed)
Common Patterns
Email + Phone Validation
Enum-style Parameters
Pagination Parameters
Best Practices
Validate Early
Validate Early
Use
@validator to catch invalid inputs before executionClear Descriptions
Clear Descriptions
Write clear parameter descriptions - AI uses these to understand what to pass
Sensible Defaults
Sensible Defaults
Provide defaults for optional parameters to improve UX
Permission Checks
Permission Checks
Always use
@permission_required when accessing internal APIsRetry for Network
Retry for Network
Use
@retry for external API calls and network operations