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:
interface ReactAgent// 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({ ... });Draw the graph as a Mermaid string.
Visualize the graph as a PNG image.
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:
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:
For more granular event-level streaming (like individual LLM tokens), use streamEvents instead.
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.
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.