Fetch real-time data
An agent needs current information unavailable in its prompt or model knowledge.
AI Agents · Const
Tools are callable functions that let LangChain agents interact with external systems. A chat model chooses when to call a tool and supplies arguments according to its declared input schema.
Tools are callable functions with declared inputs and outputs that an agent can expose to a chat model. The model chooses whether to invoke one and supplies arguments based on the conversation; an agent then executes the call and feeds the result back into its loop.
tool(async (args) => result, { name, description, schema })| Name | Type | Description |
|---|---|---|
implementation | callable function | The function that performs the tool's operation and returns its result. |
name | string | A unique identifier the model uses to refer to the tool. |
description | string | Human-readable guidance describing the tool's purpose. |
schema | input schema | Schema describing the tool's accepted arguments. |
A callable tool definition with declared metadata, input validation, and an implementation result.
tool from the LangChain package.import { tool } from "langchain";
import * as z from "zod";
const getWeather = tool(
async ({ city }) => `Weather for ${city}: sunny`,
{
name: "get_weather",
description: "Get the weather for a city",
schema: z.object({ city: z.string() }),
},
);This defines a callable tool with a name, description, input schema, and implementation.
An agent needs current information unavailable in its prompt or model knowledge.
An agent must perform computation or execute an operational function.
An agent needs to read from or interact with an external data store.
A tool is a callable function with a defined input and output contract. It gives an agent capabilities such as retrieving data, executing code, querying databases, or taking actions.
Follow-up: How does a model decide which tool to use? It considers the conversation context and generates the arguments for the selected tool.
Define it with the tool function and provide an implementation plus metadata: a name, description, and input schema. The schema describes the arguments that the model may supply.
Follow-up: Why include a description? It helps the model understand the tool's purpose and decide when it is relevant.
Tools are used by agents, which expose them during the model's tool-calling loop. The model can request a call, the tool runs, and its result becomes available for continued agent reasoning.
Follow-up: What other integration can execute tools? In LangGraph workflows, tools can be registered with a graph, while agent execution is commonly handled through an agent abstraction.
agentschat modelscreate_agentmiddlewareheadless tools