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

AI Agents · Function

createReactAgent

Creates a prebuilt ReAct agent graph from a language model and tools. The agent can invoke tools during a message-driven execution loop before returning a response.

How it works

createReactAgent constructs a prebuilt agent graph from a language model and tools. The graph repeatedly lets the model choose whether to call a tool, executes selected tools, and continues until the model produces a final response.

Syntax

createReactAgent({ llm: model, tools: [tool] })

Parameters

NameTypeDescription
llmBaseChatModel or compatible language-model runnableLanguage model used to reason and select whether to call tools.
toolsArray of toolsTools available to the agent during its execution loop.

Returns

An agent graph runnable that accepts message state and produces the resulting agent state.

Key points

  • The documented JavaScript example imports createReactAgent and tool from the langchain package.
  • A chat model instance is created and supplied as the agent's language model.
  • The returned agent is executed asynchronously through its invoke method.

Common mistakes

  • The current documentation presents this as a prebuilt ReAct agent rather than a general-purpose graph constructor.
  • The function requires its configuration to be passed as an options object.

Example: Create a tool-using ReAct agent

import { createReactAgent, tool } from "langchain";
import { ChatAnthropic } from "@langchain/anthropic";
import { z } from "zod";

const getWeather = tool(
  async ({ location }) => `Weather for ${location}: sunny`,
  { name: "get_weather", schema: z.object({ location: z.string() }) }
);

const agent = createReactAgent({
  llm: new ChatAnthropic({ model: "claude-3-7-sonnet-latest" }),
  tools: [getWeather],
});

const result = await agent.invoke({
  messages: [{ role: "user", content: "What is the weather in SF?" }],
});
console.log(result.messages.at(-1)?.content);

Creates an agent with a chat model and weather tool, then invokes it with a user message.

When to use it

Tool-augmented chat

A conversational assistant needs to answer questions using external functions such as weather lookup.

Conditional tool use

A model must decide dynamically whether a supplied capability is needed for each request.

Prebuilt agent orchestration

An application wants a ready-made agent loop without manually wiring model and tool nodes.

Interview questions

QWhat does createReactAgent do?

It creates a ReAct agent graph that combines a language model with tools. The returned graph can be invoked with a messages state, and the model may use the supplied tools before answering.

Follow-up: How would you add another capability? Pass another tool in the tools array, ensuring it has a callable implementation and schema suitable for model tool selection.

QWhat are the main configuration options?

The llm option supplies the chat model responsible for deciding whether to respond or call a tool. The tools option supplies the functions available to that model.

Follow-up: What happens if no tool is appropriate? The model can finish with a direct response, so tool execution is not required for every invocation.

QHow is the resulting agent run?

Invoke the returned agent with an object whose messages field contains the conversation, such as a user role and content. The result contains the agent's resulting message state.

Follow-up: How can a conversation continue? Preserve the returned messages and provide them in a later invocation together with the next user message.

  • tool
  • ChatAnthropic
  • agent.invoke
  • messages

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