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

AI Agents · Const

Tool Calling

Tool calling lets a LangGraph.js workflow execute tools selected by a model. ToolNode handles dispatch, parallel execution, and returns one ToolMessage per tool call.

How it works

Tool calling in LangGraph.js connects model-generated tool requests to executable tools. ToolNode reads the tool calls in the latest AI message, runs the requested tools, and returns one ToolMessage per call; multiple calls can run in parallel.

Syntax

new ToolNode(tools)

Parameters

NameTypeDescription
toolsStructuredToolInterface[] | Record<string, StructuredToolInterface>The tools that ToolNode may execute; supplied as a tool array or a mapping of tool names to tools.

Returns

A Runnable node result containing ToolMessages, one for each executed tool call.

Key points

  • ToolNode dispatches the tool requests contained in the most recent AI message.
  • Several tool calls in one message can execute concurrently.
  • Execution results are returned as ToolMessages, with a separate message for every call.

Common mistakes

  • The input graph state must provide messages in the form expected by ToolNode; it supports StateGraph message state or MessageGraph.

Example: Execute a model tool call

import { ToolNode } from "@langchain/langgraph/prebuilt";
import { tool } from "@langchain/core/tools";
import { z } from "zod";

const getWeather = tool(
  async ({ city }) => `Sunny in ${city}`,
  {
    name: "get_weather",
    description: "Get the weather for a city",
    schema: z.object({ city: z.string() }),
  },
);

const toolNode = new ToolNode([getWeather]);
const result = await toolNode.invoke({
  messages: [{
    role: "assistant",
    content: "",
    tool_calls: [{
      name: "get_weather",
      args: { city: "Paris" },
      id: "call-1",
      type: "tool_call",
    }],
  }],
});
console.log(result.messages[0].content);

ToolNode receives a message containing model-generated tool calls, executes the matching tools, and returns ToolMessages.

When to use it

Execute external actions

Run model-selected APIs, database queries, or application functions inside a graph.

Parallel tool execution

Let several independent model requests finish concurrently.

Build agent workflows

Use a ready-made execution node instead of implementing tool dispatch and result messages.

Interview questions

QWhat does ToolNode do?

ToolNode is a prebuilt LangGraph node that executes the tools requested in the latest AI message. It returns ToolMessages corresponding to the executed calls.

Follow-up: How are concurrent calls handled? Multiple requested tool calls are executed in parallel, producing one ToolMessage for each call.

QHow is ToolNode configured and invoked?

Construct ToolNode with the tools it may execute, then invoke it with graph state containing the relevant messages. The node matches each model tool call to the configured tool.

Follow-up: What input shape is required? The state must expose a messages collection containing an AI message with tool_calls.

QHow do tools access arguments and graph context?

A tool receives the arguments generated by the model as its first argument. In JavaScript, graph-side state and run-scoped context can be accessed through the tool's second ToolRuntime argument.

Follow-up: What is the access boundary? A tool can access only state values passed to ToolNode, so required state must be available there.

  • ToolNode
  • ToolMessage
  • StateGraph
  • MessageGraph
  • ToolRuntime
  • createReactAgent

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