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

AI Agents · Class

ToolNode

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.

How it works

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.

Syntax

new ToolNode(tools)

Parameters

NameTypeDescription
toolsStructuredToolInterface[]Tools that ToolNode can execute; construct the node with an array of tools.

Returns

A runnable result containing ToolMessages, one for each tool call.

Key points

  • ToolNode executes the tools requested by the final AIMessage.
  • Multiple requested tools execute in parallel rather than strictly one after another.
  • The result is a list containing one ToolMessage for every executed call.
  • Use ToolNode in a StateGraph with messages state or in a MessageGraph.

Example: Execute an AI-generated 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.

When to use it

Graph tool execution

Execute model-generated tools inside a StateGraph or MessageGraph.

Parallel tool calls

Run several independent tool calls concurrently.

Standalone execution

Invoke a tool executor directly with an AIMessage or tool-call list.

  • toolsCondition
  • MessagesAnnotation
  • StateGraph
  • AIMessage
  • ToolMessage

Source: ToolNode | LangGraph.js API Reference. Checked 2026-10-15.