Previous in LangChain
← Getting Started with LangChain: Understanding Agents, Models, and ToolsBuilding Your First LangChain Tool in Node.js
June 1, 2026
Building Your First LangChain Tool in Node.js
Introduction
Large language models are powerful, but they cannot access live information on their own.
This is where tools become important.
Tools allow agents to retrieve data, call APIs, query databases, and perform actions on behalf of users.
Creating a Dummy Weather Tool
Let's create a simple weather tool that always returns the same response.
import { createAgent, tool } from 'langchain';
import * as z from 'zod';
const getWeatherTool = tool(
(input) => `It's always sunny in ${input.city}!`,
{
name: 'get_weather',
description: 'Get the weather for a given city',
schema: z.object({
city: z.string().describe(
'The city to get the weather for'
)
})
}
);
Understanding the Tool Definition
A LangChain tool consists of three parts:
1. Function
The actual code that runs.
2. Metadata
The tool name and description help the model decide when to use the tool.
3. Schema
The schema tells the model what inputs are required.
Registering the Tool
const agent = createAgent({
model: 'gpt-5.4',
tools: [getWeatherTool]
});
Invoking the Agent
await agent.invoke({
messages: [
{
role: 'human',
content: 'What is the weather in San Francisco?'
}
]
});
Behind the Scenes
Loading diagram…
The model decides that weather information is needed and requests execution of the weather tool.
The agent executes the tool and returns the result back to the model.
Key Takeaways
- Tools extend the capabilities of LLMs.
- Zod schemas define tool inputs.
- Descriptions help the model choose the right tool.
- Agents automatically orchestrate tool execution.