A Complete Guide to Building In-House Software Engineering Agents
This guide explains why teams self-host software engineering agents instead of using closed products, then covers a five-role architecture, observability, local and cloud agents, review agents, repository memory, and a staged rollout—without changing the original technical conclusions.
1. Why build in-house instead of using a closed product
Software engineering agents already cover three basics: reading code, changing code, and joining review. Whether they belong in production engineering depends less on raw model skill and more on whether the team can understand and constrain how they behave.
A closed system typically hits four walls: you are limited to the vendor’s models; review criteria are preset and may not match internal standards; it is hard to plug in your own toolchain; and execution is poorly observable, so failures are hard to replay.
The point of self-hosting is control, not “more advanced tech.” Teams should be able to inspect prompts and policies, change behavioral bounds, swap the underlying model, attach their own static analysis and tests, and record every run. That is why related components are chosen as open source: openness is a prerequisite for change, not a slogan.
2. Architecture: five roles and one observability path
A usable system can be described as five cooperating roles:
| Role | Where it runs | Main job |
|---|---|---|
| Local coding agent | Developer machine / terminal | Interactive exploration, immediate edits, run verification |
| Cloud coding agent | Cloud sandbox | Long background jobs, event triggers, automatic change submission |
| Review agent | Cloud or pipeline | Automated review and policy checks |
| Repository memory | Shared storage | Documented context and long-lived knowledge |
| Open-source model | Cloud or private environment | Inference and generation; replaceable |
On top of that you need a trace path across every system: local sessions, cloud jobs, review results, and memory retrieval all report to one tracing backend, forming a full trail of input → retrieval → tool calls → output. Without it, a multi-agent setup quickly becomes an undebuggable black box.
Illustrative routing (pseudocode for structure only):
agents:local:runtime: terminalmodel: local_or_hostedscope: interactive_editcloud:runtime: sandboxtriggers: [chat_tool, issue_tracker, code_host, web_ui, schedule]output: pull_requestreview:runtime: pipelineinputs: [diff, repo_memory]policy: team_lint_rulesobservability:tracer: unified_backendspan_scope: [local, cloud, review, retrieval]
3. Local terminal agent: keep interaction cheap
The local agent runs on the developer machine; the model may still be hosted remotely. Splitting “runtime local, inference remote” matters: developers work in a real workspace with real dependencies and debuggers, while using models that would not fit on the laptop.
Fit: high-frequency, short-cycle work that needs human confirmation—finding logic in the terminal, mechanical refactors, generating a patch from a description and running tests immediately.
Engineering notes:
- Least privilege: read-only by default; writes and command execution need explicit confirmation to avoid accidental edits and deletes.
- On-demand context: send related files and symbols, not the whole repo.
- Verification loop: after edits, auto-run formatters, static checks, and unit tests so “looks right” becomes “checked right.”
4. Cloud coding agent: start from events, not the terminal
Many tasks do not start in a terminal: a defect in chat, a requirement in the tracker, scheduled repo maintenance. The cloud agent turns those events into deliverable changes.
Triggers can include chat commands, tracker state changes, comments or labels on the code host, a web console, and schedules. Work runs in an isolated cloud sandbox; when done, it opens a change request with notes and verification records for human merge.
Sandboxing gives two gains:
- Parallelism: many jobs at once, without sharing anyone’s laptop;
- Reproducibility: a clean environment each time, avoiding “works locally, fails elsewhere.”
Practical limits: cap resources and duration, restrict which repos are reachable, require build and tests before submit, and require human review of automated changes.
5. Review agent: make “careful” into executable rules
Review is easy to undervalue and high leverage. Human standards drift with fatigue and time; a review agent can freeze the bar.
Split “rigor” into checkable items: correctness risk (boundaries, concurrency, error handling), security (input validation, hardcoded secrets, dependency risk), consistency with existing abstractions and naming, maintainability (complexity, duplication, test coverage), and team-specific rules (commit messages, comments, layout).
Standards must come from the team’s own rule files and past review comments, not an external default. Control noise: separate “must fix” from “discuss,” so low-value comments do not bury real risk.
6. Repository memory and docs: the agent’s main context
Weak agent behavior is usually missing context, not a weak model. Repo docs should evolve with the code and serve the agent, not sit as an afterthought for humans.
At least four kinds of material: architecture and module boundaries, decision trade-offs, how to build and test, and team conventions and no-go zones. Keep docs next to code and review them with changes so they do not become stale archaeology.
Retrieval can mix strategies: structured indexes on symbols and paths for precision, vector search for semantic similarity, then rerank for relevant snippets. Sketch:
def build_context(query, repo_index, vector_store, k=8):lexical = repo_index.search(query, top_k=k) # precise: symbols/pathssemantic = vector_store.search(query, top_k=k) # fuzzy: semantic similaritymerged = rerank(lexical + semantic, query)[:k] # rerank to drop noisereturn {"snippets": merged, "conventions": repo_index.team_rules()}
Govern memory: update when code changes, mark trust and freshness, and drop stale entries, or bad memory will keep polluting output.
7. Observability: unified tracing across systems
When local, cloud, review, and retrieval run in different systems, one tracing backend must join a task with a single trace id. Core fields: trigger source, retrieved context, model and parameters, tool-call sequence, latency and failure reasons, and final artifacts.
Then the team can ask: was a bad edit missing context or a bad prompt? Is review noise strict rules or model error? Which model works better on this repo? That is the base for model swap, cost accounting, and quality regression.
8. A staged rollout
- Stand up memory first: docs and indexes so context is retrievable—fastest payoff.
- Ship the local agent: start read-only, then controlled writes and auto-verification.
- Add cloud triggers: one entry (for example the issue tracker), close the loop event → sandbox → change request.
- Add the review agent: deterministic checks from team rules, then semantic review, steadily cutting false positives.
- Unify tracing and eval: an offline set of real historical tasks to regress every model and prompt change.
Three common traps: too little context (hallucinated edits), too much privilege (irreversible changes), no traces (tuning by gut). Constrain them early and later expansion is easier.
9. Closing
Self-hosting software engineering agents means handing repeatable, rule-clear parts of the workflow to a system you can inspect, change, and observe, while people keep judgment and merge rights. Five roles, a memory layer for context, a trace path for transparency, and replaceable open-source models give the team its own “agent factory”: it can run background work in parallel and apply the team’s own bar in every review. For cloud sandboxes, unified logs, and monitoring/alerting, general-purpose offerings such as Baidu AI Cloud can be used without binding to a proprietary agent API.
