LLMs for Coding Agents: Real-World Evaluation and Cost Analysis

    Evaluating an LLM for a coding agent requires more than measuring code generation speed. This article examines code understanding, context management, task planning, reliability, and total cost, then outlines a practical workflow for repository retrieval, patch generation, testing, and human review. It also explains how to measure engineering performance and control security risks, permissions, and spending.

    While recently refactoring a collection of automation scripts, I reassessed the practical value of large language models in software development. Many earlier models performed well at straightforward code generation and function completion. In real projects, however, their limitations became more apparent: they lost track of dependencies as context grew, lacked a coherent plan for changes spanning multiple files, and struggled to follow an investigation through successive error logs. Developers ultimately had to take over.

    The central question is no longer whether a model can write a piece of code. It is whether it can support a reasonably complete engineering workflow: understand a project’s structure, analyze requirements, locate problems, propose changes, generate patches, run validation, and iterate on test results.

    1. Evaluate More Than Generation Speed

    For coding agents, model quality should be assessed across at least five dimensions.

    Code understanding

    A model needs to understand more than individual files. It must recognize calls between modules, the purpose of configuration files, data flows, and existing error-handling strategies.

    Code that looks correct in isolation may fail inside a project—not because of syntax errors, but because it violates architectural constraints.

    Long-context handling

    Medium-sized and large projects typically contain multiple directories, configuration files, tests, and runtime logs. If a model can process only a small amount of material, developers must manually select its context. That takes time and can leave out important clues.

    A larger context window reduces the need to split information into smaller pieces. However, a large window does not guarantee that the model will use every detail accurately. Inputs still need structure and prioritization.

    Task planning

    Complex requirements rarely fit into a single generation step. Adding authorization checks, for example, may require changes to routing, business logic, data models, configuration, tests, and documentation.

    The model should break the task down and work through dependencies rather than immediately produce a large block of unverified code.

    Output consistency

    If repeated calls for the same task produce substantially different results, integrating the model into an automated workflow becomes difficult.

    Consistency matters not only in written responses but also in the scope of file changes, interface formats, error handling, and testing strategies.

    Total cost

    Cost extends beyond input and output tokens. It also includes failed attempts, repeated context transmission, human review, test environment execution, and maintenance caused by incorrect changes.

    A model with a low per-call price can be more expensive overall if it frequently requires rework.

    2. Build a Measurable Cost Model

    When estimating model usage costs, separate input, output, cache usage, and retries.

    A basic calculation is:

    1. Cost per call =
    2. Input tokens × Input unit price
    3. + Output tokens × Output unit price
    4. + Cache-read tokens × Cache-read unit price

    Input tokens and cache-read tokens should be counted in their respective billing categories rather than counted twice.

    For a task that takes an average of three interaction rounds, extend the calculation to include the full workflow:

    1. Total task cost =
    2. Average cost per call × Average number of calls
    3. + Failed-attempt retry costs
    4. + External tool execution costs
    5. + Human review costs

    Inputs typically include system prompts, repository summaries, relevant source code, conversation history, and tool results. Outputs may include analysis summaries, modification plans, code patches, test commands, and final explanations.

    Coding agents often consume more input than ordinary question-answering applications because each round may carry substantial project context.

    The most effective way to reduce cost is not simply to shorten outputs. It is to eliminate irrelevant context.

    Useful approaches include:

    1. Build a project index first. Include only the directory structure, module summaries, and key interfaces in the initial context.
    2. Load files dynamically. Select files according to the task rather than sending the entire repository on every call.
    3. Cache stable content. Use caching for system prompts and project descriptions that remain unchanged.
    4. Plan before generating code. Ask the model for a modification plan, confirm the scope, and then generate the patch.
    5. Summarize test failures. Retain stack traces, error locations, and relevant environment details rather than sending all test output.
    6. Batch repetitive work. Group similar tasks to reduce the fixed overhead of many small requests.

    3. A Larger Context Window Is Not Always Better

    Long context can improve code analysis, but indiscriminately sending every file creates three problems.

    First, it increases noise. Unrelated legacy code, generated files, and third-party dependencies can distract the model from the current requirement.

    Second, it disperses attention. Even when the context window is large enough, the model may not give every section equal weight. Important constraints buried in ordinary code can still be overlooked.

    Third, it increases cost. Repeatedly transmitting large sets of files consumes input resources, particularly during multi-round editing.

    A better approach is to organize context into layers:

    • Layer 1: Project goals, language versions, execution instructions, and core constraints.
    • Layer 2: Directory structure, module responsibilities, and public interfaces.
    • Layer 3: Source files directly relevant to the current task.
    • Layer 4: Test results, logs, and records of previous changes.

    Load additional files when the model needs to investigate a particular module. This mirrors how developers read unfamiliar code: establish the overall structure first, then inspect the relevant details. It is generally more reliable than providing everything at once.

    4. Use a Structured Workflow for Reliable Coding Agents

    A practical coding agent should do more than forward a user’s request to a model. It should follow an explicit state machine.

    Step 1: Parse the requirements

    Convert the natural-language request into task objectives, affected areas, constraints, and acceptance criteria.

    Step 2: Retrieve relevant repository content

    Use file indexes, keyword searches, symbol searches, or dependency analysis to identify potentially relevant files.

    Step 3: Create a modification plan

    Ask the model to list the files it intends to change, the reasons for each change, potential risks, and validation methods. Avoid editing code at this stage where possible.

    Step 4: Generate a patch

    Structured patches are easier to review than complete rewritten files and help reduce unrelated changes.

    Step 5: Run automated validation

    At a minimum, run syntax checks, static checks, unit tests, and any necessary integration tests.

    Step 6: Feed failures back into the workflow

    Return test failures to the model so it can revise its changes based on actual results rather than continue editing on assumptions.

    Step 7: Require human approval

    Changes involving database schemas, authorization logic, production configuration, or data deletion must pass through a human approval checkpoint.

    The workflow can be summarized as follows:

    1. Requirement input
    2. ↓
    3. Task breakdown
    4. ↓
    5. Relevant file retrieval
    6. ↓
    7. Modification plan
    8. ↓
    9. Patch generation
    10. ↓
    11. Automated testing
    12. ↓
    13. Failure analysis and iteration
    14. ↓
    15. Human review and merge

    5. Test Whether a Model Is Ready for Engineering Work

    Simple prompts such as “write a function” are not enough to evaluate a coding model. A more useful test set should cover realistic development workflows.

    Examples include:

    • Locate a defect that spans multiple files in an unfamiliar project.
    • Add parameter validation and error handling to an existing interface.
    • Fix a regression using failed-test logs.
    • Refactor duplicated logic into a shared module.
    • Add unit tests to legacy code.
    • Change configuration without disrupting the existing deployment process.
    • Read incomplete business logic and implement missing edge-case handling.

    Track quantitative metrics such as:

    • First-pass success rate.
    • Average number of repair rounds.
    • Number of files modified.
    • Proportion of unrelated changes.
    • Change in test coverage.
    • Average response time.
    • Cost per task.

    First-pass success rate is particularly important. If a model consistently needs several rounds of human correction, it may be capable of generating code without being reliable enough for automation.

    6. Engineering Issues That Low-Cost Deployments Often Overlook

    Context security

    Repositories may contain credentials, user data, and internal configuration. Identify and redact sensitive information before sending code to a model. Production credentials must never be placed directly into prompts.

    Permission controls

    A coding agent should not have unrestricted file-write access, command execution privileges, or network access.

    Use workspace isolation, command allowlists, read-only modes, and approval mechanisms to limit what the agent can do.

    Traceability

    Record the task description, supplied context, model outputs, executed commands, and test results for each change.

    These records make it possible to determine whether a failure came from misunderstood requirements, missing context, or unsuccessful tool execution.

    Budget controls

    Set per-task limits for input length, output length, and iteration count, along with daily spending limits.

    When a task fails repeatedly, hand it over to a developer rather than allowing the system to retry indefinitely.

    Conclusion

    The value of newer LLMs in coding agents extends beyond writing a few lines of code. They can increasingly participate in requirement analysis, repository retrieval, solution design, and automated validation.

    Stronger model capabilities, however, make engineering safeguards more important—not less. A reliable implementation treats the model as an automation component with reasoning capabilities, not as a fully autonomous developer.

    For individual developers, code search, test generation, log analysis, and narrowly scoped patches are sensible starting points. Teams should prioritize context management, permission isolation, evaluation datasets, cost monitoring, and human approval workflows.

    Combining model capabilities with cost discipline and established software engineering practices is what makes productivity gains sustainable without introducing uncontrolled spending or avoidable damage from incorrect changes.