Define custom functions that AI models can call dynamically. Tool nodes enable function calling, structured interactions with external systems, and advanced AI agent capabilities.
The Tool Node is a powerful component that defines custom functions AI models can invoke during execution. Instead of returning unstructured text, AI models can call your tools to perform specific actions—query databases, call APIs, perform calculations, or interact with external services.
Tool nodes work with AI providers that support function calling:
You define what the function does and how to call it. The AI model decides when to call it based on the user's prompt and conversation context.
string"get_weather", "searchDatabase"string"Get current weather for a city. Use when user asks about weather conditions."Record<string, any>stringcity, temperature_unit instead of arg1, paramprocess.env for API keys and secrets, never hardcode themexport type ToolNodeData = {
// Configuration
name: string // Function name (required)
description: string // What the function does (required)
parameters?: Record<string, any> // JSON Schema for parameters
code?: string // JavaScript function body
// Execution state (managed by system)
status?: "idle" | "running" | "completed" | "error"
output?: any
error?: string
}Tool Configuration
get_weatherParameters Schema
{
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "The city name (e.g., 'San Francisco', 'London')"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Temperature unit"
}
},
"required": ["city"]
}Function Code
async function get_weather({ city, unit = "celsius" }) {
const apiKey = process.env.WEATHER_API_KEY
const url = `https://api.openweathermap.org/data/2.5/weather?q=${city}&units=${
unit === "celsius" ? "metric" : "imperial"
}&appid=${apiKey}`
const response = await fetch(url)
const data = await response.json()
return {
city: data.name,
temperature: data.main.temp,
conditions: data.weather[0].description,
unit: unit
}
}get_weather({ city: "Tokyo", unit: "celsius" }) and uses the result to respond: "The current weather in Tokyo is 22°C with clear skies."Tool Configuration
search_databaseParameters Schema
{
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "Search query (name, department, or project)"
},
"type": {
"type": "string",
"enum": ["employee", "project"],
"description": "Type of search"
}
},
"required": ["query", "type"]
}Function Code
async function search_database({ query, type }) {
const db = await getDatabase()
if (type === "employee") {
const results = await db.employees.find({
$or: [
{ name: { $regex: query, $options: "i" } },
{ department: { $regex: query, $options: "i" } }
]
}).limit(5)
return results.map(emp => ({
name: emp.name,
department: emp.department,
role: emp.role
}))
} else {
const results = await db.projects.find({
name: { $regex: query, $options: "i" }
}).limit(5)
return results.map(proj => ({
name: proj.name,
status: proj.status,
team_size: proj.team.length
}))
}
}Tool Configuration
calculate_returnsFunction Code
function calculate_returns({ principal, rate, years }) {
if (principal <= 0 || rate < 0 || years <= 0) {
return { error: "Invalid input: all values must be positive numbers" }
}
const finalAmount = principal * Math.pow(1 + rate, years)
const totalGain = finalAmount - principal
const percentageGain = (totalGain / principal) * 100
return {
initial: principal,
final: finalAmount.toFixed(2),
gain: totalGain.toFixed(2),
percentage: percentageGain.toFixed(2),
years: years
}
}You can provide multiple Tool nodes to a single AI model. The AI will choose which tool(s) to call based on the user's request.
Example Multi-Tool Scenario
User: "What's the weather in New York and how should I invest $10,000 at 5% for 10 years?"
The AI will call both tools:
get_weather({ city: "New York" })calculate_returns({ principal: 10000, rate: 0.05, years: 10 })Then formulates a response using both results.
Tool node must have a valid function name
Tool node must have a description to help AI decide when to use it
Function name must be a valid JavaScript identifier (alphanumeric + underscores only)
If provided, parameters must be valid JSON Schema format
Tool has no implementation. AI can call it but it won't execute anything
Description is too short or unclear. AI may not know when to use this tool
Possible Causes:
Solutions:
Possible Causes:
Solutions:
Possible Causes:
Solutions:
enum for parameters with fixed optionsrequired in schemaPossible Causes:
Solutions:
console.log(result){ error: true, message: "..." }Continue learning about other node types and advanced workflow patterns: