How to Build a Controllable Software Engineering Agent

    This article explains how to build a controllable software engineering agent system, moving beyond a single coding tool toward a "software engineering agent factory." It breaks the architecture into five layers—interaction, execution, quality, context, and governance—along with two main threads: context synchronization and observability. You will see how local agents handle interactive development, how cloud agents process event-driven batch work in sandboxes, how review agents enforce codified quality gates, how codebase memory keeps context aligned with code, and how unified tracing and evaluation support continuous improvement. A phased adoption roadmap is included to help teams turn scattered experiments into a sustainable, auditable, and modifiable agent system.

    1. Why You Need an Agent Factory, Not a Single Tool

    The value of a software engineering agent is not that it can generate a snippet of code. It is that it can enter a real engineering workflow: reading code, modifying files, submitting changes, reviewing pull requests, and taking responsibility for the outcome. Once agents move from demos to production, the team’s focus shifts from “can it do the work?” to “is it controllable, reproducible, and auditable?”

    A single tool can rarely meet all of these requirements. A practical implementation looks more like a pipeline: a local agent handles interactive exploration, a cloud agent handles background batch work, a review agent enforces quality gates, codebase memory provides stable context, the model layer stays replaceable, and tracing spans every stage. Together, these components form a software engineering agent factory.

    2. Overall Architecture: Five Layers and Two Main Threads

    Break the system into five layers:

    1. Interaction layer: terminals, web interfaces, and collaboration platform entry points;
    2. Execution layer: local runtimes and cloud sandboxes;
    3. Quality layer: automated review and specification checks;
    4. Context layer: codebase documentation, indexes, and long-term memory;
    5. Governance layer: model routing, permissions, tracing, and evaluation.

    Two main threads run through all of them. The first is the context thread, which ensures the information an agent sees stays in sync with the code. The second is the observability thread, which ensures every inference, tool call, and file change can be traced and replayed.

    3. Local Agents: Keep Interaction Close to the Developer

    The core role of a local coding agent is interactive collaboration. The runtime runs on the developer’s machine with direct access to the local codebase, terminal, and debugging tools. It is well suited to exploring unfamiliar modules, quickly testing changes, performing refactors, and adding tests. The model can be hosted in the cloud, balancing local data boundaries with large model capabilities.

    Key practices:

    • Least privilege: read-only by default; write operations require explicit confirmation;
    • Revertible changes: all modifications land as patches or branches;
    • On-demand context loading: avoid stuffing the entire repository in at once;
    • Integration with local quality tools: instant feedback from formatting, static checks, and unit tests.

    An illustrative policy configuration (pseudocode):

    1. local_agent:
    2. workspace: current_repo
    3. default_mode: read_only
    4. write_requires_confirmation: true
    5. context:
    6. max_files: 20
    7. prefer: [changed_files, related_tests, module_docs]
    8. hooks:
    9. pre_commit: [format, lint, unit_test]

    4. Cloud Agents: Start Work from Events, Not Terminals

    Many engineering tasks do not begin at a terminal: a bug report appears in a collaboration platform, a requirement is logged in a task system, or a scheduled job needs periodic dependency maintenance. Cloud coding agents are a good fit for this event-driven work: triggered by an external event, executed in an isolated sandbox, and finished by submitting changes for review.

    Because they run in cloud sandboxes, multiple tasks can run in parallel without occupying anyone’s local environment or polluting each other’s dependencies. This approach naturally suits batch fixes, version upgrades, documentation completion, and low-risk repetitive work.

    General trigger and execution flow:

    1. Event intake: from a collaboration platform, task system, code hosting platform, or custom interface;
    2. Task normalization: convert the event into a clear goal, constraints, and acceptance criteria;
    3. Sandbox preparation: pull the code, install dependencies, and restore caches;
    4. Execution and self-check: modify the code and run tests;
    5. Produce changes: open a pull request with an explanation and verification records.

    5. Review Agents: Turn Standards into Executable Gates

    Review must be rigorous and tightly integrated with the code hosting workflow. A review agent should cover three categories of issues at once: correctness (logic and boundary conditions), security (input validation, secret leakage, dependency risk), and consistency (naming, directory structure, and team conventions).

    The key is that standards must be codable. The team writes review rules as configuration and scripts, and the agent produces structured feedback based on them rather than vague comments. Example:

    1. review_agent:
    2. checks:
    3. - correctness: [boundary_conditions, error_handling]
    4. - security: [secret_scan, input_validation]
    5. - consistency: [naming, module_layout]
    6. severity_levels: [blocker, major, minor]
    7. require_evidence: true # must include test or log evidence

    Review results should be graded, pinpointed to specific lines, and traceable to the rule that produced them. Only then can they genuinely serve as merge gates.

    6. Codebase Memory and Documentation: Context Must Come from the Same Source as the Code

    When an agent performs poorly, the problem is usually not the model but the context. If codebase documentation drifts away from the code, the agent will keep producing outdated conclusions. You therefore need a mechanism that keeps documentation and code from the same source: documentation is reviewed and versioned together with code changes, and its freshness is checked in the merge workflow.

    Memory can be divided into three layers:

    • Short-term memory: files, diffs, and test results for the current task;
    • Structural memory: indexes generated from module dependencies, interface contracts, and directory conventions;
    • Long-term memory: accumulated historical decisions, failure cases, and team standards.

    The engineering recommendation is to make memory invalidatable and rebuildable: every memory entry should be traceable to its source commit, and entries can be invalidated and rebuilt in bulk as the code evolves, preventing stale knowledge from polluting decisions.

    7. Observability and Evaluation: Cross-System Tracing Is the Baseline

    Unified tracing across systems is the baseline for production. Every task should record the input context summary, the model and parameters, the tool call sequence, file changes, test results, and elapsed time. With this data, teams can replay runs, locate regressions, and compare the effectiveness of different models and prompt strategies.

    The evaluation set should come from real historical tasks and include acceptance criteria and automated judgment scripts. Before rolling out a new model or new rules, run a regression on the evaluation set first, and observe pass rate, rework rate, and the number of human interventions, avoiding “it feels better” decisions.

    8. Why Controllability and Openness Matter

    If an agent is a closed system, the team is confined to predetermined models, predetermined review behavior, predetermined integrations, and predetermined observability. A safer approach is to keep the architecture open: replaceable models, editable rules, pluggable tools, and exportable traces, so the team can inspect and modify agent behavior to fit its own review standards, codebase conventions, and internal toolchain.

    1. First get a minimal loop working: local interaction + automated tests + revertible changes;
    2. Add event triggers and cloud sandboxes to take on low-risk batch tasks;
    3. Build a review rule library and graded gates, blocking high-risk issues first;
    4. Establish same-source documentation and layered memory to stabilize context quality;
    5. Unify tracing and evaluation to form a continuous improvement mechanism.

    Following this path, a team can gradually converge scattered experiments into a sustainable agent factory: keeping the agility of local development, gaining the scale of cloud parallelism, and making every automation clearly traceable, controllable, and modifiable.