Overview › 7Orchestration › d.Shaping the loop › iii.
ReAct loop
Control flow General
Run the agent as a loop: the model reasons, calls a tool, reads the result and picks the next step, until it answers or hits a cap. The loop is the common default for tasks that need several dependent tool calls; the 2022 text template (Thought/Action/Observation lines in a few-shot prompt) is not. On current models, use native tool calling, carry the model's reasoning across tool calls, bound the whole feedback path, and keep the per-step preamble small: with the model fixed, the harness around the loop moved cost per task by up to 3x and pass rate by less than the noise.
Tier 4 because it changes the control loop.
When it applies
- In the code: A loop that alternates model call and tool dispatch, feeds results back, and has a max-iteration guard; check that the guard bounds the whole feedback path (retries, handoffs), not just the outer loop.
- In traces: Thought before each action; observations used in the next thought; loops that ignore results.
- In eval results: Success on tool-use tasks; steps per task; tool error rate.
- With a judge: Do thoughts inform the next action or are they boilerplate.
- With probes: Tasks needing two to four dependent tool calls.
How
- Use the provider's native tool calling, not a text Thought/Action/Observation template.
- Loop: call the model, run every tool call it returns, append each result to the history (errors included, as observations), and call again; stop on a final answer or an explicit finish tool.
- Let the model reason before each action (interleaved or adaptive thinking; a think tool on models without it), and pass its reasoning back unchanged across tool calls.
- Cap steps, cost and wall time on the whole feedback path, retries and handoffs included; count a cap hit as a failure (7.b.iii sizes the caps, 7.b.i catches stalls).
- Keep the per-step preamble (system prompt and tool schemas) small; it is re-sent every step.
- Paired eval against the current design (one call or a fixed workflow), per model: success, steps, cost per task, cap-hit rate.
How to measure it
- experiment (tier 4): paired eval of the loop against the current design, per model: success, steps, cost per task, cap-hit rate; use the full task pool, since 45 tasks catch a 12.9-point gap only half the time
- monitor: steps per task, cap-hit rate, tool error rate, cost per task
To compare the change against your agent's current version, with the same cases and enough repeats to see past run-to-run noise, use aot-evals.
Expected impact
- Quality: improves, large: tasks that need several dependent tool calls: text-to-SQL 45.9 to 72.2 on EHR-SQL over a single shot, but 78.5 to 79.1 on BIRD (Lu, Aug 2026); ALFWorld 71 against 45 for acting without reasoning (Yao, 2022)
- Cost: degrades, medium: one model call per step, each re-sending the preamble and history; with the model fixed, cost per task differed by up to 3x across harnesses (Liu and Han, Oct 2026)
- Performance: degrades, medium: serial round trips, one per step
- Security: mixed, medium (unmeasured): Autonomous tool actions need scoping.
- Governance: mixed, medium (unmeasured): Every action must be logged to be auditable.
- Brand: none (unmeasured)
Caveats
The 2022 gains came from few-shot text prompting on PaLM-540B, and ReAct alone trailed chain-of-thought on HotpotQA; a 2024 study found the interleaved reasoning in that template mattered little next to the choice of examples. Whether reasoning between calls helps depends on the model and harness: switching thinking off cost one harness 11 points and moved two others by less than the noise. Every tool result feeds the next action, so untrusted content can steer the loop: contain it (10.c.i) or commit to a plan before reading it (6.c.ii). Harness comparisons need large task pools.
Evidence
Evidence comes from: Computer use, Web research, Tool use, Conversation, Data analysis, Code generation, Retrieval, Planning.
-
Lists this practice in its agent-optimization pattern library (Prompting Strategies group)Not measured
Names the practice as a known agent optimization; reports no measured effect for it.
Scale AI, "VeRO: A Harness for Agents to Optimize Agents" (ICML 2026) · Feb 2026 · paper Table 6; pattern library file master-agent-optimization-cookbook.md
-
Interleave reasoning traces with actions, against acting only, chain-of-thought, and imitation or RL agents
ALFWorld success 71 (best of 6) against 45 for acting only and 37 for BUTLER; WebShop success 40.0 against 30.1 (acting only), 29.1 (IL) and 28.7 (IL+RL). HotpotQA EM 27.4 against 29.4 for chain-of-thought, 35.1 when ReAct falls back to CoT-SC; FEVER 60.9 against 56.3 for chain-of-thought.
Yao et al., "ReAct: Synergizing Reasoning and Acting in Language Models" · Oct 2022Older evidence · Abstract; Table 1, Table 3, Table 4
-
Vary ReAct's few-shot prompt on ALFWorld: move the reasoning out of the loop, change its content, change the examplesAgainst
Reasoning given once before acting, instead of interleaved, beat base ReAct for GPT-3.5-Instruct (44.7 to 61.9) and GPT-4 (23.3 to 43.3), not for Claude-Opus (56.6 to 50). Performance is "minimally influenced by the 'interleaving reasoning trace with action execution'" and driven by how similar the examples are to the query.
Verma, Bhambri, Kambhampati, "On the Brittle Foundations of ReAct Prompting for Agentic Large Language Models" · May 2024Older evidence · Abstract; Table 1
-
Native function calling against text-formatted ReAct and Act agentsMixed
"natively supported function calling consistently outperforms text-formatted agent methods with the state-of-the-art models. For text-formatted agent methods, adding reasoning traces still consistently helps." A "think" function added to function-calling agents "did not boost performance".
Yao, Shinn, Razavi, Narasimhan, "τ-bench: A Benchmark for Tool-Agent-User Interaction in Real-World Domains" · Jun 2024Older evidence · Method comparison; Figure 3
-
ReAct against plan-then-execute and other agent methods on everyday app tasksMixed
Task goal completion, normal / challenge test sets: GPT-4o ReAct 48.8 / 30.2 against plan-then-execute 44.6 / 19.7; GPT-4-Turbo ReAct 26.8 / 17.5 against 32.7 / 11.0. GPT-4o cost about $0.7 per example with ReAct and $1.33 with plan-then-execute.
Trivedi et al., "AppWorld: A Controllable World of Apps and People for Benchmarking Interactive Coding Agents" · Jul 2024Older evidence · Table 3; App. E.8
-
Give the model a think tool to reason between tool calls
τ-bench airline pass^1 0.570 with the think tool and an optimized prompt against 0.370 baseline; retail 0.812 against 0.783; SWE-bench +1.6% on average. A Dec 2025 update recommends extended thinking "instead of a dedicated think tool in most cases".
Anthropic, The "think" tool: Enabling Claude to stop and think in complex tool use situations · Mar 2025Older evidence · Evaluation sections; Dec 15, 2025 update note
-
Pass the model's previous reasoning items back across tool calls (Responses API) instead of dropping them
"Tau-Bench Retail score increases from 73.9% to 78.2% just by switching to the Responses API and including previous_response_id to pass back previous reasoning items into subsequent requests."
OpenAI, "GPT-5 prompting guide" · Aug 2025Older evidence · Responses API paragraph
-
Add a ReAct loop (SQL actions with execution feedback) to a zero-shot single-shot baseline, then a typed DSL of 15 operations
Single shot to loop: EHR-SQL 45.9 to 72.2, BIRD 78.5 to 79.1; with the typed DSL, 73.9 and 84.5. Matches more elaborate pipelines while running up to 8x faster.
Lu, Yu, Xiong, Zhang, "Iteration Without Elaboration: A Simple ReAct Architecture Suffices for Text-to-SQL Generation" · Aug 2026 · Abstract; Table 4
-
Hold the model fixed and swap the harness around the loop: Claude Code, OpenCode, and the bash-only mini-SWE-agent
Claude Code and mini-SWE-agent "are equivalent within five points" (-1.8 and -1.4 points on two models). Cost per task differed by up to 3x across harnesses, set by the per-step preamble (16k tokens in Claude Code, 7k in OpenCode, under a thousand in mini-SWE-agent) times the number of steps. Switching thinking off cost mini-SWE-agent 11 points on one model and moved the other two by less than the noise.
Liu, Han, "What Does a Harness Buy? Tokens, Mostly" · Oct 2026 · Abstract; Table 1; §4.4; App. J
-
Scan agent code for feedback paths that can repeat costly operations without an effective bound
68 confirmed infinite agentic loops across 47 projects, from 6,549 agent repositories scanned (91.9% precision). Developers "omit them, misuse them, configure them with ineffective bounds, or place them outside the actual feedback path."
Hou, Wang, Zhao, Wang, "When Agents Do Not Stop: Uncovering Infinite Agentic Loops in LLM Agents" · Jul 2026 · Abstract; §1
-
Position paper: whether web agents should default to ReAct or to plan-then-executeAgainstNot measured
Argues ReAct is "the wrong default for web agents" because untrusted page content flows into every next-action decision. All WebArena tasks are compatible with plan-then-execute, and 80% can be done with a purely programmatic plan.
Piet et al., "Web Agents Should Adopt the Plan-Then-Execute Paradigm" · May 2026 · Abstract
Related
- 7.b.iiiSize run budgets so productive runs aren't cut off: turn caps, deadlines, command timeouts
- 7.b.iDetect stalls and loops: warn, then stop early
- 2.a.iiiChoose how the agent acts: typed tools, code execution, or shell, matched to the model and task
- 6.c.iiPlan-then-execute
- 10.c.iContain sensitive data and untrusted input
- 6.c.iCode-then-execute (CaMeL)
- 7.d.iiInversion of control
- 7.c.vLanguage Agent Tree Search (LATS)
- 6.b.iParallel tool execution for read-only calls
In Claude Code
This optimization is a skill in aot-kit, our open-source Claude Code plugin: /aot-kit:react-loop. Its library entry holds every source. Have new evidence, or a correction? Suggest a change.