Tool Definition
Laddr tools are Python functions decorated with@tool. Parameter schemas are automatically generated from function signatures, so you don’t need to manually define JSON schemas.
Basic Tool
With Pydantic Model
For complex validation, use a Pydantic BaseModel as the first parameter:Minimal Tool (Auto-inferred)
If you omitname and description, they’re inferred from the function:
@tool Decorator Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
name | str | ❌ | Unique tool identifier (auto-inferred from function name) |
description | str | ❌ | What the tool does (auto-inferred from docstring) |
trace | bool | ❌ | Enable tracing (default: True) |
trace_mask | list[str] | ❌ | Fields to redact in traces |
Parameter Descriptions
name
Rules:
- Must be unique and descriptive
- Use lowercase
snake_case - Avoid generic names
- If omitted, uses function name
description
Best Practices:
- Begin with an action verb
- Limit to 100 characters
- Avoid redundant phrasing like “use this tool to…”
- If omitted, uses first line of docstring
trace
Enables or disables trace logging.
Example:
False when:
- Handling sensitive user data
- Reducing log volume for high-frequency tools
trace_mask
Redacts specified fields in traces.
Example:
***REDACTED*** in logs.
Automatic Schema Generation
Parameter schemas are automatically generated from Python function signatures. The system maps Python types to JSON Schema types:| Python Type | JSON Schema Type | Example |
|---|---|---|
str | string | query: str |
int | integer | limit: int |
float | number | price: float |
bool | boolean | enabled: bool |
list[T] | array | items: list[str] |
dict | object | config: dict |
Optional[T] | Type with null | timeout: int | None |
BaseModel | object (validated) | inputs: MyModel |
Type Hints Examples
Supported Type Annotations
- Basic types:
str,int,float,bool - Collections:
list[T],dict,tuple - Optional:
Optional[T]orT | None - Union:
str | int(maps to first type) - Pydantic Models: Full validation support
Complete Examples
Example 1: Basic Tool
Example 2: With Pydantic Validation
Example 3: API Wrapper Pattern
Example 4: Data Transformer
Example 5: File Operations
Return Format
Tools should return dictionaries with a consistent format:"success"- Tool executed successfully"error"- Tool execution failed
Registering Tools with Agents
Tools must be registered with agents. There are several ways to do this:Method 1: Direct Registration
Method 2: Auto-Discovery
Tools are automatically discovered fromagents.<agent_name>.tools package:
@tool decorated functions from this package.
Method 3: Using bind_tools
Tool Registry
Tools are managed through aToolRegistry that supports:
- Registration: Add tools with optional aliases
- Lookup: Find tools by name or alias
- Listing: Get all available tools
- Validation: Automatic input validation via Pydantic
Testing Tools
Manual Testing (Python)
Testing via API
Best Practices
- Use Type Hints: Always annotate function parameters for better schema generation
- Descriptive Names: Use clear, action-oriented tool names (
web_searchnotsearch) - Error Handling: Always return consistent error format
- Sensitive Data: Use
trace_maskfor API keys, tokens, passwords - Pydantic for Complex: Use Pydantic models for complex validation needs
- Documentation: Write clear docstrings (used as descriptions if not provided)
Common Patterns
Pattern: API Wrapper
Pattern: Data Transformer
Pattern: File Operations
Next Steps
- Tool Configuration - Complete tool development guide
- Agent Configuration - Agent configuration schema
- MCP Integration - Connect to MCP servers
- API Reference - API endpoints for tool inspection