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

AI Agents · Const

Parallel tool calls

ToolNode executes the tools requested by the latest AIMessage. Multiple requested tools run in parallel, and the node returns one ToolMessage for each call.

How it works

Parallel tool calls are handled by ToolNode: it reads the tool calls in the latest AIMessage, runs the requested tools concurrently, and returns a separate ToolMessage for each call. This is useful in a StateGraph or MessageGraph when independent operations can be performed during the same model step.

Syntax

new ToolNode(tools)

Returns

A list of ToolMessages, one for each tool call.

Key points

  • ToolNode consumes tool requests from the latest AIMessage rather than selecting tools independently.
  • The node supports both state-based graphs and message-only graphs.
  • Several calls in one AIMessage are executed concurrently.
  • Results are returned as one ToolMessage per executed call.

Common mistakes

  • Calls execute concurrently, so tools that mutate shared state or depend on one another should not be placed in the same batch without coordination.
  • Do not expect a single scalar result: consume the returned list and associate each ToolMessage with its corresponding call.

Example: Execute parallel tool calls

import { ToolNode } from "@langchain/langgraph/prebuilt";
import { AIMessage, ToolMessage } from "@langchain/core/messages";

const tools = [
  async function getWeather({ city }: { city: string }) {
    return `${city}: sunny`;
  },
  async function getTime({ city }: { city: string }) {
    return `${city}: 12:00`;
  },
];

const toolNode = new ToolNode(tools);
const message = new AIMessage({
  content: "",
  tool_calls: [
    { name: "getWeather", args: { city: "Boston" }, id: "1", type: "tool_call" },
    { name: "getTime", args: { city: "Tokyo" }, id: "2", type: "tool_call" },
  ],
});

const result = await toolNode.invoke({ messages: [message] });
console.log(result.messages.map((m: ToolMessage) => m.content));

ToolNode receives one AI message containing multiple tool calls and executes those calls in parallel, returning one ToolMessage for each result.

When to use it

Run independent operations concurrently

A model requests weather, calendar, and database operations in one response.

Add prebuilt tool execution

A graph needs standard tool execution without implementing dispatch logic.

Connect tool calls to either supported graph style

A workflow uses message-based state or a messages field in graph state.

Interview questions

QWhat does ToolNode do with parallel tool calls?

ToolNode is a prebuilt node that executes the tools requested in the most recent AIMessage. When that message contains several calls, ToolNode runs them in parallel and returns one ToolMessage per call.

Follow-up: How would you represent the input? Pass a graph state containing a messages key with the AIMessage, or use the corresponding MessageGraph input.

QWhat is the output shape when several tools are called?

The node returns a list of ToolMessages. Each message contains the result of one requested tool call, allowing the graph or model to process all completed results.

Follow-up: What must downstream code avoid assuming? It must not treat the result as one tool output; it should iterate over the returned messages.

QWhich graph styles support ToolNode?

ToolNode can be used in either a StateGraph with a messages key or in a MessageGraph. The model first produces an AIMessage containing tool calls, and the node executes those calls.

Follow-up: When is this pattern most useful? When independent tools can answer different parts of a request during one model step.

  • ToolNode
  • AIMessage
  • ToolMessage
  • StateGraph
  • MessageGraph

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