Outer-Inner Agent Loop
also known as Dual-Loop Agent, Planner-Outside Executor-Inside, Dispatch-and-Act Loop
Run two nested loops: an outer planner agent decomposes the goal into subtasks; an inner executor runs a ReAct loop on each, and the outer can replan based on the inner's progress.
This pattern helps complete certain larger patterns —
- specialisesPlanner-Executor-Observer★— Add an explicit Observer role between Planner and Executor so progress is checked against the plan instead of trusted blindly.
- specialisesPlan-and-Execute★★— Plan all the steps once with a strong model, then execute each step with a cheaper model under the plan.
Context
A team operates an agent on long-horizon work — multi-step report writing, multi-stage data investigations, multi-day refactors — where the breakdown of the goal matters as much as the individual steps. Partway through the run, the agent may discover something that invalidates the original plan: a missing data source, a contradictory finding, a failed dependency. The team wants the planner to react to that evidence instead of letting execution proceed on a stale plan.
Problem
A single agent loop that conflates planning and acting (such as ReAct) does both on every turn and pays the cost of replanning at each step even when the plan is still valid. Plan-and-Execute fixes the plan up front but then runs the executor blind — by the time execution finishes, the planner has no chance to react to mid-run evidence except by abandoning the run. The team needs planning and execution on separate cadences, with a controlled channel by which execution evidence can interrupt the plan.
Forces
- Plans need a stable horizon; execution needs flexibility within steps.
- Replanning is expensive; doing it every turn is wasteful, doing it never is brittle.
- Inner-loop autonomy must not silently expand subtask scope.
Example
A research agent that handles multi-step report writing repeatedly drifts mid-execution — it discovers a fact that invalidates its plan but keeps executing because the planning loop has already exited. The team restructures as an outer-inner-agent-loop: the outer planner decomposes the report into subtasks with milestones; the inner executor runs a ReAct loop on each subtask and reports back. When the inner agent reports an invalidating finding, the outer can interrupt and replan instead of letting execution proceed on a stale plan.
Diagram
Solution
Therefore:
Define two roles. Outer agent (Dispatcher + Planner): decomposes the goal into subtasks with milestones, dispatches each to the inner agent, and may interrupt to replan when milestones are missed or new evidence arrives. Inner agent (Actor): runs a tool-use loop on a single subtask, reports back a structured result. Outer holds the global state; inner holds the local state. The interruption channel is the only path the outer has into the inner's loop.
What this pattern forbids. The inner agent may not change its subtask scope; scope changes must come back through the outer planner.
The smaller patterns that complete this one —
- usesReplan on Failure★★— Trigger a fresh planning step when execution evidence contradicts the current plan.
- usesStep Budget★★— Cap the number of tool calls or loop iterations the agent is allowed within a single request.
And the patterns that stand alongside it, or against it —
- complementsSupervisor★★— Place a coordinating agent above a set of specialised agents and route work to them.
Neighbourhood
Click any neighbour to follow the language. Scroll to zoom, drag to pan.