Long-Running AI Agents: A Practical Guide to Separating Planning from Execution

    This article explains why long-running, multi-step AI agents hit cost, latency, and capability-mismatch bottlenecks at the same time, and how decoupling planning from execution addresses all three. It walks through a three-stage Plan–Execute–Review architecture with bounded retries, a two-dimensional routing matrix that selects model tiers by task difficulty and latency sensitivity, a total-cost-of-ownership formula showing why output tokens and cache reuse matter more than per-million-token price, a layered evaluation set for measuring tool use, structured and 3D generation, code quality, aesthetics, and efficiency, and the review and quota-governance practices needed to run such systems in production. Readers get concrete configuration examples, an implementation checklist, and a way to spend top-tier reasoning only where it pays off.

    1. The Problem: Three Coupled Bottlenecks in Long-Running Tasks

    When teams build agents that autonomously complete multi-step work, they consistently run into three bottlenecks. They are coupled, so none can be optimized in isolation:

    1. Cost bottleneck: Long tasks repeatedly read and write context, so input tokens grow roughly linearly—sometimes super-linearly—with each round. Even a low unit price can be swallowed by the total volume.
    2. Latency bottleneck: The highest reasoning tiers usually come with significant latency, and user experience degrades sharply in interactive scenarios.
    3. Capability mismatch bottleneck: Not every sub-step needs top-tier reasoning. Sending the hardest and the easiest steps to the same tier is the main source of waste.

    The core insight from this practice can be stated in one sentence: planning and execution are two different kinds of computation, and they should be decoupled and selected for separately.

    2. Architecture: A Three-Stage Plan–Execute–Review Pipeline

    Split the agent pipeline into three stages with single responsibilities, and choose the model tier and budget ceiling independently for each.

    • Planning stage (Planner): Produces a structured task graph (DAG) that specifies sub-goals, dependencies, acceptance conditions, and an estimated token budget. This stage is called infrequently but delivers high value per call, so it suits a strong reasoning tier.
    • Execution stage (Executor): Works through the DAG node by node, including code changes, file operations, UI operations, and 3D modeling. This stage is called most often and is the main cost driver, so a medium tier is the right trade for throughput.
    • Review stage (Reviewer): Runs static checks, executes tests, and reviews diffs on the output, falling back to the execution stage for retries when necessary. A high reasoning tier is needed only in the final round, which avoids paying that cost throughout.

    A sketch of the scheduling skeleton:

    1. def run_task(goal, cfg):
    2. plan = planner.invoke(goal, budget=cfg.plan_budget) # high reasoning tier
    3. for node in plan.order(): # execute in topological order
    4. result = executor.invoke(node, tier="medium")
    5. if not node.repeatable(result):
    6. continue
    7. report = reviewer.invoke(plan.diff(result), tier="high") # high tier in the final round only
    8. return report if report.passed else run_task(goal, cfg) # bounded retry

    The key is bounded retry: set a hard cap on the number of fallbacks, or a planning error turns into an infinite loop and a token black hole.

    3. Tiered Routing: Selecting Tiers by Difficulty and Latency

    Routing should not look only at “how hard is the task”—it also has to look at “how long can the user wait.” A two-dimensional matrix describes this:

    Scenario Latency sensitivity Recommended tier Notes
    Interactive Q&A, small single-file edits High Medium-low Optimize for time to first token and throughput
    Multi-file refactoring, cross-module migration Medium Medium execution + high review The mainstay combination
    Research reproduction, long tool-call chains Low High planning + medium execution Most cost-efficient
    High-fidelity 3D/UI generation Medium High tier + reference material Material constraints markedly improve consistency

    In engineering terms, express routing as configuration rather than hard-coded logic, so it can be tuned continuously against production telemetry:

    1. routing:
    2. default: {tier: medium, max_tokens: 8000}
    3. escalate_on: [test_fail, schema_violation, low_confidence]
    4. review: {tier: high, rounds: 1}
    5. hard_budget_usd: 3.0

    4. Cost Model: Unit Price Is Not the Bill

    When assessing the economics of an approach, you have to take a total cost of ownership view instead of comparing per-million-token prices. A workable estimation formula:

    1. Cost = (Tin * Pin + Tout * Pout + Tcache_read * Pcache + Tcache_write * Pwrite) / 1e6

    What actually determines the bill is Tout and total token consumption. A common pattern in practice: a cheaper model is “chatty,” writes large amounts of its reasoning and intermediate output into the response, and ends up with a higher bill. So token efficiency (the inverse of the output volume needed to complete the same task) should be a first-class selection metric.

    Cache reuse is the second lever. When cached input reads are priced well below normal input, the economics of multi-turn conversations and repeated references to long documents improve substantially, and tiers that were previously “only good for producing a plan, not for continuous conversation” become usable. Implementation points:

    • Put stable system prompts, tool definitions, and repository conventions in the context prefix to guarantee cache hits;
    • Avoid inserting volatile content such as timestamps or random IDs at the start of each round, which breaks the cache;
    • Move large reference material to external storage (such as object storage) and pass it by reference instead of stuffing it all into the context.

    5. Capability Evaluation: Turning “Feel” into Metrics

    Selection cannot rely on impressions. Build a layered evaluation set and score each dimension independently:

    1. Tool and UI operation capability: measured by task completion rate, ineffective-click rate, and number of fallbacks.
    2. Structured generation and 3D modeling: measured by geometry/parameter correctness, constraint satisfaction rate, and human ratings of fidelity; results with and without reference material should be tallied as separate groups.
    3. Code quality: compile pass rate, unit test pass rate, number of static-check warnings, and change size (diff lines).
    4. Aesthetics and consistency: use blind evaluation with multiple cross-scoring reviewers to avoid brand bias.
    5. Efficiency metrics: tokens consumed per task, end-to-end elapsed time, and cache hit rate.

    Evaluation must fix random seeds and dependency versions and retain raw traces; otherwise the conclusions are not reproducible.

    6. Code Review and Budget Governance

    Output from the execution stage must go through independent review—never let the executor grade itself. Chain static checks, type checks, tests, and diff review into a pipeline where any failure triggers a bounded fallback. The review logic itself should also be configurable so it can be wired into individual projects.

    On budget governance, what most easily gets out of control in long tasks is “invisible consumption.” Recommendations:

    • Set both token and dollar ceilings per task and per stage; on breach, trip the breaker and persist the scene;
    • Build dashboards over call volume, cache hit rate, and failure rate through logging and monitoring services, with alerts on abnormal swings;
    • Archive task traces and artifacts to object storage for regression evaluation and incident post-mortems;
    • Use queued scheduling to smooth peaks, so a concurrency spike cannot exhaust the quota and take down the interactive path.

    7. Implementation Checklist

    • Split the stages first, then talk about selection; do not cover the whole pipeline with a single tier.
    • Default to medium-tier execution and high-tier review in the final round; in practice this usually yields a noticeable drop in overall elapsed time.
    • Write token efficiency and cache hit rate into your selection metrics instead of looking only at unit price.
    • A stable prefix plus external references are the two basic moves for controlling long-context cost.
    • Bounded retries, dual-ceiling circuit breaking, and full-chain observability are the three non-negotiables for running long tasks in production.

    Organized this way, a long-horizon agent system can achieve a stable success rate and a predictable bill within a limited budget, while placing top-tier reasoning precisely where it is actually needed: planning and review.