SPAR Agent Loop Design
also known as Sense-Plan-Act-Reflect, SPAR framework
Build the agent's core as a loop with four named phases: Sense, Plan, Act, Reflect. Sense takes in signals from the environment and the task input. Plan works out what the agent intends to do next. Act runs the tool calls and makes the changes. Reflect checks the outcome against the plan and updates what the agent believes. Make each phase a real, named step you can point to in code and see in traces. Then you can tell which phase is failing instead of staring at a black box.
Methodology process overview
Intent. Give every agent the same four named phases, Sense, Plan, Act, and Reflect, so behaviour, traces, and failures line up with a phase instead of hiding in one murky loop.
When to apply. Use this when you design the main loop of any real agent: a coding agent, a research agent, a browser agent, or an ops agent. It helps most when a team is reaching for ReAct or a free-running loop with no clear control structure. Don't apply it for a single-shot prompt or a fixed pipeline with no perception and no reflection. There is no loop to design.
Inputs
- Environment interface — The channels the agent reads from: APIs, user turns, the file system, and other observers.
- Task goal — The goal the agent is chasing, written so the Plan phase can break it into steps.
- Action repertoire — The tools, effectors, or sub-agents the Act phase can use.
Outputs
- Four-phase agent loop — Clear Sense, Plan, Act, and Reflect steps joined by typed transitions. You can test and watch each step on its own.
- Phase trace schema — Structured trace events from each phase that your tooling can group, search, and replay.
Steps (6)
Build the Sense phase
Decide what the agent observes each tick: user input, tool outputs, memory recall, and environment state. Sense gathers the situation, it does not judge it. Surface anything unclear instead of papering over it.
Build the Plan phase
Turn the sensed situation into an intended next move or plan. Use chain-of-thought, tree-of-thoughts, or plan-and-execute when the task calls for it. The output is a plan, not a free monologue.
Build the Reflect phase
Check the outcome of Act against what the plan intended. Update beliefs, note lessons, and decide whether to loop, replan, escalate, or stop. Reflect is what makes the agent more than a script.
Wire phase transitions and termination
Define the typed moves between phases: Sense to Plan to Act to Reflect, then back to Sense or stop. Add a step budget and clear stop conditions so the loop always ends.
Instrument each phase as a first-class trace event
Emit a structured trace event tagged with its phase. Your observability tools can then group, filter, and replay by phase, so failures stay easy to find.
Framework-specific instructions
Pick a framework and generate a framework-targeted rewrite of this methodology's steps.
Choose framework
AI-generated for Agent Development Kit (ADK) (Google) — verify against official docs.
Principles
- Every agent has the same four phases. Make them visible, do not hide them.
- Only Act changes things. The other three observe, decide, and learn.
- Reflect is required. An agent that never reflects is just a script.
- Phase boundaries are contracts you can test, not nice-sounding labels.
Known failure modes (3)
- ✕Unbounded Loop
Loop runs Sense→Plan→Act→Reflect→Sense forever because Reflect lacks a stop condition or step budget.
- ✕Same-Model Self-Critique
Reflect uses the same model and prompt as Plan, so the agent rubber-stamps its own decisions.
- ✕Hidden State Coupling
Phases share mutable state outside their typed transitions, breaking the localisation guarantee SPAR is supposed to give.
Related patterns (5)
- ★★ReAct
Interleave a single thought, a single tool call, and a single observation per step so the agent reasons over fresh evidence.
- ★★Plan-and-Execute
Plan all the steps once with a strong model, then execute each step with a cheaper model under the plan.
- ★★Reflection
Have the model review its own output and produce a revised version in one or more passes.
- ★★Tool Use
Let the LLM produce typed calls against an external toolkit instead of producing free-form text the surrounding system has to parse.
- ★★Step Budget
Cap the number of tool calls or loop iterations the agent is allowed within a single request.
Related compositions (3)
- recipe · abstract shapeModern Coding Agent
An agent that reads, writes, and runs code in a sandbox, calling tools and (optionally) sub-agents while a human approves the destructive parts. The shape that powers Cursor, Claude Code, OpenHands, Aider, Codex CLI.
- recipe · abstract shapePlanning Loops
Different ways to structure 'think then act': linear ReAct, plan-then-execute, parallel DAG planning, tree search with backtracking, and the outer/inner planner+executor split.
- recipe · abstract shapeReflection & Self-Correction
Patterns where the model reviews its own work before shipping it: scoped rubric reflection, self-refine, deterministic post-checks, process rewards.
Related methodologies (2)
- Agentic Workflow Construction★★
Make agent authors name the four parts and the freedom level before they code, so a failure points to one part instead of smearing across a vague agent.
- Plan-Reason-Evaluate-Feedback Loop★
Split the agent's control loop into Plan, Reason, Evaluate, and Feedback so each one can be written, tested, and tuned on its own instead of crammed into a single prompt.
Sources (2)
Agentic Artificial Intelligence: Harnessing AI Agents to Reinvent Business, Work, and Life
Ch 4 'Inside the Mind of an AI Agent' (pp. 83–107) “Inside The Mind Of An AI Agent (pages 83-107)”
How to see the bigger picture re: AI agents
“what makes AI agents powerful is how these four capabilities work together in an integrated cycle, creating a system that can pursue complex goals with increasing sophistication”
Provenance
- Added to catalog:
- Last updated:
- Verification status: verified