LLM Selection and Engineering Practices for Agentic Coding

    This article explores the shift from single-turn code completion to agentic coding and outlines the key capabilities required for large language models (LLMs) in agentic scenarios. It covers multi-step reasoning, tool calling stability, long context utilization, and latency management. Additionally, it provides engineering practices for building custom evaluation sets and managing context budgets to optimize model performance in real-world development tasks.

    1. From Single-Turn Completion to Agentic Coding

    Over the past two years, the primary forms of coding assistance tools have been code completion and single-turn Q&A. Developers input a requirement description, and the model returns a snippet of code whose quality is easily judged. Agentic coding is different. The model autonomously reads project files, invokes search and editing tools, executes test commands, and determines the next step based on the execution results within a loop. A medium-scale bug fix task might involve dozens of tool calls, with each turn’s output appended to the context.

    This paradigm brings two changes. First, the evaluation dimension shifts from “is the answer correct” to “can the task be fully completed.” Second, the performance bottleneck moves from single-generation speed to the total time and cost of the entire task chain. Therefore, model selection and optimization must revolve around the complete task chain rather than single-problem performance.

    2. Four Capability Requirements for Agentic Scenarios

    2.1 Multi-Step Reasoning and Self-Verification

    Agent tasks require the model to first decompose the goal and then verify step by step. In practice, allowing the model to output a more thorough reasoning process and actively run tests after modifying code can usually improve the first-pass success rate. However, longer reasoning means higher single-turn latency and greater token consumption. Teams need to balance accuracy with wait time, rather than focusing solely on one metric.

    2.2 Tool Calling Stability

    Tool calling requires the model to output structurally compliant parameters and understand error messages returned by tools. Common failures include: incorrect parameter field names, repeatedly retrying the same operation when a path does not exist, and treating overly long logs as instructions to execute. Evaluations should track the “parameter error rate” and “error recovery success rate,” as these two metrics better reflect real-world usability than overall impressions.

    2.3 Effective Utilization of Long Context

    The nominal context window of a model often differs from its actual effective utilization range. Research and engineering practices widely observe that when key information is located in the middle of a very long text, the model’s utilization efficiency may decline. Therefore, a large window capacity does not mean content can be stacked infinitely. The context window should be treated as a budget, not a container.

    2.4 Latency and Throughput

    In compute-constrained service environments, single response times can become noticeably longer. For programming scenarios requiring frequent interaction, latency directly impacts the developer’s focus and rhythm. Teams can tier tasks by complexity: use faster-responding models for minor changes requiring quick feedback, and use models with stronger reasoning capabilities for complex cross-file refactoring.

    3. Build Your Own Evaluation Set

    Public leaderboards can serve as a reference, but they mostly target single-problem solving, which has a significant gap from real engineering tasks. A more reliable approach is to sample tasks from your own codebase.

    It is recommended to cover the following types of tasks:

    • Bug fixing: Provide an error symptom and require locating and fixing it.
    • Test supplementation: Add unit tests for a specified module and ensure they pass.
    • Cross-file changes: Modify an interface definition and synchronize updates across all callers.
    • New feature integration: Add an interface or page following existing patterns.

    Record the following fields for each task:

    1. from dataclasses import dataclass
    2. @dataclass
    3. class TaskRecord:
    4. task_id: str
    5. passed_first_try: bool # Passed tests on first submission
    6. human_interventions: int # Number of manual corrections
    7. tool_calls: int # Total number of tool calls
    8. total_tokens: int # Total input and output tokens
    9. wall_time_sec: float # End-to-end time in seconds
    10. rolled_back: bool # Whether the result was rolled back

    It is recommended to run the evaluation set once a month to compare metric changes across different models or configurations. Task descriptions, initial code, and test cases must remain unchanged; otherwise, the results from two runs will not be comparable.

    4. Context Budget Management

    4.1 Split the Budget

    A single session’s context typically includes system instructions, project documentation, conversation history, tool outputs, and currently involved file contents. Teams should set approximate limits for each part. For example, if tool output exceeds a fixed number of lines, only retain the error message and its head/tail snippets; read file contents on demand rather than loading them entirely.

    4.2 Set Thresholds and Compression Strategies

    When context usage exceeds a certain proportion of the window, it should be actively handled. There are two common approaches:

    1. Compression: Summarize the conversation history into a decision log, retaining established constraints, unfinished items, and key file paths.
    2. New session: Use the summarized task state as the starting point for a new session.

    The most easily lost items during compression are constraints, such as “do not modify public interfaces” or “must be compatible with legacy data formats.” Such content should be listed separately and re-confirmed after each compression. Below is a simple budget check example:

    1. def check_context_budget(used_tokens: int, window_size: int,
    2. compact_ratio: float = 0.5) -> str:
    3. usage = used_tokens / window_size
    4. if usage >= 0.8:
    5. return "new_session" # Usage too high, suggest starting a new session with a summary
    6. if usage >= compact_ratio:
    7. return "compact" # Threshold reached, compress historical content first
    8. return "continue"