Separating Planning from Execution: A Layered LLM Development Workflow with Cost Control

    Single-shot generation says little about a large model's true capability. This article argues that planning ability is what actually determines success on long-horizon tasks, and presents a layered development workflow in which a strong planning model produces documents and contracts while a more cost-effective execution model writes the code. It covers requirement freezing with testable acceptance criteria, domain modeling and interface contracts, task DAGs, execution discipline, and a phased cost-control strategy with budget circuit breakers. Using a spreadsheet-style compute kernel as a stress test, it also explains how to evaluate programmatically drawn visuals and how to package reusable assets for handoff, closing with the risk boundaries that keep model output inside a controllable process.

    1. Why Planning Ability Is the Real Differentiator

    When discussing coding models, a common bias is to equate “can it generate something that runs in one shot” with “the ceiling of its capability.” Whether a single generation succeeds depends heavily on the prompt, sampling randomness, and how the task is sliced; sample variance alone is enough to make a demo result neither reproducible nor generalizable.

    Planning ability is what actually determines the outcome of long tasks, for three reasons:

    • Context is a finite resource. An engineering project of tens of thousands of lines can never fit into the context window at once; it has to rely on external documents as a “memory carrier” and on an external state machine.
    • Rework cost grows non-linearly the further along you are. A wrong domain model or a vague interface contract hurts little at the design stage, but by the integration stage the change surface is often several times the cost of fixing it early.
    • Planning quality determines verifiability. Good planning slices vague requirements into small blocks where “every step has clear acceptance conditions,” so the execution stage can automatically judge success rather than relying on manual test runs.

    So the layered paradigm used here is: a strong planning model only outputs documents, and an execution model only writes code against those documents. This carries an additional engineering benefit—documents are assets. They can be reviewed, versioned, and reused even after switching models.

    2. A Reproducible Layered Development Workflow

    2.1 Requirement Freeze: Write Acceptance Criteria Before Features

    Don’t feed in “build something like [some software]” as input. Instead, converge the requirements into decidable acceptance conditions:

    1. Goal: Build the core of a spreadsheet-like application with basic computation (GUI optional)
    2. Acceptance criteria:
    3. A1 Support A1-style cell addressing, with configurable row/column size
    4. A2 Support arithmetic, parentheses, common aggregate functions, and range references
    5. A3 Support absolute and relative references; references shift by rule when filling
    6. A4 On circular references, must raise an error without hanging, and the error must be locatable to a cell
    7. A5 After a single cell changes, only recompute the set of cells affected by it
    8. A6 Under a 100,000-cell scale, full recalculation P95 latency has a clear upper bound
    9. A7 Undo/redo covers the most recent N edits, with reproducible behavior
    10. A8 Provide import/export; values and types are not lost after a round-trip
    11. Non-goals: multi-user collaboration, charts, macro scripting

    The “non-goals” column matters just as much. A high-frequency cause of long-task failure is not insufficient ability but continuously expanding scope.

    2.2 Domain Modeling and Interface Contracts

    Require the planning stage to produce data structures and function signatures, and to make error semantics explicit. Contracts first let the execution model “connect” across stages:

    1. Cell:
    2. id: (row, col)
    3. raw: string # original user input
    4. kind: number | text | formula | empty
    5. value: number | text | error
    6. dirty: bool
    7. Formula:
    8. tokens: Token[]
    9. ast: Node
    10. deps: Set<CellId> # direct dependency set
    11. Engine API:
    12. set_cell(id, raw) -> Result<Unit, ParseError>
    13. recalc(seed?: Set<CellId>) -> RecalcReport
    14. get(id) -> CellValue

    Only when it is clear that error is a value rather than an exception can the subsequent error-propagation logic be implemented uniformly; only when it is clear that recalc accepts a “dirty starting-point set” can incremental recomputation have a place to land.

    2.3 Task DAG: Dependency Order Is Execution Order

    Break the plan into a directed acyclic graph, labeling each node with its input artifacts, output artifacts, and acceptance command. The execution model handles one node at a time, moving to the next only after the artifacts are written to disk:

    1. T1 Lexing & parsing -> T2 AST & dependency extraction
    2. T2 -> T3 Dependency graph & topological sort
    3. T3 -> T4 Incremental recalc & dirty marking
    4. T2 -> T5 Function library (aggregate, logical, lookup)
    5. T4 + T5 -> T6 Error propagation & circular reference detection
    6. T6 -> T7 Serialization & import/export
    7. T7 -> T8 Undo/redo
    8. T4 -> T9 Batch computation performance optimization (columnar/vectorized)
    9. All -> T10 Regression tests & documentation

    2.4 Three Disciplines in the Execution Stage

    1. Tests first. Each node generates failing cases first, then the implementation, avoiding the model “conveniently editing the tests to make them green.”
    2. Small commits. Try to confine each change to a single node, making rollback and localization easier.
    3. Fix the regression baseline. After each node, run the full baseline and output three metrics—latency, memory, and test pass rate—forming a comparable historical curve.

    3. Cost Control: Breaking “One-Shot Generation” into Phased Budgets

    The cost of generation calls is roughly proportional to input and output token counts, and the input side of a long task keeps growing as context accumulates. Without constraints, cost growth becomes super-linear and is often amplified during failed retries.

    Practical control measures:

    • Tiered model selection. Use the most capable model in the planning stage, aiming to get the approach right in one pass; use a more cost-effective model in the execution stage, since the tasks have been split small and the contracts are clear.
    • Context trimming and summarization. Inject only the contract fragments and adjacent module interfaces needed for the current node; compress historical dialogue into structured summaries rather than carrying the full text.
    • Prefer incremental edits. For minor requirement tweaks, make local diff-style changes rather than fully regenerating files—this is the most direct way to save money.
    • Budget circuit breaker and retry cap.
    1. budget = { plan: 20%, implement: 60%, integrate: 15%, reserve: 5% }
    2. on node(node):
    3. if spent(node) > node.cap: # per-node cost cap
    4. escalate_to_human(node) # escalate to a human instead of blindly retrying
    5. for attempt in 1..3:
    6. r = generate(node, context=minimal_slice(node))
    7. if tests(r).pass: commit(r); break
    8. else:
    9. shrink_scope(node) # degrade the goal: cut non-core acceptance items

    The shrink_scope step is often overlooked, but it is more effective than “trying a few more times”: loosening the A6 performance target by one notch so the main path goes through first, then coming back to optimize it, results in less overall rework.

    4. Complexity Reference: Why a Spreadsheet-Like Kernel Is a Good Stress Test

    It looks like just “input cells, display cells,” but the real difficulty concentrates in a few places:

    • Recomputation order. Topological sorting over the dependency graph, combined with dirty marking for incremental propagation; once implemented as “full recomputation every time,” it is correct at small scale but unusable at large scale.
    • Reference semantics. The coordinate-shifting rules for absolute and relative references during fill are the part most easily simplified during implementation.
    • Circular references. They need to be detected and located to a specific cycle, rather than throwing an uninformative error.
    • Value domain and types. The rules for empty cells participating in operations, text participating in operations, and error values propagating upstream must form a unified semantics.
    • Large-data interaction. Once the cell count reaches the tens of thousands, both rendering and recomputation must account for virtualization and batched evaluation.

    Taking dependency propagation as an example, the core logic itself is clear; the difficulty lies in boundary handling:

    1. function recalc(seed):
    2. visited, stack = {}, []
    3. for c in seed:
    4. if has_cycle(c, visited, stack):
    5. return Error(CIRCULAR, path=stack)
    6. order = topo_order(union_deps(seed))
    7. for c in order:
    8. c.value = eval(c.ast, resolve_refs) # treat references not yet ready with lazy evaluation
    9. return Report(recomputed=len(order))

    The engineering judgment standard here is: the correctness of this kind of kernel depends heavily on “semantic completeness” rather than lines of code. So using it to evaluate a model is more discriminative than using “generate a small game”—the latter can be padded with dense samples, whereas the former must stay self-consistent across a large number of boundary conditions.

    5. Visuals and Aesthetics: How to Evaluate Programmatically Drawn Scenes

    Stacking large numbers of primitives with scripting languages to draw scenes (for example, an underground-style cityscape made of multi-layer silhouettes + lighting + grain noise) is a common way to showcase a model’s “aesthetics” today. But looking at the finished image directly is easily distorted: public demos are often carefully selected samples, and a single success does not mean the distribution is stable.

    A more reliable approach is to break aesthetics into evaluable dimensions and sample:

    • Composition and silhouette readability. Whether the subject’s outline is clear, and whether background, midground, and foreground are separated.
    • Atmospheric perspective and value layering. Whether contrast and saturation of distant objects decay with distance—this is the key to “looking real.”
    • Color relationships. Whether primary, complementary, and ambient colors are unified, and whether muddy gray appears.
    • Detail density distribution. The number of primitives does not equal quality; dense detail in focal areas and negative space in secondary areas is effective composition.
    • Quantifiable auxiliary metrics. Value histogram distribution, edge density, and noise ratio can serve as a first-pass filter, but cannot replace human evaluation.

    Suggested evaluation flow: generate N copies from the same prompt (for example, 8–12), have multiple people blind-score them and take the distribution, record the common defects of the failure samples, and then write those defects back into the constraints of the next planning round. This turns aesthetic evaluation from “watching a spectacle” into an iterable engineering step.

    6. From Demo to Delivery: Accumulated Assets and Handoff

    Layered development ultimately leaves four types of reusable assets: requirements and acceptance documents, interface contracts, the task DAG with milestone records, and regression test baselines. When all four are in place, the project can keep moving even after the underlying model is swapped—this is the hardest metric for judging “whether a model truly improves engineering efficiency.”

    For engineering handoff, you can leverage general-purpose cloud capabilities to standardize the process: use object storage to hold planning documents, generated artifacts, and evaluation materials; use a container platform to turn builds and regression tests into repeatable pipelines; use a logging service and monitoring alerts to track call volume, failure rates, and per-task cost. Taking Baidu AI Cloud as an example, such general-purpose components can typically be combined on demand, making it easy to put the budget circuit breakers and metrics collection described above into practice.

    7. Risk Boundaries

    • Hallucinated dependencies. A model may reference libraries, interfaces, or parameters that do not exist; dependency existence checks and static analysis must be added to the pipeline.
    • License and source compliance. The reference sources of generated code need human confirmation to avoid introducing incompatible licenses.
    • Prompt injection. When handling external input (files, web pages, user-uploaded content), assume it may carry embedded instructions; the execution side should apply least-privilege constraints on tool calls.
    • Secrets and credentials. Under no circumstances should credentials be written into prompts or code repositories; inject them uniformly via the environment.
    • Single success cannot be extrapolated. Any demo result should be treated as one sample; only when it is reproduced stably on your own evaluation set does it carry engineering reference value.

    In one sentence: the difference between models is more about whether they can turn vague requirements into a verifiable engineering plan; and whether the engineering actually lands depends on whether you use documents, contracts, budgets, and regression baselines to confine the model’s capabilities within a controllable process.