Can Million-Token Context Agents Handle Dirty Work in Software Engineering?
This article examines why generating a patch is only the first step in software delivery, and why a million-token context window is a necessary but insufficient condition for autonomous agents. It breaks down the real benefits of long context alongside three hidden costs—attention dilution, latency, and cache invalidation—and introduces a layered context assembly strategy. It also outlines a five-step verification loop, long-term memory design, tool orchestration with least-privilege governance, and an outcome-based evaluation system for agents that take over repetitive engineering work.
1. The Bottleneck Is Not Writing a Patch, but Delivering a Result
Hand a ticketing tool to an AI coding agent, and it can often produce a plausible-looking patch within minutes. The hard work comes afterward: locating the right code, understanding why past changes were made, filling in missing tests, reproducing the issue across multiple runtime environments, assessing the impact on existing functionality, and explaining the process clearly enough for review. This is the core tension: generating code is only the first link in the chain, while engineering delivery is a long pipeline of understanding, verification, collaboration, and rollback.
As open-weight models push context windows to the million-token scale, a natural expectation emerges: stuff the repository, logs, and documentation all into the window, and the agent will “just get it done.” Engineering practice tells us otherwise. Context length is a necessary condition, not a sufficient one. A larger window solves visibility; delivery depends on locating accurately, verifying reliably, and explaining clearly.
2. Real Benefits of Long Context and Three Hidden Costs
The benefits of long context are clear: cross-file call chains stay coherent within a single inference pass; large-scale refactoring does not require repeated summarization that causes semantic drift; and debugging can hold stack traces, configuration, and recent commits at the same time.
The hidden costs are equally obvious.
First, attention dilution. The more information there is, the higher the chance that a critical clue gets buried, and the model may latch onto an irrelevant log line and reason about it at length.
Second, cost and latency. Increasing context length typically raises prefill overhead, and the waiting time in interactive scenarios becomes more noticeable.
Third, caching and consistency. Long context often relies on prefix caching to reduce cost, but once new information is inserted midway, the cache hit is invalidated and the actual cost goes up instead.
The right approach is therefore not “stuff everything in,” but “assemble dynamically per task.”
3. Context Engineering: Turning “Long” into “Accurate”
A layered assembly strategy is recommended:
- Baseline layer: project conventions, directory structure notes, build and test entry points, kept to roughly a thousand words;
- Task layer: files, interface definitions, and failing cases strongly related to the current ticket;
- Retrieval layer: on-demand recall of historical issues, design documents, and similar changes via hybrid keyword and vector retrieval;
- Ephemeral layer: command output and stack fragments from the current round, discarded after use.
The assembly logic can be sketched as:
def build_context(task, repo_index, budget=200_000):parts = [BASELINE_CONVENTIONS, repo_index.tree_summary()]parts += retrieve_relevant_files(task, repo_index, top_k=12)parts += retrieve_similar_history(task, repo_index, top_k=5)parts.append(task.failing_logs[-200:]) # Keep only the critical tail of the stackreturn fit_to_budget(parts, budget) # Trim by layer when over budget
Pairing this with a “conclusion first, details second” prompt structure—having the model output localization hypotheses and a verification plan before expanding into code—can significantly reduce the chance of going off track.
4. From Patch to Delivery: The Verification Loop You Must Close
Reliable automation must build verification in, rather than trusting the model’s self-report that it is “done.” A minimal loop has five steps:
- Reproduce: run the failing case in an isolated environment and confirm the issue is real;
- Localize: output the affected call chain and responsible module, with evidence line numbers;
- Modify: keep changes minimal, and forbid opportunistic refactoring of unrelated code;
- Verify: run unit tests, static checks, and key regression cases;
- Attribute: if verification fails, read the output and iterate, escalating to a human after at most N rounds.
Pseudocode example:
loop attempt in 1..N:patch = agent.propose(context)result = sandbox.apply_and_test(patch)if result.passed: return deliver(patch, result.report)context = context + summarize(result.failure)escalate_to_human(context, attempt)
The engineering point here is sandbox isolation and rollback capability: all changes happen in a containerized environment and are discarded on failure, avoiding contamination of the main branch.
5. Memory and Knowledge Retention: Making the Second Time Cheaper
A single task relies on context; long-term efficiency relies on memory. Three types of memory should be managed separately: code facts (module responsibilities, interface contracts) maintained by an indexing service; decision memory (why a change was made this way, which options were rejected) stored as structured entries; and failure memory (which attempts did not work) used to avoid repeating the same mistakes. Writes must be validated so that wrong conclusions are not solidified into “facts.”
6. Tool Orchestration and Permission Governance
The agent’s real leverage lies in tools: reading files, running tests, querying monitoring metrics, and reading or writing tickets. Orchestration should follow the least-privilege principle: write operations require a second confirmation, and high-risk actions (deletion, release, permission changes) are prohibited by default. All tool calls should be logged to form an auditable trail. If combined with common general-purpose capability categories on Baidu AI Cloud, object storage can hold build artifacts, a message queue can decouple tasks, a container platform can host sandboxes, and logging and monitoring services can provide observability—upgrading “it runs” to “it is operable.”
7. Evaluation: Do Not Measure by “Does It Look Right”
Evaluation should be outcome-oriented: first-pass rate, average number of iterations, human takeover rate, regression introduction rate, cost and latency per task. It is advisable to build a fixed benchmark set of tickets and run a regression on every model or prompt change to prevent capability regression.
8. Conclusion
Million-token context and open weights lower the barrier, but they do not automatically remove the complexity of dirty work. Turn long context into layered assembly, embed generation in a verification loop, distill experience into verifiable memory, and write permission constraints into the tool layer—only then can agents reliably take over repetitive labor in real engineering.
