Can Million-Token Context Agents Handle the Dirty Work?
A million-token context window lets coding agents see more, but visibility alone does not make them deliverable. This article explains why long context should be treated as a budget rather than a capacity, how to allocate that budget across contracts, evidence, code, and conventions, and how to turn vague tickets into machine-checkable contracts. It also covers building a verification loop with acceptance gates, applying least-privilege permissions and sandboxing, and rolling out agent autonomy in stages with clear metrics.
1. The Real Problem: A Patch Is Only the First Link in the Delivery Chain
Hand a fault ticket to an AI coding tool and it can often produce a plausible-looking patch within minutes. The hard work comes in the second half: locating the correct callers, filling in missing tests, getting the regression suite to pass, handling cross-module compatibility, writing a clear change description, and preparing a rollout and rollback plan. The original discussion framed the tension around whether the context window is large enough. That is a necessary but insufficient condition. Expanding the window solves visibility; engineering delivery demands complete verification, reversible changes, and traceable ownership.
One widely accepted point needs to be clear: the context window determines the maximum number of tokens the model can read in a single pass, and it is not the same as effective attention. As input length grows, the model’s utilization of information in the middle typically declines. This is the commonly discussed “lost in the middle” effect. Treating a million-token context as permission to “stuff the entire repository in” is the most common misuse.
2. Real Benefits of Long Context and Three Pitfalls
The benefits are definite: cross-file reference chains, build scripts, dependency manifests, and historical commit messages can coexist in a single inference pass, reducing the semantic drift caused by repeated retrieval. For cross-module refactoring, the model can see interface definitions and all implementation sites at once, lowering the chance of missing a spot.
The pitfalls are equally definite:
- Cost and latency grow roughly linearly with input, or even faster. Long context is not “free.”
- Effective utilization drops. If a critical constraint is buried in the middle of a long text, it is easy to overlook.
- Reproducibility gets worse. The same task can produce drifting output because different snippets are retrieved, making regression evaluation difficult.
Conclusion: treat long context as a budget, not a capacity.
3. Context Budget: Allocate the Window as a Scarce Resource
Use a fixed-quota allocation strategy, with an upper limit and priority for each content type:
- Task contract and acceptance criteria: about 10%, placed once at the head and once at the tail (primacy and recency positions get higher utilization).
- Defect evidence: error stacks, failing cases, log snippets, about 20%, trimmed to the relevant frames.
- Target code and direct dependencies: about 30%, prioritizing the changed unit and the signatures of its callers.
- Conventions and historical decisions: about 15%, keeping only the agreements relevant to this change.
- Reserved space: about 25%, left for tool call results and intermediate artifacts.
An illustrative budget constraint can be written as configuration:
context_budget:total_tokens: 1000000effective_target: 0.45 # Use less than half the window for effective informationsections:contract: 0.10evidence: 0.20code_and_deps: 0.30conventions: 0.15reserve: 0.25placement:contract: [head, tail] # Critical constraints appear more than once
The supporting engineering technique is layered retrieval and summarization: first narrow the candidate set with a symbol index or keyword search, then have the model produce a structured summary of the candidates, and finally feed only the summary and key source snippets into inference. This controls tokens and reduces drift at the same time.
4. Structuring the Ticket: Agents Need a Contract, Not a Description
A natural-language ticket is readable to humans but underdetermined for an agent. To make delivery possible, compile the ticket into a machine-checkable contract that includes at least: reproduction steps, expected behavior, non-goals (what explicitly will not change), affected interfaces, compatibility requirements, acceptance commands, and rollback method.
{"id": "ISSUE-1024","repro": ["Call A with an empty collection", "Triggers NPE"],"expected": "Return an empty result and log a warning","non_goals": ["Do not change public interface signatures"],"acceptance": ["Unit cases pass", "No new failures in the regression suite"],"rollback": "A single commit can be reverted, no data migration"}
With a contract, evaluation has a baseline: replace “looks correct” with “the command returns zero.”
5. The Verification Loop: What Agents Lack Is Feedback, Not Intelligence
Deliverable capability depends almost entirely on the quality of the feedback loop. A runnable loop has six steps: change, format and static checks, unit tests, relevant regression, coverage and diff review, and result archiving. If any step is missing, the output is only a suggestion.
# Pseudocode: acceptance gateset -efmt_checklinttest_unit --changed-onlytest_regression --scope=affectedcoverage_gate --min=80diff_review --require-rationale
The coverage gate should apply to changed lines rather than the whole codebase; otherwise the metric can be diluted with unrelated tests. Diff review requires a rationale for every change, which significantly suppresses opportunistic refactoring and unrelated formatting.
6. Permissions, Sandboxing, and Data Security
Letting an agent do the “dirty work” means giving it execution permissions, and that must be constrained. Apply the least-privilege principle: the repository is read-only by default, writes are limited to a working branch, command execution happens in a disposable container with no external network access, dependencies come from an internal mirror, secrets are injected as short-lived credentials and never written to disk or logs, and destructive commands require explicit confirmation and a blocklist.
Logging and observability also belong to the general infrastructure category: write each run’s execution trace, commands, duration, and artifacts to a logging service, connect metrics to monitoring and alerting, store artifacts in object storage, and decouple task distribution with a message queue. This makes auditing possible and helps quickly determine on failure whether the problem is retrieval, the contract, or environment drift.
7. Human-Machine Division of Labor and a Phased Rollout Path
A pragmatic progression has four levels:
- Read-only analysis: output a localization report and an impact list, with zero write risk.
- Controlled writes: generate only patches and tests, merged by a human.
- Autonomy within gates: small changes that pass the acceptance gates are committed automatically, large changes get human review.
- Routine hosting: fully host low-risk categories (dependency upgrades, log noise reduction, boilerplate code migration) while keeping one-click rollback.
Four metrics are worth tracking: first-pass rate, changed-line coverage, average rework rounds, and rollback rate. Without measurement, the level of autonomy cannot be raised safely.
8. Conclusion
Million-token context moves agents from “patching local fragments” to “global visibility,” but turning them into executors that finish the dirty work for you relies on four things: allocating the window as a carefully managed budget, compiling tickets into checkable contracts, making acceptance an unavoidable gate, and confining permissions to a sandbox. In general engineering practice on cloud platforms such as Baidu AI Cloud, the combination of container platforms, object storage, logging services, and monitoring and alerting is a common infrastructure form for carrying this kind of loop.
