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

AI Agents · Function

tool

LangGraph's ToolNode executes tools within workflows and supports parallel calls, error handling, and state injection. It is useful when an agent needs controlled, graph-based tool execution.

How it works

A tool is a callable capability exposed to an agent. The agent can select it from the configured tool set, provide model-generated arguments, and use its result in the workflow.

Syntax

new ToolNode(tools)

Key points

  • ToolNode runs tools inside a graph and is intended for workflows needing explicit execution control.
  • ToolNode can coordinate multiple tool calls while managing common execution concerns.
  • ToolNode is a foundational component for graph-based agent tool execution.
  • A tool receives the model-produced arguments as its first argument.
  • JavaScript tools can use their second argument to access state and run-scoped context.

Example: Give an agent a tool

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

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

const agent = createReactAgent({
  llm,
  tools: [getWeather],
});

const result = await agent.invoke({
  messages: [{ role: "user", content: "What is the weather in Paris?" }],
});

Defines a structured tool and supplies it to a ReAct agent, which can decide when to call it.

When to use it

Agent tool execution

Run one or more model-selected tools in a LangGraph workflow.

Parallel tool calls

Execute multiple independent tool calls efficiently.

State-aware tools

Expose graph state or run context to JavaScript tools.

  • ToolNode
  • ToolRuntime
  • createReactAgent

Source: Workflows and agents. Checked 2026-10-15.