Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Agents · Const

Tools

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.

How it works

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.

Syntax

tool(async (args) => result, { name, description, schema })

Parameters

NameTypeDescription
implementationcallable functionThe function that performs the tool's operation and returns its result.
namestringA unique identifier the model uses to refer to the tool.
descriptionstringHuman-readable guidance describing the tool's purpose.
schemainput schemaSchema describing the tool's accepted arguments.

Returns

A callable tool definition with declared metadata, input validation, and an implementation result.

Key points

  • Tools give agents capabilities beyond generating text, including interaction with external systems.
  • Typical tool capabilities include live data retrieval, code execution, and database queries.
  • A tool is implemented as a callable function rather than merely descriptive prompt text.
  • Tools should expose an explicit contract for accepted arguments and returned results.
  • The tool definition is supplied to the chat model so it can produce tool calls.
  • The basic JavaScript creation path imports tool from the LangChain package.

Common mistakes

  • Do not assume every available tool will run: the model selects invocation from the conversation context.
  • The input must conform to the tool's declared schema because the model generates the arguments.

Example: Define a tool

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.

When to use it

Fetch real-time data

An agent needs current information unavailable in its prompt or model knowledge.

Run code or actions

An agent must perform computation or execute an operational function.

Query external databases

An agent needs to read from or interact with an external data store.

Interview questions

QWhat is a tool in an agent system?

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.

QHow do you define a tool in LangChain.js?

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.

QHow do tools participate in an agent loop?

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.

  • agents
  • chat models
  • create_agent
  • middleware
  • headless tools

Source: Tools. Checked 2026-10-15.