Building a Software Engineering Agent: Architecture, Governance, and Deployment

    Self-hosted software engineering agents are not another chat interface. They are controlled pipelines that combine local interaction, cloud background execution, independent review, repository memory, replaceable models, and end-to-end tracing. This article explains how to define capability boundaries, separate authoring from review, design sandboxed local and cloud execution surfaces, version review rules, use layered repository memory, and roll out permissions and observability in stages.

    Software engineering is shifting from “people driving tools” to “people defining goals, with agents executing under constraints.” An agent can read a repository, modify code, initiate review, and write conclusions back. But if it is a closed system, the team can only accept the vendor’s preset models, review criteria, integration methods, and observability. It becomes difficult to align the agent with the team’s own standards.

    The goal of self-hosting is not to rebuild a chat window. It is to build a controllable software engineering agent pipeline: local interaction, cloud background execution, independent review, repository memory, replaceable models, and tracing across the entire process.

    Define Capability Boundaries First

    A usable engineering agent should cover at least four types of actions.

    First, understanding: locate modules, dependencies, and call chains based on the task.

    Second, modification: edit in a working copy, run checks, and explain differences.

    Third, delivery: prepare change descriptions and submit them to the code hosting platform for human merge.

    Fourth, memory: preserve architectural conventions, historical decisions, and common failure points for reuse in later tasks.

    The boundaries must be equally clear. By default, the agent should have no production write access. It should not publish directly, bypass code review, or perform uncontrolled reads of secrets, billing data, or personal data. High-risk directories, migration scripts, and permission configurations should be on a manual confirmation list. Writing “what it can do” and “what it must not do” as policy is more effective than assigning blame after an incident.

    Why It Must Be Auditable and Modifiable

    What teams really need to control is behavior, not the brand of the interface. Review standards, directory conventions, comment style, test gates, model choice, and internal tools all change with the organization. Closed assistants often lock these into the vendor side: changing models requires waiting for vendor support, review rules cannot be graded by repository, logs do not show prompts, tool calls, or failure reasons, and when something goes wrong the team can only guess.

    The value of an open-source or in-house runtime is that policy, tool adapters, and tracing live in the team’s own repository. Models can be open weights or cloud inference services. Once the runtime is decoupled from the model, a large model that cannot run on a laptop can still be used through remote inference, while files, commands, and diffs remain in a controlled environment. When choosing cloud resources, standard capabilities such as object storage, container platforms, logging, monitoring, and alerting are enough to support operation. The architecture does not need to be tied to a proprietary interface. If using general cloud infrastructure such as Baidu AI Cloud, rely only on standard capabilities such as containers, storage, networking, and observability, and keep agent logic in your own code.

    Two Execution Surfaces: Local and Cloud

    A local agent is suitable for interactive programming. The command line and runtime sit on the developer’s machine and work directly against the workspace: exploring directories, making small changes, and running tests immediately. Model requests go to an inference service, and keys use local secure storage or short-lived tokens. Long-term credentials should not be written into the repository. The advantages of the local path are fast feedback and real context. The disadvantages are local resource consumption and the difficulty of copying the same task to multiple people for parallel work.

    A cloud agent is suitable for work that does not start from a terminal. A defect may come from a messaging system, a requirement from an issue tracker, a maintenance task from a scheduled job, or a manual trigger from a web entry point. The runtime pulls a specified revision in an isolated cloud environment, performs edits and checks, then pushes a branch and opens a pull request. Because the sandbox is separate from the personal desktop, multiple tasks can run at the same time without competing for the local environment. Parallelism depends on isolation: independent working directories, independent credentials, network egress allowlists, CPU and duration quotas, and temporary volumes that are destroyed on failure.

    The two paths should share the same tool protocol and policy, not two sets of prompts. Otherwise, patches produced locally and patches submitted from the cloud will silently diverge in review standards.

    Review Agents and Repository Memory

    Authoring and review must be separate. The authoring agent optimizes for “completing the task,” while the review agent optimizes for “finding errors against repository standards.” Review input should be the diff, relevant tests, and a rule checklist, not unlimited permission to modify the repository again. Rules should be versionable: security red lines, interface compatibility, error handling, prohibitions on logging sensitive fields, and test coverage expectations. Review conclusions should be written back to the pull request with supporting evidence, so humans can change rules rather than change moods.

    Repository memory addresses context decay. With only per-task retrieval, the agent will repeatedly fall into the same traps: a directory forbids new frameworks, a module must use unified error codes, or a configuration can only be injected by the pipeline. Memory is suitable for stable, reviewable facts: architecture notes, module boundaries, decision records, and common failures and fixes. Writes should include source and date, and stale entries should be downranked or archived. Memory is not a second secret prompt. It should be readable and correctable by developers. Wrong memory is more dangerous than no memory.

    Memory can be divided into three layers. In-repository documentation changes with code review and is suitable for standards. A retrieval index is suitable for interface signatures and call relationships and is updated with commits. Run summaries keep only task-level conclusions and have a retention period, avoiding the mistake of turning a failed guess into a “fact.”

    Models, Tools, and Tracing

    The model layer should remain replaceable. Interactive exploration can use a faster model, cross-module modification can use a stronger model, and review can use a more conservative configuration with lower temperature. The choice should be based on task risk and context length, not slogans. Regardless of the model, it should return structured actions through a unified adapter: read a file, apply a patch, execute an allowed command, and submit a change description. The model must not directly assemble an uncontrolled shell command.

    The tool layer should be small and strict. Read, search, limited write, and run checks in a sandbox are enough to support most tasks. Each tool should record a parameter summary, exit code, and duration. Write operations should use patches rather than full-file overwrites whenever possible, making review and rollback easier.

    Tracing is the skeleton of governance. A single task should link the trigger source, operator, repository and revision, system prompt and rule version, model identifier, each tool call, diff summary, review conclusion, and final status. Without this chain, it is impossible to answer “why did it change this file?” Trace data itself must be desensitized. Secrets and personal information must not enter log bodies. Alerts should focus on abnormal patterns: privilege-escalation paths, abnormal outbound connections, a large number of pushes in a short time, and skipped reviews.

    A thin orchestration sketch can express the flow; the important part is the stages, not a specific framework:

    1. trigger -> policy_check -> sandbox_prepare -> plan
    2. plan -> tool_loop(read/search/patch/test) -> diff
    3. diff -> review_agent(rules) -> human_gate -> pull_request
    4. each step -> trace(actor, model, tools, artifacts)

    If policy check fails, the process stops and does not enter the tool loop. If review fails, the task can be returned to the authoring agent a limited number of times. Beyond that limit, it should be handed to a human, avoiding infinite self-modification.

    Permissions, Triggers, and Human-Agent Division of Labor

    Triggers must map to identity. A command in a messaging system, an issue status change, a code platform event, and a scheduled job should all resolve into the same internal event: who initiated it, which repository, the allowed permission set, and the budget cap. Bot accounts should be separate from human accounts. Tokens should be minimized per repository and rotated regularly. Cloud sandboxes should have no production secrets by default. When internal documents are needed, use read-only, audited interfaces.

    A practical human-agent division of labor is: the agent drafts implementations, adds tests, and reviews against a checklist; humans decide whether the goal is correct, whether an interface should change, and whether to merge. The merge button should not be given to the agent. Generated code should go through the same pipeline as human patches: static checks, unit tests, and necessary integration tests. An agent is not a reason to exempt code from quality gates.

    Rollout Sequence

    Step one is local read-only exploration plus manual copy-based modification, to verify whether retrieval and explanation are reliable. Step two allows local patches, but pushes are still performed by humans. Step three introduces the cloud sandbox, starting with low-risk maintenance tasks and scheduled inspections. Step four adds an independent review agent, turning verbal rules into diffable files. Step five connects memory and cross-system triggers. At every step, add tracing and quotas before expanding permissions. Parallelism, timeouts, and retries must have upper limits so failed tasks do not saturate the cluster.

    Metrics should focus on process, not spectacle: whether tasks finish within budget, whether review identifies real defects, the ratio of manual rework, the number of privilege interceptions, and whether memory adoption reduces repeated errors. Do not substitute call counts for quality.

    Conclusion

    Self-hosting a software engineering agent is essentially about separating reading, modification, review, memory, and observability into replaceable modules, and using policy to keep them inside sandboxes and human gates. Local execution handles interaction close to the code, cloud execution handles parallel background tasks, review is separated from authoring, memory can be corrected by people, models can be replaced, and tracing must be present. With these pieces, the team does not get a black box that cannot be opened. It gets an engineering pipeline that can evolve along with its standards.