Graph tool execution
Execute model-generated tools inside a StateGraph or MessageGraph.
AI Agents · Class
ToolNode is a prebuilt LangGraph.js node that executes tool calls from an AIMessage. It supports graph message state and parallel execution, returning one ToolMessage per call.
ToolNode is a prebuilt LangGraph.js runnable that receives an AIMessage with tool calls, looks up the matching tools, executes requested calls—concurrently when there are several—and returns one ToolMessage per call. It accepts graph state containing messages, a message list directly, or tool-call objects, and can be placed in a StateGraph or used independently.
new ToolNode(tools)| Name | Type | Description |
|---|---|---|
tools | StructuredToolInterface[] | Tools that ToolNode can execute; construct the node with an array of tools. |
A runnable result containing ToolMessages, one for each tool call.
import { AIMessage } from "@langchain/core/messages";
import { tool } from "@langchain/core/tools";
import { ToolNode } from "@langchain/langgraph/prebuilt";
const getWeather = tool(
async ({ location }: { location: string }) => `Weather in ${location}: sunny`,
{
name: "get_weather",
description: "Get the weather for a location",
schema: undefined as any
}
);
const toolNode = new ToolNode([getWeather]);
const message = new AIMessage({
content: "",
tool_calls: [{ name: "get_weather", args: { location: "sf" }, id: "call-1", type: "tool_call" }]
});
const result = await toolNode.invoke({ messages: [message] });
console.log(result);
Creates a ToolNode, supplies an AIMessage containing a tool call, and invokes the node to produce the corresponding ToolMessage.
Execute model-generated tools inside a StateGraph or MessageGraph.
Run several independent tool calls concurrently.
Invoke a tool executor directly with an AIMessage or tool-call list.
toolsConditionMessagesAnnotationStateGraphAIMessageToolMessage