Expand description
The prebuilt ReAct agent (LangGraph create_react_agent parity).
create_react_agent assembles the classic reasoning-acting loop as a
two-node cyclic graph over a single messages channel
(Reducer::AddMessages):
┌──────────────────────────────────────────┐
│ │
▼ │
[agent] ── last message has tool_calls? ──► [tools]
│ │
└─ no tool_calls ──► End ◄── static edge ──┘agent— serializes themessageschannel intoChatMessages, callsChatModel::chatwith the registry’s OpenAI-format tool schemas, and appends the assistant message (final answer or tool-call request) back ontomessages.tools— takes thetool_callsof the last assistant message, dispatches them in parallel throughToolExecutor::execute_batch, and appends onerole: "tool"message per call.- Routing — a conditional edge on
agentroutes totoolswhen the last message carries tool calls, otherwise toRoute::End; a static edge loopstools → agentso the model observes the tool results.
The caller drives the returned Graph with a crate::state::StateSpec
declaring messages with Reducer::AddMessages and an initial state
seeding the conversation (see examples/react_agent.rs).
Four flavors exist: create_react_agent (the agent node calls
ChatModel::chat; no crate::executor::GraphEvent::Token events),
create_react_agent_streaming (the agent node calls
ChatModel::chat_stream and forwards deltas as
crate::executor::GraphEvent::Tokens into the run’s event channel),
and the Flight Recorder pair create_react_agent_with_recording /
create_react_agent_replaying.
§Flight Recorder
create_react_agent_with_recording wires the run’s Journal into
both nodes: every model call is journaled through
crate::replay::RecordingChatModel and every tool call through
crate::replay::RecordingTool, in the canonical
crate::replay::model_call_request / crate::replay::tool_call_request
payload shapes, parented per iteration to the invocation’s node-input
event (the executor hands its id over via
crate::journal::PARENT_EVENT_KEY). Attach the same journal to the run
with crate::executor::RunConfig::with_journal.
create_react_agent_replaying is the mirror image for exact replay:
the same topology with crate::replay::ReplayingChatModel /
crate::replay::ReplayingTool answering from the recorded journal —
zero outbound calls, so the wrapped model and tools may be
panic-on-call sentinels. See examples/react_record_replay.rs for the
full record → replay loop.
Constants§
- AGENT_
NODE - The name of the model-calling node in the compiled graph.
- MESSAGES_
CHANNEL - The state channel the ReAct loop reads from and appends to. Declare it
with
Reducer::AddMessagesin the run’scrate::state::StateSpec. - TOOLS_
NODE - The name of the tool-dispatch node in the compiled graph.
Functions§
- create_
react_ agent - Build a prebuilt ReAct agent graph over
modelandtools. - create_
react_ agent_ replaying - Build a prebuilt ReAct agent graph that answers every model and tool call from a recorded journal instead of executing it (exact replay).
- create_
react_ agent_ streaming - Build a prebuilt ReAct agent graph whose
agentnode streams token deltas asGraphEvent::Tokens throughtoken_tx(ChatModel::chat_streamunder the hood; LangGraph’smessagesstream mode). - create_
react_ agent_ with_ recording - Build a prebuilt ReAct agent graph that journals every model and tool
call into
journal(Flight Recorder, R0.5).