LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Browser
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
  • Tools
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Compat
  • Event
  • Llms
  • Openai Completions Stream
  • Profile
  • Stream
  • Structured Output
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Testing
  • Tools
  • Base
  • Console
  • Log Stream
  • Run Collector
  • Tracer Langchain
  • Stream
  • Async Caller
  • Chunk Array
  • Context
  • Env
  • Event Source Parse
  • Format
  • Function Calling
  • Gateway
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Standard Schema
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Uuid
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangChain
BrowserUniversalHubNodeLoadSerializableEncoder BackedFile SystemIn MemoryTools
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsCompatEventLlmsOpenai Completions StreamProfileStreamStructured OutputLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryTestingToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingGatewayHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesUuidVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScriptlangchainbrowserReactAgent
Interfaceā—Since v1.2

ReactAgent

ReactAgent is a production-ready ReAct (Reasoning + Acting) agent that combines language models with tools and middleware.

The agent is parameterized by a single type bag Types that encapsulates all type information:

Copy
interface ReactAgent

Example

Copy
// Using the type bag pattern
type MyTypes = AgentTypeConfig<
  { name: string },  // Response
  typeof myState,    // State
  typeof myContext,  // Context
  typeof middleware, // Middleware
  typeof tools       // Tools
>;

const agent: ReactAgent<MyTypes> = createAgent({ ... });

Properties

property
options: CreateAgentParams<Types["Response"], Types["State"], Types["Context"]>
property
checkpointer: boolean | BaseCheckpointSaver<number> | undefined
property
graph: AgentGraph<Types>
property
store: BaseStore | undefined

Methods

method
drawMermaid→ Promise<string>

Draw the graph as a Mermaid string.

method
drawMermaidPng→ Promise<Uint8Array<ArrayBuffer>>

Visualize the graph as a PNG image.

method
invoke→ Promise<MergedAgentState<Types>>

Executes the agent with the given state and returns the final state after all processing.

This method runs the agent's entire workflow synchronously, including:

  • Processing the input messages through any configured middleware
  • Calling the language model to generate responses
  • Executing any tool calls made by the model
  • Running all middleware hooks (beforeModel, afterModel, etc.)
method
stream→ Promise<IterableReadableStream<StreamOutputMap<TStreamMode, TSubgraphs, MergedAgentState<Types>, MergedAgentState<Types>, string, unknown, unknown, TEncoding>>>

Executes the agent with streaming, returning an async iterable of state updates as they occur.

This method runs the agent's workflow similar to invoke, but instead of waiting for completion, it streams high-level state updates in real-time. This allows you to:

  • Display intermediate results to users as they're generated
  • Monitor the agent's progress through each step
  • React to state changes as nodes complete

For more granular event-level streaming (like individual LLM tokens), use streamEvents instead.

method
streamEvents→ Promise<AgentRunStream<MergedAgentState<Types>, Types["Tools"], InferStreamExtensions<Types["StreamTransformers"]>>>

Executes the agent with the v3 streaming interface, returning an AgentRunStream that provides ergonomic, typed projections for messages, tool calls, and middleware events — without requiring knowledge of Pregel channels, stream modes, or namespace routing.

Pass version: "v3" to opt into this projection-oriented stream. Omitting version preserves the legacy internal LangGraph event-stream behavior for compatibility with LangGraph Platform integrations.

This v3 stream is experimental and its API may change in future releases. It will become the default in a future major release.

method
withConfig→ ReactAgent<Types>

Creates a new ReactAgent with the given config merged into the existing config. Follows the same pattern as LangGraph's Pregel.withConfig().

The merged config is applied as a default that gets merged with any config passed at invocation time (invoke/stream). Invocation-time config takes precedence.

View source on GitHub