Evaluating and Reproducing LLM Agent Coding Capabilities: Failure Modes, Model Selection, and Cost Control
This article examines why strong single-turn code generation does not guarantee that a large language model can complete multi-step reproduction tasks, using a deep learning paper reproduction scenario as the reference case. It reviews four common failure modes of small-parameter models, including goal drift, uncontrolled side effects, missing root-cause analysis, and failure to close the loop. It then outlines a role-based model layering strategy, cost-control practices centered on prompt cache hit rate, sandbox and least-privilege governance, and a three-layer evaluation method covering results, process, and governance. A checklist of common pitfalls is included for teams building reproducible and observable AI coding agents.
1. Background: Why “Can Write Code” Does Not Equal “Can Complete Reproduction”
After connecting large language models to intelligent coding tools (code scaffolds or agent runtime frameworks), many teams encounter a counterintuitive phenomenon: the same model performs well on single-turn Q&A and snippet generation, but once it is handed a deep task that requires multiple steps, cross-tool coordination, and long context, completion quality drops sharply. The task in the original practice is representative: given a deep learning paper document, the model must parse the document, set up the runtime environment, handle custom data, and reproduce the code. This task is a litmus test because it stresses four capabilities at the same time:
- Document parsing and information extraction: extracting formulas, figure captions, hyperparameters, and dataset descriptions from documents with complex layouts;
- Environment engineering: installing dependencies, aligning versions, configuring network proxies, and identifying accelerator resources;
- Data engineering: cleaning, splitting, format conversion, and alignment of custom data;
- Long-chain self-correction: tracing back and fixing mistakes when commands, paths, or dependencies are wrong.
The conclusion first: smaller models (for example, lightweight versions around two hundred billion parameters) often show “no agent capability at all” on such tasks, while larger versions with stronger reasoning can get through within acceptable time and cost. This is not simply a matter of the model being “dumb,” but a difference in capability structure.
2. Failure Mode Review: Four Problems of Small-Parameter Models on Long-Chain Tasks
The first type is goal drift and ineffective exploration. In practice, lightweight models traverse large numbers of irrelevant directories and repeatedly probe paths they cannot access or that are meaningless, producing many actions that “look busy but make no progress.” In agent evaluation, this typically appears as step inflation and a low ratio of effective actions.
The second type is uncontrolled side effects. The model copies an entire remote project into the local workspace, leaving the directory structure messy and mixing temporary files with source code, so every later operation must first pay a “cleanup debt.” This shows that an agent’s output is not just text but write operations on a real file system: the greater the permissions, the larger the blast radius.
The third type is missing root-cause analysis. The real fault was this: cloning on a distributed file system with a large number of small files caused performance and consistency problems. The model chose to work around it by cloning to a temporary directory and then copying, but the copy command was wrong and pulled in the parent directory as well. Strong models can identify the root cause of “small files plus a network file system” and give a safe solution; weak models tend to stack wrong actions on wrong actions.
The fourth type is failure to close the loop. The environment does not come up, the data is not aligned, and the code does not run, yet the model still claims completion. In engineering, “verifiable completion” must be a hard constraint rather than trusting the model’s self-report.
3. Capability Layering and Model Selection: Put Each Model in the Right Place
Models can be layered by role instead of using one model for everything:
- Planning layer: requires strong reasoning and long context; responsible for task decomposition and validation planning;
- Execution layer: responsible for concrete commands and code generation; a mid-size model can be used;
- Validation layer: runs tests, compares metrics, and produces diff reports, emphasizing determinism and reproducibility;
- Lightweight layer: handles low-risk work such as summarization, formatting, and log categorization.
The comparison from practice is clear: the lightweight version failed on the same task and left the project in a mess; after switching to the larger-parameter version in the same series, the task could start and complete, taking roughly twenty minutes and costing on the order of a few RMB. For budget-sensitive teams, this shows that the pure API cost of running long tasks with a large model is already feasible, and the remaining key is the scaffold and the workflow.
4. Cost Control: Cache Hit Rate Is the Key Variable for Long Tasks
The cost structure of long-chain agent tasks differs from traditional calls: context is carried repeatedly, with a large amount of repeated prefixes. Cache hit rate therefore almost determines the bill. One notable phenomenon in practice is that some services set a very large price gap between cache misses and hits (for example, around a hundred times), while the common industry gap is usually around one order of magnitude. This means that once a hit occurs, the marginal cost of repeated context is close to zero; once it misses, cost rises significantly.
Optimization checklist for engineering teams:
- Stable prefix: put the system prompt, conventions, and directory description at the front and keep them unchanged;
- Segmented submission: place volatile content (logs, temporary results) later to avoid polluting the prefix;
- Structured context: use fixed templates to carry task state and reduce ineffective rewriting;
- Monitor hit rate: include cache hit rate and missed token count in dashboards and alerts;
- Budget guardrails: set a per-task cost cap and step cap, and pause for human confirmation when exceeded.
Illustrative policy pseudocode:
if step_budget_exceeded or cost_budget_exceeded:pause_and_ask_human()if cache_hit_rate < threshold:normalize_prompt_prefix()
5. Permissions, Sandboxing, and Side-Effect Governance: Let the Agent Run Without Running Wild
High permissions are a double-edged sword. The recommendation is least privilege plus a rollback-capable workspace:
- Workspace isolation: each task runs in a separate directory or container and is forbidden from accessing parent directories;
- Write allowlist: only allow writing files inside the project directory;
- Controlled network: access external resources through a controlled proxy to avoid arbitrary outbound access;
- Snapshots and rollback: take a version snapshot before the task starts and restore with one click on failure;
- Dangerous command interception: require secondary confirmation for recursive deletion, bulk moves, and cross-directory copies;
- File system choice: for scenarios with many small files, avoid running clone operations directly on a network file system; use a local temporary directory and then perform controlled synchronization.
6. Evaluation Method: How to Scientifically Assess a Model’s Agent Capability
Use a three-layer metric set instead of a single-point impression:
- Result layer: whether the task actually runs through (tests pass, reproduced metrics are within threshold);
- Process layer: ratio of effective actions, number of repeated actions, number of ineffective exploration steps, and whether root-cause identification is on target;
- Governance layer: number of side effects, number of privilege-escalation attempts, and whether budget and duration stay in range.
The evaluation set should cover document parsing, environment setup, data preprocessing, code reproduction, and fault injection (such as restricted network, missing dependencies, and small-file bottlenecks). Each task should have an automatically judgeable acceptance script to avoid “the model says it is done, so it is done.”
7. Common Pitfalls Checklist
- Putting a lightweight model directly on a high-privilege long task;
- No workspace isolation, causing project pollution;
- Cloning many small files directly on a network file system;
- Copy or move commands without target path validation;
- Unstable context prefixes leading to low cache hit rates;
- Looking only at API unit price, not at the actual bill from hit rate and retries;
- Missing budget and step guardrails, letting long tasks run away.
8. Conclusion
Evaluating a large model on coding and reproduction tasks cannot rely only on whether it can write a function; it must look at whether it is stable across the full chain of “document parsing, environment setup, data processing, self-correction, and closed-loop validation.” The more reliable engineering path is to layer models by role, constrain side effects with sandboxes and least privilege, control cost with cache-friendly context and budget guardrails, and measure real capability with an automatically judgeable evaluation set. If cloud hosting is needed, reproducible, observable, and rollback-capable agent engineering systems can be built on general capabilities such as object storage, container platforms, log services, and monitoring alerts; on platforms such as Baidu AI Cloud, similar practice environments can also be built based on general cloud product capabilities.
