LangChain ReAct Agent Loop (Legacy)
LangChain ReAct Agent Loop (Legacy)
Deprecated at
0.1.0, removed at1.0. Defined inlangchain_classic/agents/react/base.py.
Implements the ReAct paper (arXiv 2210.03629): interleave Reasoning (Thought) and Acting (tool calls) in a single text stream.
Loop mechanics
The loop lives in the parent AgentExecutor class, not in ReActDocstoreAgent itself:
┌──────────────────────────────────────────────────────┐
│ Build prompt: [history] + "Thought:" │
│ LLM call → stop at "\nObservation:" │
│ Parse via ReActOutputParser → action + action_input │
│ Execute tool → observation string │
│ Append "Observation: <result>" to context │
│ Repeat until LLM emits "Final Answer: <answer>" │
└──────────────────────────────────────────────────────┘
- LLM prefix:
"Thought:" - Stop sequence:
["\nObservation:"] - Output parser:
ReActOutputParser(parsesAction:/Action Input:/Final Answer:)
Class hierarchy
ReActDocstoreAgent(Agent)
↑ used by
ReActChain(AgentExecutor) ← thin wrapper that wires DocstoreExplorer
Tool constraints
Validated at construction; hard-coded to exactly {"Lookup", "Search"}. The DocstoreExplorer helper bridges these to an abstract Docstore:
| Tool | What it does |
|---|---|
Search |
Retrieves a document; saves it as current document |
Lookup |
Finds next occurrence of a term in the saved document (paginated) |
DocstoreExplorer is stateful: it tracks the current document and lookup cursor across turns.
Comparison
See Source - LangChain Agent Loop for full legacy vs modern comparison table.
Modern replacement: LangChain LangGraph Agent Loop.
Related
- Hermes Agent Loop — another class-based agent loop, multi-provider
- Agent Loop (OpenClaw) — gateway-layer loop above LLM calls