LLM Coding Agents: From Code Generation to Engineering Execution
This article explains why long context alone is not enough for LLM coding agents. It covers terminal task execution, repository-level engineering challenges, the limits of ultra-long context, and practical patterns such as retrieval, staged execution, and sandboxed runtimes.
Longer context is not always better. When large models perform programming work, retrieval, staged execution, and a secure runtime environment are the factors that truly determine effectiveness. This article discusses these three areas.
1. From Code Generation to Task Execution
In the past, programming models were evaluated mainly by whether they could write syntactically correct functions with sound logic. As engineering requirements have become more complex, industry attention has shifted toward terminal task execution capability. Public evaluations such as Terminal-Bench ask models to complete end-to-end tasks in real terminal environments, such as installing dependencies, modifying configurations, running tests, and fixing failures.
When reading such leaderboards, keep two points in mind. First, scores from different evaluation sets, model versions, run scripts, and run counts cannot be compared directly. Second, a difference of a few percentage points on a leaderboard may not produce a noticeable difference in a real project. Therefore, when comparing models, verify the specific evaluation conditions or test them with tasks from your own project.
Specifically, models that can be used for engineering execution usually have the following three capabilities:
| Capability | Observable behavior | Checkpoint | Failure handling |
|---|---|---|---|
| Requirement understanding and translation | Convert natural language requirements into commands or code scripts | Whether the output commands match the actual project structure | Ask the model to restate the requirements before execution |
| Toolchain invocation | Invoke version control, testing frameworks, and package managers | Whether the parameters and return values of each call are correct | Limit available tools and open them gradually |
| Error capture and recovery | Read error logs, analyze causes, adjust, and retry | Whether the retry targets the real cause | Set a maximum retry count and hand over to a human after it is exceeded |
Only when these three capabilities are connected do they form a complete execution loop. A model that can only generate code cannot achieve this, because it cannot judge whether the code can run, nor can it correct its output based on runtime results.
2. Three Difficulties in Repository-Level Engineering Execution
The correctness of a single function does not represent how a model will perform in a large code repository. After entering a real project, three problems are most likely to surface.
The first is cross-file modification. Modern software is mostly modular or based on microservices. A seemingly simple requirement change may involve interface definitions, business logic, and the data access layer at the same time. An agent needs to trace function call chains and data flows; otherwise, it is easy to change one place and miss another.
The second is regression risk. When modifying old code, the most common problem is fixing one defect while breaking another function. An agent should run unit tests and integration tests before and after the modification and use test results, rather than its own judgment, to confirm whether the change is safe. If a project lacks tests, the risk of agent modifications increases significantly. In this case, tests should be added first before letting the agent make changes.
The third is context stability. In multi-turn conversations and continuous tool calls, the task objective may gradually drift. The longer the context, the easier it is for the model to forget initial constraints, such as “do not modify public interfaces.” Writing task objectives and constraints as fixed instructions and re-providing them at the start of each stage can mitigate this problem.
3. The Boundaries of Ultra-Long Context
Many models or services now support million-token input windows. For materials such as large codebases, long technical documents, or multiple financial reports, long windows can indeed reduce manual splitting and stitching work. However, the supported window length and the length a model can actually use well are two different things. Available windows, pricing, and latency vary greatly across providers and deployment methods. Specific parameters should be based on official documentation and your own testing.
Long context has three main limitations.
Being able to read is not the same as being able to use accurately. Models tend to make weaker use of information in the middle of long texts, a phenomenon often called “Lost in the Middle.” Placing key evidence at the beginning or end of the context, and performing segmented retrieval and reranking on middle content, can mitigate this problem but cannot eliminate it.
Multi-step reasoning is prone to contradictions. The more material there is in the context, the more attention is dispersed during multi-step reasoning, and conclusions may become inconsistent. For tasks that require rigorous reasoning, the reasoning process should be split into small steps, with only the necessary material provided at each step.
Computational cost rises rapidly with length. The computational cost of standard self-attention grows quadratically with sequence length, that is, O(n²). Actual latency and cost are also affected by KV caching, parallel strategies, and inference framework optimizations, so they cannot be estimated by formula alone. They should be measured on your own workload.
Therefore, putting an entire code repository directly into the context is usually not the optimal approach. It is both expensive and slow, and it reduces the probability that key information will be used correctly.
4. Practical Recommendations for Complex Engineering Tasks
Based on the analysis above, the following three recommendations can be implemented in order.
1. Retrieve first, then feed. Use a combination of vector retrieval and keyword retrieval to first recall candidate files relevant to the task, then use a reranking model to select the most relevant snippets, and finally provide only these snippets to the model. There is no universal value for the number of retrieved items (Top-K). It is recommended to start with a small number and adjust gradually based on task success rate.
2. Execute in stages, with acceptance criteria for each stage. Split complex tasks into five stages: analyzing the current state, writing a plan, modifying code, running tests, and reviewing. Check clear criteria at the end of each stage. For example, after the modification stage, unit tests and interface tests must pass before proceeding to the next stage. In this way, even if an error occurs in the middle, its impact is limited to the current stage.
3. Run the agent in a secure sandbox. Because an agent executes commands, the runtime environment must be isolated. Enterprises can choose their own Kubernetes clusters or use container services provided by any cloud provider. The key requirements are isolation, logging, and resource quotas. The specific choice should be evaluated according to the enterprise’s compliance requirements; this article does not recommend specific products. Regardless of which option is chosen, at least the following five measures should be implemented:
- Least privilege: Open only the directories, networks, and commands required for the current task, and deny access to production environments and sensitive configurations by default.
- Data masking: Remove secrets, personal information, and customer data before code and logs enter the context.
- Operation auditing: Record the command, parameters, return results, and duration of each tool call so that issues can be traced.
- Failure rollback: Complete all modifications in a separate branch or working copy first. Automatically roll back when tests fail, and do not modify the main branch directly.
- Cost alerts: Set limits on token count and runtime for each task, automatically pause when limits are exceeded, and notify the person responsible.
5. Common Mistakes
In practice, the following types of mistakes occur frequently and are worth avoiding in advance.
- Stuffing everything into the context. This increases cost and latency and also causes key information to be ignored.
- Task granularity that is too large. Asking an agent to refactor an entire module at once makes it difficult to locate the cause when it fails.
- Relying only on the model’s self-report. The model saying “completed” does not mean the function is correct; test results must be the standard.
- No rollback strategy. Once an agent breaks the code, without a backup, recovery can only be done manually.
- Treating leaderboard scores as project performance. There is a gap between public evaluations and specific projects, so you should validate with your own tasks.
Conclusion
New-generation large models can already complete a fair amount of practical work in terminal task execution, but they are still far from “out of the box.” Long context can expand the readable range, but it cannot replace precise retrieval. Agents can speed up execution, but tests and sandboxes are needed to constrain risk. Developers should first clarify the model’s capability boundaries, then incorporate it into engineering workflows through retrieval, staged execution, and secure isolation. Only in this way can large models truly become tools that improve R&D efficiency.
