Complex LLM Coding: An Engineering Approach to Separating Planning and Execution

    This article examines why complex coding tasks often fail when a single LLM is asked to generate an entire system, and presents an engineering workflow that separates planning from code execution. It covers how to produce an actionable planning document, how to choose top-level and downstream models, how this approach compares with single-model direct generation, how to accept downstream output, what prototype results do and do not show, how to estimate API costs, common mistakes, and risk controls. Readers will gain a practical framework for testing whether planning-execution separation is worthwhile for their own projects.

    In software development, large language models have moved from completing individual functions to attempting to generate complete systems. Whether they can complete such tasks depends on whether the model can first clarify the structure and then turn that structure into code. This article describes a working method that assigns planning and coding to different models, and explains its steps, cost estimation method, and risks to watch.

    Why Complex Coding Tasks Often Fail

    If a model is given only a one-sentence requirement and asked to output the entire project directly, three common problems appear. First, interfaces between modules are not defined in advance, so later files do not match earlier files. Second, after the project exceeds a certain length, the model forgets earlier conventions, and the same data structure appears with different field names in different files. Third, errors are hard to locate because no document records the original design intent.

    Splitting the task into two phases can alleviate these problems. The document produced in the planning phase acts as long-term memory, and each step in the coding phase follows that document rather than relying on conversational context.

    How to Decompose Complex Coding Tasks

    The goal of the planning phase is to produce a document that is specific enough for downstream models to execute directly. The document should contain at least the following:

    • Module boundaries: what each module is responsible for and what it is not responsible for.
    • Interface contracts: function names, parameter types, return values, and exception cases.
    • Dependency graph: the call direction between modules, avoiding circular dependencies.
    • Data structures: fields, value ranges, and default values of key objects.
    • Exception handling: behavior when input is invalid, resources are insufficient, or external services time out.
    • Acceptance cases: at least several sets of inputs and expected outputs for each module.
    • Rollback strategy: if a module fails, how to replace only that module while preserving completed parts.

    After the document is complete, a human should review it first. The review should focus on whether interfaces match each other and whether acceptance cases cover boundary conditions. This step takes little time, but it prevents downstream models from writing large amounts of code under wrong assumptions.

    How to Choose Top-Level and Downstream Models

    The selection criteria can be divided into two layers. The top-level model needs strong reasoning ability and is suitable for architecture design, task decomposition, and interface definition. The downstream model is mainly responsible for implementing code according to the document and is more cost-sensitive; it only needs to reliably follow the document and write runnable unit tests.

    For specific selection, you can test several candidate models with the same requirement and record three results: whether the document is complete, whether the code passes unit tests, and how many revisions were needed. Do not judge only by a single generation, because model outputs are stochastic; results from multiple runs are more reliable.

    The prompt also needs to be fixed. A reusable template usually includes role setting, project background, output format, prohibitions, and a checklist. The template version should be recorded so that different results can be compared later.

    Single-Model Direct Generation vs. Planning-Execution Separation

    The table below compares the two approaches across several dimensions.

    Dimension Single-model direct generation Planning-execution separation
    Initial cost Lower; one call is enough Higher; requires both planning and execution calls
    Context retention Depends on conversational memory; long tasks are easily forgotten Depends on documents; information can be preserved long term
    Maintainability Module coupling is common; changes have a large impact Interfaces are defined in advance; module replacement is easier
    Failure mode Overall structure is wrong and hard to repair locally A single module fails and can be redone locally
    Suitable boundary Small scripts, single-file tools Multi-module projects, software requiring long-term maintenance

    Separation is not necessarily cheaper. If the planning document is revised repeatedly, or if the downstream model frequently reworks, the total cost may exceed direct generation. Therefore, actual task data is needed to make the judgment.

    How to Accept Downstream Model Output

    Acceptance should be based on the acceptance cases in the document. Run unit tests for each module and record the pass rate. Then perform integration testing to check whether calls between modules conform to the dependency graph. Finally, a human should read the code on critical paths to confirm that there are no obvious logic problems.

    Take a spreadsheet prototype as an example. Its core mechanisms can be divided into three parts for separate acceptance: cell data storage and dirty marking, formula lexing and parsing, and stack-based formula evaluation with circular reference detection. Each part should have an independent test set. Only after the core mechanisms pass acceptance is it worth discussing whether the overall functionality is usable.

    Passing tests does not mean the functionality is complete. Formulas, UI operations, or performance scenarios not covered by the test set may still fail.

    How to Interpret Results from Office Software Prototypes and Game Scenarios

    In one test, a team used planning-execution separation to build two types of prototypes: a simple spreadsheet and a key level of a 2D action-adventure game. The spreadsheet prototype’s plan divided it into a data layer, a logic layer, and a presentation layer, and the execution phase implemented them layer by layer. The game prototype’s plan included AABB collision detection, a character state machine with Idle, Run, Jump, and Attack states, and layer-based rendering order.

    These results demonstrate the feasibility of the method, but they cannot be treated as general conclusions. The prototypes validated only core mechanisms and did not reach the scale of large commercial software. The spreadsheet prototype has not been tested with complex formulas, large data volumes, or long-running operation. The game scenario’s logic and visual effects need to be evaluated by humans after actually running it.

    To reproduce a similar experiment, it is recommended to record the following information: model name or version, input and output length of each call, number of code files and total lines of code, number of test cases and passed cases, and the number and time of manual modifications. This data allows results to be compared and verified by others.

    How to Estimate Costs

    API cost usually consists of three parts: input tokens, output tokens, and unit price. The planning phase requires long context, so input volume is larger; the coding phase outputs more code, so output volume is larger. Failed retries and manual corrections also increase actual spending.

    The basic estimation method is: input tokens for each call multiplied by the input unit price, plus output tokens multiplied by the output unit price, plus additional call costs caused by retries. If a subscription or credit system is used, credits should be converted into an equivalent amount, with the measurement time and exchange rate noted.

    This article does not provide specific cost figures because the original test did not fully record token usage and unit prices for each call. Readers should calculate costs in their own environment using the method above, rather than directly applying someone else’s numbers.

    Common Mistakes

    • The planning document is too vague, leaving the downstream model to guess interfaces.
    • Model versions are not fixed, making results impossible to reproduce.
    • Only normal inputs are tested, while exception cases are ignored.
    • A single generation result is treated as a stable capability.
    • Generated code is merged into the main branch without review.
    • The planning document is not updated after code changes, so document and code fall out of sync.

    Risks and Precautions

    AI-generated code requires human review, including security vulnerabilities, input validation, sensitive information handling, and dependency licenses. Features involving user data should run in an isolated test environment, and security testing should be completed before launch.

    The effects and costs described in this article represent estimates under a specific test environment only and do not constitute performance or price commitments for production environments. Model pricing and capabilities change with versions, and the service provider’s latest documentation should be treated as authoritative.

    Conclusion

    Planning-execution separation is a testable engineering method. It breaks “whether the model can write code” into more specific questions: whether the model can write a clear architecture, whether it can implement modules according to a document, and whether it can pass acceptance tests. As long as teams record data at each step, they can judge whether this method is worth adopting in their own projects.