Hirestack
Hirestack
Chapter 12

AI Agents · ReAct loop and core patterns

📖 3 min read · 8 sections · May 2026

Why this matters

An LLM that can call tools is an LLM that can do work in the real world: search, write code, send emails, hit APIs. The pattern that makes this reliable is called ReAct (Reason → Act → Observe). It's the foundation of every agent framework, and you should understand it before reaching for one.

The ReAct loop

flowchart LR
    Start([Start]) --> R[Reason
What do I do next?] R --> A[Act
Call a tool] A --> O[Observe
Read result] O --> D{Done?} D -->|no| R D -->|yes| End([Answer])

The model produces a reasoning step ("I need to find the user's location to answer the weather question"), then a tool call (get_user_location), observes the result, then reasons again. Loop until the model decides it has enough to answer.

Failure modes of ReAct agents

Memory: short-term vs long-term

Multi-agent patterns

PatternSetupUse case
Supervisor / workerOne agent plans + delegates; specialised workers executeComplex tasks with distinct sub-skills (research, write, code)
Parallel workersSpawn N agents in parallel, merge resultsMap-reduce style work (analyse 100 docs)
Critic / reviewerGenerator produces; critic reviews and sends back fixesQuality-critical generations (code review, content)
DebateMultiple agents argue different positions; final synthesisReducing single-model bias; not yet widely deployed

Frameworks: when to reach for one

You don't need a framework for simple ReAct loops — ~50 lines of Python do it. Reach for one when:

FrameworkStrengthsBest for
LangGraphState machine for agents; checkpointing; human-in-the-loop primitivesProduction agents with clear flows
CrewAICrew + roles abstraction; readable for product teamsMulti-agent collaboration patterns
AutoGenMicrosoft; conversation-driven multi-agentResearch and complex agent debates
smolagentsHugging Face; minimal, code-firstWhen you want to understand every line

When NOT to use agents

Agents are slow and expensive (one task = many LLM calls). If your problem is single-shot — "extract these fields from this PDF", "summarise this article" — a single prompt is faster, cheaper, more reliable. Agents are for tasks that require multi-step reasoning with tools, not for tasks where you'd like fancier output.

War story: team replaced a simple "extract sentiment" call with a 3-agent setup (researcher / analyser / scorer). Latency went from 1s to 8s. Cost went up 6×. Accuracy moved 1%. Reverted to the single call. Agents are a tool, not a default.
Q: When does an agent beat a single carefully-crafted prompt?
When the task genuinely requires real-world feedback to make progress — e.g., "search the web and summarise findings" (you can't pre-bake the search results in the prompt), "fix the failing test" (you need to run code, see the failure, iterate), "book me a flight" (multiple API calls with branching). For pure transformation tasks where you have all the input upfront, prompts win.
Cross-Q: What's the upper limit on agent steps before reliability drops? A: Empirically, 10-15 with current SOTA models. Past that, error compounds: each step has, say, 95% chance of being right; 15 steps gives you 0.95¹⁵ ≈ 46% end-to-end. Design for short loops; break complex tasks into multiple shorter agent runs.

Takeaway

Agents are powerful for tasks that need real-world interaction and branching reasoning. They're overkill for single-shot work. Frameworks help when you have multi-agent state + checkpointing needs; for simple ReAct, a 50-line loop is clearer than any framework. Cap your iterations, return errors as data, and treat tool descriptions as your most important documentation.