LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
LangGraph SDK
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Server
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
  • Store
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemote
LangGraph SDK
ClientAuthReactLoggingReact UiServer
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
Store
LangGraph Checkpoint Redis
ShallowStore
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
Cli
LangGraph API
LangGraph CLI
LangGraph CUA
Utils
LangGraph Supervisor
LangGraph Swarm
Language
Theme
JavaScript@langchain/langgraphprebuiltcreateReactAgent
Function●Since v0.3Deprecated

createReactAgent

Copy
createReactAgent<
  A extends InteropZodObject | AnyAnnotationRoot = AnnotationRoot<__type>,
  StructuredResponseFormat extends Record<string, any> = Record<string, any>,
  C extends InteropZodObject | AnyAnnotationRoot = AnyAnnotationRoot
>(
  params: CreateReactAgentParams<A, StructuredResponseFormat, C>
): CompiledStateGraph<ToAnnotationRoot<A>["State"], ToAnnotationRoot<A>["Update"], any, __type  ToAnnotationRoot<A>["spec"], __type  ToAnnotationRoot<A>["spec"]>

Used in Docs

  • Test a ReAct agent with Pytest/Vitest and LangSmith
  • Composio integration
  • LangChain v1 migration guide
  • LangGraph v1 migration guide

Parameters

NameTypeDescription
params*CreateReactAgentParams<A, StructuredResponseFormat, C>

Example

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

const model = new ChatOpenAI({
  model: "gpt-4o",
});

const getWeather = tool((input) => {
  if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
    return "It's 60 degrees and foggy.";
  } else {
    return "It's 90 degrees and sunny.";
  }
}, {
  name: "get_weather",
  description: "Call to get the current weather.",
  schema: z.object({
    location: z.string().describe("Location to get the weather for."),
  })
})

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

const inputs = {
  messages: [{ role: "user", content: "what is the weather in SF?" }],
};

const stream = await agent.stream(inputs, { streamMode: "values" });

for await (const { messages } of stream) {
  console.log(messages);
}
// Returns the messages in the state at each step of execution
View source on GitHub