Overview
Custom tools allow you to give Smooth any arbitrary Python function that will run in your local environment. This is similar to MCP (Model Context Protocol) but without having to deal with servers or additional infrastructure. Custom tools can be used for virtually anything, including:- Handling OTP scenarios - Retrieve one-time passwords from your email or SMS service
- Human-in-the-loop - Ask questions and get input from a human operator
- Database operations - Add, update, or query data in your local or remote databases
- API integrations - Call external APIs that require credentials or complex logic
- File system operations - Read configuration files, process local data, etc.
- Custom validation - Implement business-specific validation logic
Basic Usage
Use the@client.tool() decorator to register a Python function as a custom tool:
Tool Decorator Parameters
The@client.tool() decorator accepts the following parameters:
The name of the tool that the agent will see and use to call it. Use descriptive, clear names.
A clear description of what the tool does and when to use it. The agent uses this to decide when to call your tool.
A dictionary describing the input parameters for the tool. Each key is a parameter name, and the value is an object with:
type(string): The data type (e.g., “string”, “number”, “boolean”, “object”, “array”)description(string): A clear description of what this parameter is for
The return type of the tool (e.g., “string”, “number”, “boolean”, “object”, “array”)
Error Handling
Custom tools support two types of error handling:ToolCallError (Non-Fatal)
UseToolCallError for expected errors that the agent should handle gracefully. The error message will be sent to the agent, allowing it to retry or adjust its approach.
Fatal Exceptions
Any other exception raised by your code is considered fatal and will immediately interrupt the task execution.Best Practices
- Keep tools simple to use - Each tool should do one thing well
- Use descriptive names - Name tools clearly so the agent knows when to use them
- Handle errors gracefully - Use
ToolCallErrorfor recoverable errors - Validate inputs - Check that inputs are in the expected format before processing
- Return meaningful values - Provide clear, actionable responses that help the agent continue
- Test independently - Test your tool functions separately before using them in tasks