LangChain ReAct Agent Loop (Legacy)

LangChain ReAct Agent Loop (Legacy)

Deprecated at 0.1.0, removed at 1.0. Defined in langchain_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>"    │
└──────────────────────────────────────────────────────┘

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.