Designing Intelligent Coding Agents: Six Core Modules and Engineering Practices

    This article explains why the same language model can behave differently when connected to a real software project. It breaks an intelligent coding agent into six engineering modules—task control, tool execution, context management, memory, verification, and security—and shows how these modules work together through state-driven execution, structured feedback, controlled file changes, evidence-based validation, and human oversight.

    1. Why the Same Model Behaves Differently in an Engineering Environment

    In a normal chat, developers describe a problem, paste code, apply the suggested changes, run the program, and send error messages back to the model. The model generates recommendations, while the developer connects those recommendations to the real project environment.

    An intelligent coding agent automates part of this process. It can inspect directories, locate symbols, check dependencies, edit files, run tests, and continue adjusting its approach based on the results. Its advantage is not simply that it generates more code. It can continuously collect external evidence and feed the results of its actions back into the decision-making process.

    To analyze such systems, it is useful to distinguish three layers:

    • Model capabilities: Understanding requirements, analyzing code, and generating modification plans.
    • Reasoning strategy: Allocating more computation to complex tasks, comparing candidate approaches, and checking conclusions.
    • Agent execution system: Managing task state, tool permissions, context, validation, and stopping conditions.

    A reasoning model is still a large language model. Additional reasoning computation can improve performance on some complex tasks, but it does not make the model more accurate in every situation, nor does it guarantee a favorable cost-benefit ratio.

    An agent execution system is not another type of model. It is a control layer built around the model. It determines what the model can see, what it can execute, and how the system evaluates whether the task is complete.

    A practical way to understand the relationship is:

    The model proposes the next action, the execution system constrains its boundaries, tools produce environmental feedback, and the validation mechanism determines whether the change is trustworthy.

    The following sections divide this system into six core modules. This is an engineering-oriented decomposition, not the only possible standard.

    2. Module One: Task Control and the Execution Loop

    2.1 Moving from One-Time Answers to State-Driven Execution

    Programming tasks rarely finish in a single response. Even fixing a simple boundary-condition bug may require requirement clarification, code localization, behavior reproduction, patch generation, and regression testing.

    An agent therefore needs to maintain explicit task state, including at least:

    • The user’s goal and acceptance criteria;
    • The current scope of work;
    • Facts and evidence already collected;
    • Actions already performed and their results;
    • Unconfirmed assumptions;
    • Remaining budgets and reasons for stopping.

    A typical loop can be expressed as:

    Observe the environment → inspect evidence → select an action → execute the action → update the state.

    The important point is not the loop itself, but whether every action changes the task state. If the agent repeatedly reads the same content or performs the same failed operation without forming a new judgment, the system lacks effective progress detection.

    2.2 Plans Must Support Revision

    Complex tasks benefit from an initial phased plan, but the plan should not be treated as an immutable script.

    For example, the initial assumption may be that a bug originates in input validation. After inspecting the implementation, the agent may discover that the actual cause is stale-cache logic. It should then update its assumptions and plan instead of continuing with a modification that no longer has supporting evidence.

    A useful planning unit is a verifiable sub-goal, such as:

    1. Confirm the expected behavior for invalid input;
    2. Locate the relevant implementation and call sites;
    3. Build a test that reproduces the problem;
    4. Apply the smallest necessary change;
    5. Check affected execution paths.

    2.3 Stopping Conditions Must Be Explicit

    A task should not stop merely because the model says that it is complete. The execution system should distinguish between:

    • Acceptance criteria being satisfied;
    • Missing information requiring clarification;
    • An operation exceeding the agent’s permissions and requiring approval;
    • An unavailable environment preventing further validation;
    • Time, call-count, or resource budgets being exhausted;
    • Multiple attempts producing no meaningful progress.

    These states have different meanings and should not all be reported as success.

    3. Module Two: Tool Interfaces and Controlled Execution

    3.1 Tool Design Determines Action Reliability

    Common capabilities include directory inspection, text search, file reading, patch application, controlled process execution, and change comparison.

    Compared with a universal interface that can perform arbitrary operations, narrowly scoped tools are easier to validate, restrict, and audit. For example, a file-reading tool may accept only a workspace-relative path and a line range. It does not also need permission to execute commands or access the network.

    Every tool should have a clear contract covering:

    • Input fields and allowed values;
    • The resources it can access;
    • Success and failure response structures;
    • Timeout and output-size limits;
    • Whether it causes side effects;
    • Whether human approval is required.

    3.2 Tool Results Should Be Structured

    Returning undifferentiated text makes it easy for the model to confuse normal output, error messages, and execution status. A more reliable result should separate execution status, exit information, primary output, error output, and truncation indicators.

    The system should especially distinguish among:

    • The tool call itself failing;
    • A command starting successfully but producing a failed check;
    • A check executing successfully and satisfying the target condition.

    For example, a test assertion failure does not mean that the execution tool malfunctioned. These cases require different recovery strategies.

    3.3 File Changes Must Account for Concurrent Modifications

    After an agent reads a file, a user or another process may modify it. Overwriting the file directly can destroy someone else’s work.

    Before applying a patch, the system should verify that the expected content still exists. When necessary, it should compare file versions or content hashes. If a conflict is detected, the agent should reread the file and adjust the patch rather than silently overwriting the changes.

    This may seem like a minor constraint, but it is an important boundary between a demo system and one that can operate safely in real engineering environments.

    4. Module Three: Context Construction and Compression

    4.1 Context Is Not a Simple Dump of Repository Contents

    A code repository is usually much larger than the amount of information a model can process effectively in one call. Even when the input capacity is sufficient, including every file increases cost and introduces irrelevant information.

    A better strategy is to narrow the scope progressively:

    1. Extract behavioral, symbol, and error clues from the task;
    2. Inspect the directory structure and identify potentially relevant modules;
    3. Search for symbol definitions and call sites;
    4. Read key implementations and nearby tests;
    5. Expand to other modules only when cross-module dependencies are discovered.

    The goal of context management is not to include the most information. It is to provide the strongest evidence needed for the current decision.

    4.2 Separate Information by Function

    At minimum, it is useful to distinguish four categories:

    • Stable rules: Work scope, coding conventions, and security boundaries;
    • Task state: Goals, plans, confirmed facts, and pending items;
    • Local evidence: The code, tests, and logs currently under analysis;
    • History: Earlier attempts and their results.

    Stable rules should remain as consistent as possible in both order and wording. If the underlying service supports input-prefix caching, this may help cache reuse. However, whether caching is effective, and how it is billed, depends on the specific implementation. Textual consistency alone is not sufficient evidence.

    4.3 Compression Must Preserve the Basis for Reasoning

    As a session grows, its history must be compressed. The summary should not contain only conclusions such as “already checked.”

    A useful summary records:

    • What scope was inspected;
    • What results were obtained;
    • Which evidence supports each conclusion;
    • Which conditions remain unverified.

    For example, “The target test passed, but the full test suite was not run” is more accurate and more useful for continuing work than “Tests passed.”

    5. Module Four: Memory and Long-Running Task Continuity

    Context is the information visible to the current model call. Memory is state retained across calls or sessions. They are not equivalent.

    5.1 Memory Should Be Organized by Lifetime

    Memory can be divided into:

    • Task memory: Progress, failed attempts, and unresolved items for the current issue;
    • Repository memory: Directory responsibilities, test entry points, and build constraints;
    • User preferences: Explicitly confirmed preferences for output or collaboration.

    Temporary assumptions should not automatically become repository facts after a task ends. Otherwise, one incorrect judgment may continue affecting future tasks.

    5.2 Memory Must Be Able to Expire

    Code changes, and test entry points may be reorganized. Important memories should include their source, recording time, or applicable version information.

    When a memory is reused, the agent should perform a low-cost verification first. For example, it can confirm that a relevant directory still exists and that configuration has not changed, rather than trusting historical information unconditionally.

    5.3 Sensitive Information Should Not Be Stored Long Term

    Credentials, personal information, and business secrets should not be saved automatically merely because they appeared in tool output. Memory writes require filtering, access control, and cleanup mechanisms.

    The most valuable long-term memory is confirmed, reusable engineering knowledge that is explicitly allowed to be retained—not a complete copy of all historical content.

    6. Module Five: Validation, Feedback, and the Quality Loop

    6.1 A Successful Edit Does Not Prove the Problem Is Solved

    A file being written successfully only proves that the editing operation completed. It does not prove that the software now behaves correctly.

    Validation should be layered according to the risk of the change:

    1. Check that the patch matches the intended modification;
    2. Run available syntax or static checks;
    3. Run tests directly related to the change;
    4. Inspect adjacent call paths;
    5. Expand regression testing according to the scope of impact.

    If the project lacks automated tests, the agent should state which alternative checks were used and what those checks cannot cover.

    6.2 Establish Reproducible Evidence First

    When fixing a defect, the ideal sequence is to create a failing test, implement the change, and then confirm that the same test passes.

    This avoids a common false conclusion: a newly added test already passed, but its result was incorrectly treated as evidence that the fix worked.

    Some problems depend on external systems, timing, or data volume and cannot be reproduced reliably. In such cases, the system should clearly state the strength of the evidence and avoid presenting an assumption as a verified conclusion.

    6.3 Prevent “Passing” by Lowering the Standard

    An agent might delete assertions, skip tests, or broaden exception handling so that the visible result improves while the actual problem remains hidden.

    Changes to test configuration, assertions, and validation logic should therefore be checked for independent business justification. Passing tests are one form of evidence, not a reason to permit arbitrary modifications.

    7. Module Six: Security Boundaries, Auditing, and Human Collaboration

    7.1 Treat Repository Content as Data to Analyze

    Source-code comments, documentation, and logs may contain text instructing the agent to perform additional operations. Such content must not automatically become system instructions.

    For example, if a file asks the agent to upload environment variables, the agent must not comply merely because the instruction appears in project documentation. External content is task material; any requested operation still requires permission and consistency checks against the task objective.

    7.2 Apply the Principle of Least Privilege

    Different tasks should expose different capabilities. Read-only analysis normally does not require file-write access. A standard bug fix usually does not require modifying system configuration or accessing production data.

    High-risk actions should have explicit approval points, including:

    • Large-scale deletion or overwriting of files;
    • Access to paths outside the workspace;
    • Transmitting code or data externally;
    • Installing dependencies from unverified sources;
    • Operating on production resources.

    Security controls cannot rely on prompts alone. They also require execution-environment isolation, path validation, and independent authorization policies.

    7.3 Auditing Should Focus on Verifiable Actions

    Useful audit information includes tool calls, parameters, approval records, file diffs, validation results, and final status. It should not depend on the model’s retrospective description of its own behavior.

    Logs may also contain sensitive information, so they require redaction, access controls, and an appropriate retention period.

    8. A Minimal Control Loop

    The following pseudocode is independent of any particular language or tool. It illustrates the relationship among the modules:

    1. state = initialize_task(goal, acceptance_criteria, scope, budget)
    2. while state is not finished:
    3. if budget is exhausted:
    4. mark as constrained_stop
    5. break
    6. context = organize_current_evidence(state)
    7. decision = ask_model_to_select_next_action(context)
    8. if decision requires a tool:
    9. check parameters, paths, permissions, and approval requirements
    10. result = execute_tool_in_a_controlled_environment()
    11. save_structured_result(result)
    12. update state and budget
    13. check for repeated failures or lack of progress
    14. else if decision claims completion:
    15. check whether acceptance evidence is sufficient
    16. if sufficient:
    17. mark as complete
    18. else:
    19. record the gap and continue or request clarification
    20. else:
    21. request necessary information or stop safely
    22. output change_summary, validation_results, and remaining_limitations

    The key point is not the syntax. It is the separation of responsibilities: the model proposes, the execution system authorizes and runs, and validation logic checks the evidence. Completion cannot always be judged automatically. When requirements or quality involve subjective interpretation, human confirmation may still be necessary.

    9. Applying the Full Process to a Boundary-Condition Fix

    Suppose the task is to fix a data-processing function that behaves incorrectly when given empty input.

    The agent should first confirm the intended semantics: Should the function return an empty result, return a default value, or raise an explicit exception? If neither the specification nor the tests provide an answer, the agent should ask for clarification instead of deciding on its own.

    It should then use directory and symbol searches to locate the implementation, callers, and tests. At this stage, it should check whether callers already handle empty input, whether the current exception is part of the interface contract, and whether the change would alter the return type.

    After forming a hypothesis, the agent should add a test that exposes the issue before implementing the smallest necessary change. Validation should cover not only empty input, but also normal input and adjacent boundary cases, ensuring that the new branch does not break existing behavior.

    Finally, it should inspect the complete diff and confirm that there is no unrelated formatting, temporary debugging code, or accidental file change. The delivery summary should clearly state:

    • What was changed;
    • Why it was changed;
    • Which validations were run;
    • Which validations were not run;
    • Which risks still require human confirmation.

    10. How to Evaluate Whether the System Is Truly Effective

    An intelligent coding agent should not be evaluated only by the amount of code it generates or its final test pass rate. A more complete set of metrics should cover:

    • Task quality: Whether requirements are satisfied and regressions are avoided;
    • Execution efficiency: Whether tool calls, elapsed time, and resource consumption are reasonable;
    • Process reliability: Whether the agent repeatedly fails and whether it can recover correctly;
    • Evidence completeness: Whether completion claims have verifiable support;
    • Security: Whether permission and approval boundaries are respected;
    • Collaboration cost: Whether human intervention is necessary and timely.

    Comparisons between architectures should also keep the task set, base environment, permissions, and budgets as consistent as possible. Otherwise, environmental advantages may be mistaken for advantages in agent design.

    Ultimately, a reliable intelligent coding agent is more than a language model with tool calls. It is a software execution system organized around goals, state, evidence, and permissions. The model determines the potential capability ceiling; the execution system determines whether those capabilities can operate reliably in real engineering environments.