liveBook · Manning

ReAct

As explained in Context Engineering

ReAct is an agent reasoning pattern that alternates between internal reasoning and external actions such as tool invocation.

ReAct (Reasoning and Acting) is an agent pattern that interleaves reasoning with external tool execution. Rather than answering solely from internal knowledge, an agent identifies missing information, acts to obtain it, observes the result, and continues reasoning toward an answer. section 6.3.4

A typical iteration follows a Thought–Action–Observation loop:

  • Thought: assess the current question and decide what information or computation is needed. section 6.3.4
  • Action: emit a tool call. The agent harness intercepts and executes it. section 6.3.4
  • Observation: append the tool result to the context so the model can reason with it, take another action, or answer. section 6.3.4

Calculator trace

For the square root of a city’s population of 144,000, the agent identifies the calculation, calls calculator["sqrt(144000)"], and receives 379.47 as an observation. It then answers approximately 379.47. section 6.3.4

The model does not execute tools by itself: the harness assembles context, exposes and runs tools, maintains execution state, and controls how results return to the model. Each intermediate step consumes context-window space, so growing traces may require compaction. section 6.3.4 section 1.2.3

The same reasoning-action structure can support agentic retrieval. A retriever is wrapped as a tool; the agent decides whether to search, inspects returned passages, and uses them to answer. In a LangChain implementation, create_agent takes a chat model, available tools, and a system prompt; the model must support tool calling. section 3.10.5

Listing 3.6 Tool-calling agent with a local LLM for agentic RAG
from langchain.agents import create_agent
from langchain_ollama import ChatOllama

llm = ChatOllama(model="llama3.1:8b", temperature=0) #1
agent = create_agent( #2
    model=llm,
    tools=tools,
    system_prompt="Answer in one sentence, using only the passages
    returned by the search_documents tool.",
)
question = "Who is the author of the book 'Fake Book: The New Age'?" #3
response = agent.invoke( #4
    {"messages": [{"role": "user", "content": question}]}
)
print(response["messages"][-1].content) #5

Inspect a LangChain agent configured with a local Ollama model and a document-search tool. section 3.10.5

How Context Engineering covers it

How deep it goes
Explains the Thought–Action–Observation cycle and harness handoff, with a calculator trace and a related framework implementation.
Examples
Uses a population square-root calculation and a document-search agent to illustrate tool-mediated answers.
What you can do after
Apply it via LangChain by configuring an agent with a model, retrieval tool, and system prompt.
How it connects
Connects agent loops to tool calling, context management, and agentic retrieval-augmented generation.

Also explained in

Compare how 15 books explain ReAct →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Context Engineering. The section links point to the parts of the book it draws on.