AI Coding Agents: How LLMs and Execution Layers Divide Responsibilities

    This article separates the LLM’s reasoning role from the coding agent’s execution layer and explains how the two work together. It covers model capability boundaries, the agent loop, token-based cost accounting, permission and security boundaries, practical methods for stable output, objective evaluation metrics, and suitable use cases.

    1. Distinguish Two Roles: The Model Is the Brain, the Agent Is the Executor

    Many discussions treat “large language models” and “coding agents” as the same thing, which leads to misaligned evaluation criteria. The two have different responsibilities and should be assessed separately.

    A large language model (LLM) has a very simple interface: it takes text as input and produces text as output. It is good at understanding requirements, reasoning about logic, generating code snippets, and explaining error messages. But the model itself cannot read files from disk, run tests, or execute commands. The content it can see is limited to the text placed into its context by the user.

    A coding agent is a program wrapped around the model. It mainly handles three tasks: organizing project files and command output into text that the model can understand; parsing tool-call requests from the model’s output and actually executing them in a controlled environment; and feeding execution results back to the model for the next round of reasoning. Therefore, the effectiveness of an agent is determined by two parts: the reasoning quality of the model and whether the outer toolchain is designed reliably.

    This distinction has practical value. When a task fails, you first need to determine whether the problem lies in model understanding, tool execution, or insufficient context information. Different diagnoses lead to completely different improvements.

    2. Understand the Model’s Capability Boundaries

    2.1 Capability Characteristics

    • Good at: reading code, explaining logic, designing solutions, generating unit test drafts, and refactoring local code.
    • Not good at: remembering project history outside the context, ensuring consistency across large-scale changes, and judging whether business rules are correct.
    • Cannot do: directly access the network, run programs, or modify files. These actions can only be performed by the outer program on its behalf.

    2.2 General Dimensions for Model Selection

    Models at different tiers usually trade off reasoning strength, response speed, and unit cost. The following table can be used as a reference during selection:

    Task Type Recommended Tier Reason
    Architecture design, complex incident analysis High-reasoning tier Requires multi-step reasoning and trade-offs
    Daily feature development, code review Balanced tier Balances quality and cost
    Formatting, batch sample generation Lightweight fast tier Low latency and low per-call cost

    Context window size is another key parameter. A larger window can hold more code and documentation at once, but a long context does not guarantee that the model will accurately use every piece of information in it. Key constraints should be placed close to the task description and paired with clear instructions.

    3. The Agent’s Working Loop

    A typical coding agent follows this loop:

    1. Perceive: read the task description, directory structure, relevant files, and version status.
    2. Plan: the model provides the next action, such as viewing a file or modifying a function.
    3. Execute: the outer program executes that action within the allowed scope and obtains output.
    4. Observe: feed the output, including error messages, back into the context.
    5. Iterate: repeat the above steps until the model determines that the task is complete or a preset step limit is reached.

    Pseudo-code illustration:

    1. context = task description + project overview
    2. for step in range(max_steps):
    3. action = model.reason(context)
    4. if action indicates completion:
    5. break
    6. if action is not in the allowlist:
    7. reject execution and log
    8. continue
    9. result = execute(action)
    10. context += action record + result
    11. request human confirmation of final changes

    This structure has two implications. First, every step has observable output, making problem localization relatively direct. Second, the stop condition, step limit, and allowlist are engineering design issues that depend on how the outer program is implemented, not on properties of the model itself.

    4. Billing and Cost: Two Accounting Models Need to Be Calculated Separately

    Web subscription services and metered API services are usually two independent accounting systems. Subscriptions limit access by usage quota or plan, while API calls are billed by the number of input and output tokens. A token is the basic unit of text processed by the model, and the conversion ratios for Chinese, English, and code differ.

    To estimate the metered cost of a single task, use the following formula:

    1. single-task cost = input tokens × input unit price + output tokens × output unit price

    What is special about agents is that one task generates multiple rounds of calls, and each round reuses the previous context as input. The more iterations there are, the faster input tokens accumulate. Common ways to control cost include limiting the file scope involved in the task, promptly cleaning up irrelevant history, and splitting large files into chunks for reading.

    For specific unit prices and plan rules, refer to the service provider’s latest announcements.

    5. Permissions and Security Boundaries

    The fact that an agent can execute commands means there is a risk of mistaken operations. When designing how it is used, follow the principle of least privilege:

    • Limit the working directory to the project scope and do not grant write permission to the entire user directory.
    • Classify commands into read-only, reversible write, and irreversible operations. Irreversible operations such as deleting files, force overwriting, pushing to remote branches, and changing permissions must require human confirmation.
    • Grant separate authorization for actions such as dependency installation, network requests, and reading environment variables.
    • Do not place keys and credentials in project files or context. Store them uniformly in environment variables or a secret management service.

    Prompt injection also needs to be guarded against. Comments, documentation, or web page content in a repository may contain text that attempts to change the agent’s behavior. The correct approach is to treat this content as data, not instructions. If a file contains statements such as “ignore previous requirements,” pause the task and prompt for human review.

    Permission policies can be expressed through configuration, as shown below:

    1. allow_read: project root
    2. allow_write: project root (excluding secret configuration files)
    3. require_confirm: delete files, force overwrite, push to remote, modify dependency manifest
    4. deny: access paths outside the user home directory

    6. Practical Methods for Stable Agent Output

    1. Task decomposition: split “refactor the entire module” into small steps such as “extract the interface,” “migrate one call site,” and “add tests,” so that each step can be verified independently.
    2. Define acceptance criteria: specify the test command, expected output, and the file scope that must not be changed.
    3. Read before writing: require the agent to first restate its understanding of the task and list a plan, and start modifying only after confirmation.
    4. Review diffs: inspect the full diff for every change, and do not skip reading it just because tests pass.
    5. Keep a rollback point: confirm that the version status is clean before starting so that problems can be quickly undone.
    6. Record failures: for tasks that repeatedly fail, record the reasons and determine whether the problem lies in the requirement description, context organization, or tool limitations.

    7. How to Evaluate the Experience Objectively

    “How does it feel” is easily influenced by personal emotions, so it is better to record results using quantifiable metrics:

    • First-pass rate: the proportion of tasks that pass tests without manual modification.
    • Rework count: the number of rounds of manual correction.
    • Time comparison: completion time for similar tasks with and without the agent.
    • Cost: token consumption or expense per task.
    • Error type distribution: the proportion of understanding errors, tool misuse, and environment issues.

    It is recommended to select ten to twenty historical tasks in the same project for a controlled experiment. Conclusions drawn from too small a sample are unreliable.

    8. Judging Suitable Use Cases

    Agents are suitable for tasks with clear goals, verifiable results, and controllable impact scope, such as adding tests, batch migration, and locating defects that can already be reproduced. For work with ambiguous requirements, extensive business judgment, or the need for cross-team coordination, humans should still take the lead and use agents as assistive tools.