Skip to main content

Basic Usage

Add functions directly as tools:

Tool Configuration

Use the Tool type for custom descriptions and parameter control. The handler parameter is required and must be the function:

Custom Description

If the function name or docstring doesn’t clearly describe what the tool does, add a custom description. This is the description the LLM sees about the tool:

Parameter Visibility

When a tool has many parameters, reduce tokens and avoid overwhelming the LLM by showing only required parameters:
You can also include or exclude specific parameters to fine-tune what the LLM sees:

Default Parameters

Set default values that are automatically applied when the tool is called. These values are used when not specified by the LLM:
You can also use functions or environment variables as default parameters:

Built-in Tools

Timbal provides built-in tools for common use cases. These tools are ready to use and don’t require implementing handlers.

WebSearch

WebSearch enables agents to search the web.
WebSearch only works with OpenAI and Anthropic models. It’s a specification-only tool that defines the tool schema for the LLM but doesn’t contain executable logic. The actual web search execution is handled by the model provider. Other model providers are not supported.
Available options:
  • allowed_domains: List of domains to restrict searches to
  • blocked_domains: List of domains to exclude (Anthropic only)
  • user_location: Dictionary with location info to localize search results. Must include type field. Common values are "approximate" or "exact", but valid values depend on the provider.

Multiple Instances of the Same Tool

If you need multiple instances of the same built-in tool with different configurations, they will have the same name by default, which causes conflicts. Set unique names and descriptions for each instance:

Agent as a Tool

You can use an Agent as a tool within another Agent, enabling hierarchical agent compositions where specialized agents handle specific tasks. Since Agent instances can be treated as Tool objects, they inherit the same parameter control configurations available to regular tools.
Automatic Nesting: When an agent is used as a tool within another agent (as shown above), it’s automatically nested for proper tracing and context management. However, if you use an agent inside a pre_hook or post_hook, you must manually call .nest(). See Using Agents in Hooks for details.

Commands

Register a command on any tool, agent, or workflow to let users invoke it directly with a / prefix — bypassing the LLM for that turn:
See Commands for argument parsing, nested agents, and workflows.

MCP Servers

Connect any Model Context Protocol server and use its tools like native ones:
The server’s tools are discovered at runtime and offered to the LLM alongside your other tools. See MCP Servers for transports, authentication, result handling, and connection lifecycle.

Dynamic Tools

When tool availability depends on runtime conditions (user role, permissions, input parameters), you need dynamic tool resolution. Instead of exposing all tools to the agent, use Timbal’s ToolSet class to resolve which tools are available at runtime. For example, with a role-based ToolSet:
  • Role: admin → Available tools: delete_user, modify_permissions, view_profile
  • Role: user → Available tools: view_profile
The ToolSet checks the role at runtime and returns only the relevant tools. The agent only has access to the tools returned by the ToolSet for that role. Users without admin role won’t see admin tools, preventing the agent from attempting unauthorized actions. See Dynamic Agents for implementation details and examples.

Summary

  • Automatic Introspection: Function signatures become tool schemas automatically
  • Enhanced Validation: Pydantic-based parameter validation
  • Execution Flexibility: Support for all Python callable types
  • Better Configuration: Fine-grained parameter control
  • Performance: Concurrent execution and optimized patterns
  • Robustness: Improved error handling and tracing
  • Tool Sets: Dynamic tool resolution
  • MCP Servers: Any Model Context Protocol server as a tool source — see MCP Servers
  • Commands: Slash-command shortcuts for direct tool invocation — see Commands
For more advanced patterns, see Dynamic Agents and explore the built-in tools in the Timbal library.