Engineering Practices for Agentic Programming: From Task Decomposition to Iterative Repair

    Agentic programming empowers AI models to autonomously handle multi-step development tasks based on clear goals, extending far beyond traditional code completion. This article explores the core engineering practices of agentic programming, covering the end-to-end workflow from task decomposition and repository path planning to cross-file modifications and test-driven iterative repair. Additionally, it addresses context management, evaluation metrics, security boundaries, and practical recommendations for implementing agentic programming in real-world software development.

    1. What is Agentic Programming?

    Agentic programming refers to a paradigm where a model autonomously completes multi-step operations around a clear goal. The key difference between it and traditional code completion lies in the unit of work. Code completion handles a single function or a line of code, whereas agentic programming handles a complete requirement, such as “add filtering functionality to a list page and write corresponding tests.”

    A complete agentic programming workflow typically involves the following capabilities:

    • Understanding requirements: Identifying goals, constraints, and acceptance criteria.
    • Task decomposition: Breaking down a large goal into several independently verifiable subtasks.
    • Path planning: Deciding which files to read first and which modules to modify first.
    • Executing modifications: Writing and adjusting code across multiple files.
    • Running verification: Executing tests, builds, or static analysis.
    • Iterative repair: Locating issues based on error messages and modifying the code again.

    These steps form a closed loop. The stability of this loop determines whether agentic programming can truly replace repetitive development labor.

    2. Task Decomposition: Turning Goals into Verifiable Steps

    Task decomposition is the first checkpoint in agentic programming. Poor decomposition will amplify errors in every subsequent step.

    2.1 Hierarchical Decomposition

    A three-layer structure is recommended:

    1. Business goal layer: The actual problem the user wants to solve.
    2. Functional module layer: The components, interfaces, or data structures needed to achieve the goal.
    3. Verifiable step layer: Each step has clear inputs, outputs, and verification methods.

    Taking “adding field validation to a frontend form” as an example, it can be decomposed into the following steps:

    • Analyze the structure and state management approach of the existing form components.
    • Define validation rules for each field, such as required, length, and format.
    • Execute validation before submission and display error messages on the UI.
    • Write unit tests for the validation logic, covering normal and edge values.
    • Verify that the field names in the form match those in the backend API.

    2.2 Define Acceptance Criteria for Each Subtask

    The more specific the acceptance criteria, the easier it is for the agent to determine if it has finished. Vague goals, like “optimize page experience,” are difficult to verify. Verifiable goals, like “the submit button is disabled when the input box is empty, and the tooltip appears within 100 milliseconds,” can be checked directly via tests.

    2.3 Control Decomposition Granularity

    If the granularity is too coarse, the model may modify too many files in a single step, making it difficult to review. If the granularity is too fine, the process becomes lengthy, increasing the chances of error accumulation. In practice, a subtask should typically affect only one module and yield a conclusion in a single test run.

    3. Path Planning and Repository Understanding

    Path planning determines what the agent reads first and modifies later. In repository-level tasks, the quality of this step is particularly critical.

    3.1 Build a Repository Map

    Before making modifications, the agent usually needs to understand the following information:

    • Directory structure and module division.
    • Entry files and main call chains.
    • Dependencies, especially public components and shared utility functions.
    • Location and coverage of existing tests.
    • Build and run commands.

    This information can be obtained by reading configuration files, searching for symbol references, and browsing directories. The more time spent in the planning phase, the less rework will be needed later.

    3.2 Retrieve Relevant Code and Control Input Size

    A repository typically contains a large amount of code unrelated to the current task. Stuffing everything into the context wastes resources and can interfere with the model’s judgment. A more reasonable approach is on-demand retrieval:

    1. 1. Search symbol definitions and references based on task keywords
    2. 2. Read the hit files and their direct dependencies
    3. 3. Record a list of task-related files
    4. 4. Make modifications only within this list

    3.3 Evaluate Change Impact

    Before modifying a public interface, all callers must be listed. For example, if a function’s parameters increase from two to three, all call sites must be updated synchronously. Impact analysis prevents the “fix one, break ten” scenario.

    4. Cross-File Modifications and Consistency

    Cross-file modification is one of the most error-prone parts of agentic programming. Common issues include: interface definitions are changed but callers are not updated; type declarations do not match implementations; and style files and component files have inconsistent naming.

    4.1 Use Interfaces as Anchors

    Modify the interface definition first, and then fix the callers one by one according to the prompts from the compiler or type checker. The type system provides strong consistency constraints, serving as an objective signal the agent can rely on.

    4.2 Avoid Irrelevant Changes

    Agents sometimes opportunistically rename variables, adjust formatting, or rewrite comments. These changes increase the review burden and may introduce regressions. Recommended constraints include:

    • Explicitly state “only modify code related to the goal” in the task instructions.
    • Use version control tools to check diffs and confirm the scope of changes.
    • Apply existing team rules for formatting to avoid style drift.

    4.3 Small-Step Commits

    Form an independent commit for each completed subtask. This way, if an issue arises, you can precisely revert to a specific step rather than starting all over.

    5. Test-Driven Iterative Repair Loop

    Iterative repair is the most valuable part of agentic programming. It shifts the model from “one-time generation” to “continuous correction based on feedback.”

    5.1 Basic Loop Structure

    The loop typically includes the following steps: execute tests, parse errors, locate the cause, modify the code, and run tests again. Each round should leave a traceable record.

    Here is a generic pseudocode example:

    1. MAX_ROUNDS = 5
    2. for round in 1..MAX_ROUNDS:
    3. result = run_tests()
    4. if result.all_passed:
    5. break
    6. failure = parse_first_failure(result)
    7. location = locate_source(failure)
    8. patch = generate_fix(location, failure, context)
    9. apply_patch(patch)
    10. if not result.all_passed:
    11. escalate_to_human(summary_of_attempts())

    5.2 Set Termination Conditions

    The loop must have an exit, otherwise the model might repeatedly attempt to fix the same error, consuming significant resources. Common termination conditions include:

    • Maximum number of iteration rounds.
    • The same error message appearing for two consecutive rounds.
    • The modification scope exceeding the preset number of directories or files.
    • Occurrence of situations requiring human judgment, such as contradictory requirements.

    When any condition is met, automatic repair should stop, and the attempted solutions and failure reasons should be handed over to the developer.

    5.3 Distinguish Error Types

    Different errors require different handling approaches. Syntax errors and type errors can usually be located directly. Assertion failures require an understanding of the business logic. Environment errors, such as missing dependencies or port conflicts, are often unrelated to the code and should be prioritized for environment troubleshooting. Classifying errors before fixing them significantly improves efficiency.

    6. Context Management

    Long-context capabilities expand the amount of information a model can process simultaneously, but this does not equate to infinite memory. The more information there is, the easier it is for the model’s attention to key details to be diluted.

    6.1 Hierarchical Context Organization

    It is recommended to divide the context into four layers:

    1. Task layer: Goals, constraints, and acceptance criteria.
    2. Structure layer: Repository map, module relationships, and interface definitions.
    3. Code layer: The files to be currently modified and related snippets.
    4. History layer: Completed steps, failed attempts, and their reasons.

    Information closer to the current action should be kept as complete as possible. Older history can be compressed into summaries.

    6.2 Use Summaries Instead of Raw Logs

    Test logs might contain thousands of lines, but usually, only a few are actually useful. Extracting the failed test case names, assertion information, and the top stack trace location saves context space and helps the model quickly grasp the key points.

    7. Evaluation and Quality Judgment

    When evaluating agentic programming capabilities, scores from a single leaderboard are difficult to reflect actual performance. Differences in task distribution, runtime environments, and scoring methods across different evaluations mean that direct comparisons require caution.

    7.1 Build an Internal Evaluation Set

    Teams can extract real tasks from historical requirements to build an internal evaluation set. Each task includes a requirement description, initial code, and criteria for passing tests. The results obtained this way are most relevant to the team’s own business.

    7.2 Metrics to Monitor

    • Task completion rate: The proportion of tasks passing all tests within the limited number of rounds.
    • First-time pass rate: The proportion of tasks passing tests on the first generation, reflecting the quality of decomposition and planning.
    • Modification scale: The number of changed files and lines, reflecting whether there are irrelevant changes.
    • Regression defect rate: The number of issues triggered after merging, reflecting long-term quality.
    • Human intervention rate: The proportion of tasks requiring developer takeover, reflecting the degree of automation.

    7.3 Beware of Evaluation Bias

    Public evaluation questions may have already appeared in training data, leading to inflated scores. Prompts, tool permissions, and retry counts during evaluation also affect the results. Therefore, internal evaluations should have fixed settings and be reviewed regularly.

    8. Security and Permission Boundaries

    Agents possess the ability to read and write files and execute commands, meaning their errors can have direct impacts. Security design should follow the principle of least privilege.

    • Limit readable and writable directories to avoid accessing irrelevant paths.
    • Prohibit deployment, deletion, and permission change operations without human confirmation.
    • Do not put keys and credentials into the context; provide them uniformly through environment variables or a secret management service.
    • Set up a whitelist for executed commands and keep complete logs.
    • Generated code still needs to undergo code review and pass automated tests and security scans.

    9. Implementation Recommendations and Applicable Boundaries

    Agentic programming is suitable for the following scenarios:

    • Boilerplate code, interface integration, and data structure conversion.
    • Adding unit tests to existing features.
    • Small features and page adjustments completed according to clear specifications.
    • Repetitive work with fixed patterns, such as dependency upgrades and code migration.
    • Synchronized updates of documentation and code.

    The following scenarios require more caution:

    • Tasks with vague requirements where acceptance criteria are difficult to quantify.
    • Logic containing complex business rules that require domain knowledge judgment.
    • Security-sensitive modules such as payments, permissions, and encryption.
    • Legacy systems lacking test coverage due to insufficient verification means.

    When introducing agentic programming, teams can follow these steps: start with one or two low-risk module pilots; record metrics such as first-time pass rate, modification scale, and regression defects; adjust task templates and permission configurations based on the data; form internal prompt specifications and review checklists; and gradually expand the applicable scope. At each step, use data to decide whether to proceed, avoiding blindly expanding permissions just because the tool performs well.