Tools
Let the agent call functions to fetch data and take actions.
A chat model can only produce text. A tool is a function you give the agent so it can do more: fetch the weather, query your database, file a ticket. The result folds back into the conversation.
The loop:
- The model proposes a tool: a name plus arguments.
- Your code runs it. It calls an API, reads a database, or does whatever the tool does.
- The result returns to the conversation, and the agent continues, usually turning it into a final answer.
user: "What's the weather in Tokyo?"
└─ model proposes: get_weather({ city: "Tokyo" })
└─ your code runs it → { tempC: 22, sky: "clear" }
└─ result returns to the agent
└─ agent: "It's 22°C and clear in Tokyo right now."The trust boundary stays in your code. The model only proposes which tool to call and with what arguments. Execution, provider keys, and the tool implementations live on the server and never reach the browser.
Integrate your own tool
A tool is a name, a description, and a JSON Schema for its arguments. The model uses the description and schema to decide when and how to call it, so write them like prompts.
const tools = [
{
type: "function",
name: "get_weather",
description: "Get the current weather for a city.",
parameters: {
type: "object",
properties: {
city: { type: "string", description: "City name, e.g. 'Tokyo'" },
},
required: ["city"],
additionalProperties: false,
},
},
];That declaration is what the model sees. The implementation, the code that actually fetches the weather, stays private and runs only when the agent calls the tool.
Your application runs these functions on the server and returns their results to the agent.