Quick Start - Simple Function
The easiest way is to pass a function directly toadd_tool():
- Uses the function name as the tool name
- Uses the docstring as the description
- Infers parameters from type hints
- Determines required vs optional from default values
Quick Start - Tool Class
For more control, use theTool class:
When to Use Each Approach
| Approach | Best For |
|---|---|
| Simple Function | Most use cases, rapid development |
| Tool Class | Custom descriptions, enum values, complex schemas |
Simple Function Requirements
For the ADK to auto-infer tool parameters:Supported Types
| Python Type | Inferred JSON Type |
|---|---|
str | "string" |
int | "integer" |
float | "number" |
bool | "boolean" |
list | "array" |
dict | "object" |
Tool Class
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
name | str | Yes | Unique tool name (no spaces) |
description | str | Yes | Clear description for LLM |
parameters | dict | Yes | JSON Schema defining inputs |
function | Callable | No | Python function to execute |
Defining Parameters
Parameters use JSON Schema format:Basic Schema
Supported Types
Complete Example
Auto-Infer Parameters
Generate parameters automatically from function signatures:Type Mapping
| Python Type | JSON Schema Type |
|---|---|
str | "string" |
int | "integer" |
float | "number" |
bool | "boolean" |
list | "array" |
dict | "object" |
Optional[T] | Type of T |