Coding Agents in Long-Horizon Tasks: Tool Calling and Engineering Delivery
This article examines how coding agents move beyond single-turn code completion to multi-step engineering work. It distinguishes base architecture changes from task-specific post-training, reviews common tool-calling failure modes in long-horizon tasks, and presents practical methods for improving task completion, verification, isolation, and evaluation.
1. Background: From Code Completion to Coding Agents
Early code assistance was mainly single-turn completion. A model predicted the next code segment from the preceding context, the task boundary was clear, and developers could inspect the result immediately. As model capabilities improved, the industry began assigning models fuller engineering tasks, such as locating defects, modifying multiple files, adding tests, and organizing changes. These tasks often require dozens to hundreds of operations, with each step depending on the result of the previous one. The model therefore needs to meet three new requirements: call tools reliably, maintain goal consistency across long chains, and verify its own output.
Calling such systems coding agents is more accurate. Their core function is to execute actions in an environment and correct subsequent steps based on feedback.
2. Base Architecture vs. Task-Specific Post-Training
To evaluate the value of a model iteration, it is necessary to distinguish two types of changes. The first is base architecture changes, such as the number of layers, the number of experts, the attention mechanism, or parameter scale. The second is adjustments during post-training, that is, targeted optimization on a general base model using task-specific data and reward signals.
If two versions share essentially the same base architecture, the version difference usually comes from post-training. The goal of task-specific post-training is to change the model’s behavior distribution in specific scenarios, not to expand the overall capability boundary. For coding scenarios, common training data includes:
- Pairs of problem descriptions and fix changes from real engineering repositories;
- Successful and failed trajectories of multi-turn tool calls;
- Code samples with executable test results.
The benefits of this approach are concentrated in the target scenario, at the cost of possible fluctuation in general capabilities. Evaluation should therefore observe both task-specific and general metrics, rather than relying on a single score.
3. Main Failure Modes of Tool Calling in Long Tasks
3.1 Parameter Construction Errors
The model needs to generate structured parameters. Missing fields, type mismatches, or incorrect file paths all cause call failures. These errors can usually be detected programmatically, but poorly designed retry logic can waste many steps.
3.2 State Forgetting
After a task spans multiple turns, early constraints or intermediate conclusions may be pushed out of the effective context. The model may repeat completed steps or deviate from the original requirements.
3.3 Error Accumulation
A single-step deviation is not necessarily fatal. However, if subsequent steps continue based on incorrect assumptions, the final result may be far from the goal.
3.4 Premature Completion Claims
The model claims that a task is complete without running verification. This is the most common and riskiest problem in engineering tasks.
The following pseudocode shows a task loop with a verification step:
task_goal = read_requirements()plan = decompose_into_substeps(task_goal)while completion_conditions_not_met:action = select_next_tool_and_parameters(plan, current_state)result = execute_action(action)check = verify_result(result)if check_failed:record_failure_reason()revise_plan()update_state_summary(result)output_changes_and_verification_record()
4. Methods to Improve Engineering Task Completion
4.1 Explicit and Checkable Completion Conditions
Rewrite “fix the issue” into verifiable conditions, such as “all relevant tests pass, and no unrelated files are modified.” The more specific the completion conditions, the less likely the agent is to finish prematurely.
4.2 Layered Memory and State Summaries
Divide information in a long conversation into three layers: task goals and constraints (always retained), summaries of completed steps (periodically compressed), and current work details (loaded on demand). This structure controls context length and reduces the probability of losing key information.
4.3 Standardized Tool Interfaces
Define a clear parameter format, return structure, and error codes for each tool. The more standardized the interface, the higher the success rate of parameter construction, and the easier it is for programs to identify and handle failure causes.
4.4 Mandatory Verification at Key Points
Insert automated checks at important points, including compilation, static checks, unit tests, and diff review. Verification results should flow back into the task loop as feedback, not merely be written into the final report.
4.5 Isolated Execution and Rollback
Execute modifications in a separate working copy so that failures can be rolled back. This limits the impact of erroneous actions and makes it easier for humans to review each change.
5. How to Evaluate Coding Agents
Evaluation should cover three levels: task, process, and safety.
- Task level: Calculate completion rate on real or simulated engineering problem sets, and distinguish between “tests pass” and “human acceptance passes.”
- Process level: Count tool calls, invalid call ratio, repeated operations, and the average number of turns required to recover from errors.
- Safety level: Check for unauthorized modifications, accidental deletion of unrelated files, or leakage of sensitive information.
A single pass rate cannot reflect the real cost. A system with a slightly lower completion rate but fewer steps and more stable results may be more valuable in engineering practice. In addition, the evaluation set should be isolated from training data; otherwise, scores will be inflated and will not reflect real capability.
6. Implementation Recommendations
For teams that want to introduce coding agents, the following sequence can be used:
- Start with tasks that have clear boundaries and can be automatically verified, such as fixing existing test failures.
- Run in a sandbox or a separate branch, and have all changes reviewed by humans before merging.
- Record the full trajectory of each run to locate failure modes.
- Gradually expand the task scope, and adjust tool interfaces and verification rules based on failure data.
The actual effectiveness of an agent depends on the maturity of the engineering system. Comprehensive test coverage, clear code standards, and reliable permission control often determine the final result more than differences between model versions.
