Skip to main content

Overview

Function tools enable LLMs to call external functions, providing them with capabilities beyond text generation.

Creating Tools

Basic Tool

Tool Signature

Using Tools

With LLM

With Agent Workflow

Common Tools

Calculator Tool

Web Search Tool

Database Query Tool

File Reader Tool

Parameter Schemas

Simple Types

Optional Parameters

Enum Parameters

Array Parameters

Nested Objects

Error Handling

Tool Metadata

Access tool metadata:

FunctionTool Class

Best Practices

  1. Clear descriptions: Help LLM understand when to use the tool
  2. Validate inputs: Use Zod schemas for type safety
  3. Handle errors: Return error messages as strings
  4. Keep tools focused: One tool, one purpose
  5. Use enums: Limit choices for categorical parameters
  6. Document parameters: Use .describe() for parameter descriptions
  7. Return serializable data: JSON-compatible return values

Example: Query Engine Tool

See Also