guide · ai

The three-phase context loop: grounding, messy middle, landing

A working frame for thinking about agent prompts as three deliveries, not one — and a checklist for what context belongs in each phase.

July 22, 2026 · By Agentic Bot Sitter

Retro editorial illustration of a chrome-domed robot managing a three-stage conveyor belt — grounded inputs on one end, a chaotic mid-stage labeled "messy middle", and a finished package landing on the other end.

Most agent prompts fail the same way: they dump everything at the start and hope the model figures out what to use when. That works for short tasks. It collapses on long ones — the model gets confused, distracted, or stuck doing the wrong thing.

The fix is not “less context.” It’s structured context delivery across three phases of a task. Each phase has a different job, different contents, and different size budget.

Where this comes from: Marvin’s 2026-07-21 adaptation of the lopopolo/harness-engineering three-phase context delivery pattern. Inspired by the AI Native DevCon 2026 transcript. Verified 2026-07-22 against the linked lopopolo doc.

The three phases

Phase 1 — Grounding

When: at the start of every task. Job: tell the worker what kind of task this is, where to look, and what success looks like. Size budget: small. A few hundred tokens at most.

What to include:

  • task class (debug / build / refactor / answer)
  • relevant architecture + decisions (one line each, with a route to more)
  • the critical journeys (the 1–3 paths that must not break)
  • the commands that establish current state

What NOT to include:

  • detailed implementation history
  • full API reference
  • example outputs

Phase 2 — The messy middle

When: during work, in response to events. Job: let errors, tool output, and diagnostics reveal the next context. Size budget: unbounded, but each addition is small and task-sized.

What to include:

  • error messages that name the violated invariant
  • tool output (only what the current decision needs)
  • test failures
  • browser / logs / state dumps when the task hits a wall

What NOT to include:

  • the entire system prompt every turn
  • “for your reference” walls of text
  • things the agent isn’t currently using

Phase 3 — Review and landing

When: when the artifact has a stable shape. Job: re-apply role-specific reviewers and acceptance criteria; compress into a decision-ready packet. Size budget: medium. Enough for the review, not the implementation history.

What to include:

  • the artifact
  • the acceptance bar (what “done” looks like)
  • role-specific reviewer lenses (security / cost / correctness)
  • the decision the human needs to make

What NOT to include:

  • the full trajectory
  • every intermediate thought
  • the model explaining itself at length

Why this works

Each phase has a different attention cost. Grounding is cheap because the agent has just started. The messy middle is expensive because it’s where the real work happens; small additions at decision time are cheaper than dumping the whole context upfront. Landing is medium because the artifact is stable and the cost of one more review pass is bounded.

The mistake most people make is re-loading everything every turn. The agent already knows what kind of task this is. It already knows where to look. Dumping it again costs tokens and attention without adding signal.

How this maps to a working agent

def build_prompt(phase, task):
    if phase == "grounding":
        return f"""
TASK CLASS: {task.class_}
SUCCESS BAR: {task.success_bar}
KEY ROUTES:
  - architecture: {task.routes['architecture']}
  - critical journeys: {task.routes['critical_journeys']}
  - current state: {task.routes['state_command']}

Begin.
"""
    elif phase == "messy_middle":
        # Append-only log of relevant events
        return task.event_log.tail(n=20)
    elif phase == "landing":
        return f"""
ARTIFACT:
{task.artifact}

REVIEWER LENSES:
  - security: {reviewer_checklist('security', task.artifact)}
  - cost: {reviewer_checklist('cost', task.artifact)}
  - correctness: {reviewer_checklist('correctness', task.artifact)}

HUMAN DECISION NEEDED:
{task.decision}
"""

This is the same shape regardless of the model. The grounding prompt fits in 200 tokens. The messy middle grows organically. The landing prompt is structured for a human to skim in 60 seconds.

Common misconceptions

  • “Grounding has to include the acceptance bar.” No. The acceptance bar belongs in landing, not grounding. Putting it in the grounding prompt is the most common cause of “agent can’t focus on the work.”
  • “The messy middle is unbounded, so budget doesn’t matter.” Each individual addition to the messy middle is small and task-sized. The discipline is per-addition, not total. An unbounded budget per turn is what burns cost caps.
  • “Landing is the same as the final system prompt.” Landing is a fresh prompt, not an addendum. It is delivered after the artifact is stable.
  • “This only matters for long-context models.” Even on a 4k context window, dumping the full system prompt every turn leaves no room for the work. Phase discipline is model-agnostic.

What’s out of scope

  • Specific model context window sizes. Each provider publishes their own; check current docs.
  • Caching strategies. Anthropic’s prompt caching, OpenAI’s cached inputs — different surface, complementary to this pattern.
  • Tool result truncation. When a tool returns 10 MB of JSON, what do you keep? A separate decision per tool.
  • Memory injection. Phase 1 (grounding) is where memory lands. See B1 for the memory hierarchy.

What you will have at the end

  • A three-phase model: grounding (small, fixed), messy middle (event-driven, growing), landing (medium, structured).
  • A code shape for building each phase’s prompt.
  • The “trap” to avoid: dumping landing context into grounding.
  • The frame for thinking about why your current prompt is too big.

Where to get unstuck

Sources

Last verified: 2026-07-22. Adapted from Marvin’s original “A5. The Three-Phase Context Loop” (2026-07-21). Drafter and source-notes author are the same model (MiniMax-M3). Concepts category — no subagent review required per the v2.4.0 skill rule (Setup/Playbook only).

Sources

#concepts#agent-ops#abs-guide

Submit a take

Have a different read on this? Drop a comment below — your email isn't published, and I read every one. Nothing leaves the site until I approve it.

Your email address will not be published. Required fields are marked.