Coding Agents: How Their Runtime and Orchestration Work

    Coding agents combine language models with a control loop that manages repository context, tool execution, permissions, and verification. This article explains the six core orchestration modules, how they interact, and what to evaluate when building or choosing a coding agent for reliable, auditable software development.

    A coding assistant often seems better at programming than the same model in a chat window. Usually, that is not because its token prediction suddenly becomes more capable. The difference is an orchestration layer: it continually feeds repository state, tool results, and unfinished objectives back to the model, while deciding whether to continue, execute a tool, or pause for human approval.

    Understanding this runtime is more useful than memorizing the buttons in a particular interface.

    Distinguish the Model, Reasoning, and Agent Layers

    A large language model predicts the next token from the context it receives. It does not inherently track the current state of a project, nor does it turn a prediction into a reversible file change.

    A reasoning model is still a language model. Its training or decoding strategy encourages it to spend more computation on intermediate problem-solving: breaking down a task, checking constraints, comparing alternatives, and then producing a conclusion. This can improve the depth of an individual response, but it does not automatically give the model the ability to modify a repository.

    An agent is a control loop wrapped around the model. The productized layer that manages this loop is commonly called agent orchestration. It repeatedly performs four operations:

    1. Observe the current state.
    2. Ask the model to decide what to do next.
    3. Execute permitted actions.
    4. Feed new observations back into the context.

    A coding agent applies this loop to software development. Its observations primarily consist of code, tests, logs, and version-control diffs. Its actions include searching, reading, editing, running commands, and reporting changes. The model proposes actions; orchestration determines whether those actions are permitted and how their results will be verified.

    Confusing these layers leads to two common mistakes. One is expecting a model upgrade alone to solve engineering problems without improving tools or context management. The other is treating retrieval, caching, and permissions as intrinsic model capabilities, making the behavior difficult to reproduce elsewhere.

    Evaluating coding capability requires looking at model behavior, reasoning budget, and orchestration design together.

    What the Control Loop Actually Does

    A typical task might begin with a request such as “Add pagination to the export endpoint and write tests.” The orchestrator does not treat that sentence as a specification for an immediate final patch. It starts a loop:

    1. Assemble the current input: system-level rules, the task objective, relevant file excerpts, previous tool results, and outstanding acceptance criteria.
    2. Request a structured decision: ask the user for clarification, call a tool, or declare the task complete.
    3. Validate the decision: check permissions and parameter schemas, rejecting path traversal, unbounded recursion, and unauthorized destructive operations.
    4. Execute the tool: collect standard output, diffs, or error codes.
    5. Carry the evidence forward: compact results into the next round of context and continue if the objective remains unmet.
    6. Stop at a defined boundary: finish when acceptance criteria are satisfied or a step, time, or budget limit is reached, then produce an auditable summary.

    The following minimal pseudocode illustrates the control flow. It does not represent any specific product API:

    1. state = init(task, repo_snapshot, policy)
    2. while not done(state) and budget_left(state):
    3. prompt = assemble(state) # Stable prefix + incremental observations
    4. decision = model(prompt) # Text response or tool call
    5. if not allow(decision, policy):
    6. state.record(denial)
    7. continue
    8. observation = execute(decision) # Read, edit, search, or run
    9. state.update(observation)
    10. state.maybe_compact() # Summarize old steps; retain verifiable anchors
    11. return report(state)

    The loop turns a single generation into a cycle of generation, observation, and correction. If the model guesses a file path incorrectly, a tool error is more informative than a longer explanation defending the guess. If a test fails, the failure trace is a better input for the next step than the model’s confidence.

    Module 1: Instruction Hierarchy and the Task Contract

    The first problem a coding agent must solve is whose instructions to follow. In practice, instructions are often organized into roughly the following priority order:

    1. Safety and permission policies
    2. Explicit repository conventions
    3. The current task objective
    4. The model’s general coding preferences

    High-priority rules should be short and stable. Examples include reproducing failures before making changes, avoiding broad formatting changes the user did not request, and never writing secrets to logs.

    Task-specific instructions should be testable. They should identify the directories in scope, whether success means passing tests or preserving interface compatibility, and which files must remain untouched.

    Ambiguous objectives are a leading cause of failure in long-running loops. When information is missing, orchestration should encourage clarification or read-only exploration rather than immediate, large-scale rewriting.

    Instruction growth also needs control. Reattaching every historical conversation and every complete policy document on each turn crowds out relevant code. A better approach is a concise task contract containing:

    • The objective
    • Constraints
    • Confirmed decisions
    • Current acceptance criteria

    This contract should be maintained throughout the loop so that the model does not have to reconstruct the user’s intent on every turn.

    Module 2: Repository Context and On-Demand Retrieval

    The model cannot see the entire filesystem. It sees only the material supplied in its context window. Context strategy therefore matters more than simply trying to fit the repository into the prompt.

    A common, more reliable approach is to identify candidate files through directory structure, symbol names, and dependencies, then read the relevant functions or modules. This is preferable to blindly reading fixed-size blocks of lines.

    Retrieval may use text search, symbol indexes, or vector retrieval. Regardless of the method, results must include verifiable paths and excerpts. Otherwise, the model may edit the wrong file based on vague similarity.

    Context should distinguish three types of information:

    • Stable information: language versions, build procedures, and directory conventions. These belong in a relatively stable prompt prefix.
    • Task information: requirements and acceptance criteria.
    • Volatile information: current diffs, test output, and recently read function bodies.

    Mixing changing logs with stable rules in one large block wastes context space and can invalidate prompt caches.

    Temporal consistency matters as well. Editing from stale excerpts can produce “ghost edits”: the model acts as though a function still has an implementation that has already changed. Before writing, the orchestrator should reread the target region or validate the patch against its baseline version. If a conflict appears, it should return to read-only inspection before deciding again.

    Module 3: Tool Calls and Execution Boundaries

    Tools are how an agent interacts with its environment. A minimal coding toolset typically includes:

    • Directory listing and search
    • Reading selected file ranges
    • Applying patches
    • Running tests or type checks
    • Inspecting version-control diffs

    Tool descriptions must clearly specify parameters, side effects, and failure behavior. Vague descriptions encourage the model to invent unsupported parameters. Overly broad capabilities can allow a single call to delete large numbers of files.

    Execution safeguards must be enforced through policy, not just prompt instructions. Read-only and write tools should have separate authorization. The working directory should be restricted to the task repository. Network access, secrets access, and deployment actions should be disabled by default or require human approval.

    Command timeouts, output limits, and maximum modification sizes also need explicit bounds. When truncating output, retaining only a final success message is insufficient. Preserve error summaries and the command needed to reproduce the result, or the model may incorrectly conclude that validation passed.

    Tool results should be structured. Instead of returning an entire terminal transcript, provide the exit code, key errors, associated files, and whether a retry is recommended. The model may still misinterpret the result, but orchestration can use the exit code to determine whether completion is allowed.

    Module 4: Context Windows, Compaction, and Prompt Caching

    The cost and reliability of long tasks depend heavily on how prompts grow. Appending the full history on every turn quickly fills the window with early exploration and can crowd out the actual acceptance criteria.

    Compaction is not simply deleting old messages. It should preserve verifiable anchors:

    • Files already modified
    • Summaries of important diffs
    • Names of failing tests
    • Approaches explicitly rejected by the user

    Original outputs that have been summarized should ideally remain available for on-demand retrieval. Otherwise, the summary itself can become a new source of hallucination.

    Prompt caching depends on a stable prefix. System rules, tool schemas, and repository conventions should appear near the beginning and change infrequently. Incremental observations should appear later.

    Reordering tools, inserting timestamps into the prefix, or rewriting the entire system prompt can invalidate cached prefixes, increasing both latency and cost. For very long logs, orchestration should first extract failed assertions and the top stack frames, then decide whether the model needs the full output.

    Compaction must also prevent goal drift. If a summary retains only the model’s latest self-assessment and drops the user’s original constraints, later edits can move progressively away from the task. The task contract should be treated as a short document that is not casually rewritten; process summaries should primarily preserve evidence.

    Module 5: Memory and Continuity Across Long Sessions

    Memory does not mean permanently inserting every conversation into the prompt. A more useful structure separates:

    • Session state: the current plan and unfinished work
    • Repository conventions: readable project documentation, rather than rules hidden in a conversation
    • Cross-session memory: stable preferences, such as commit-message style or generated directories that must not be edited

    Users should be able to inspect and delete long-term memory.

    Stale memory is particularly risky in coding tasks. A test command remembered from three months ago may no longer work. Long-term memories should carry a timestamp and scope, and current repository evidence should validate them before use. If a remembered instruction conflicts with a newly inspected build file, the repository takes precedence.

    When resuming across sessions, restore the task contract and uncommitted diffs before restoring lengthy previous reasoning. Reasoning text can be discarded; file state and acceptance criteria cannot.

    Human handoff is part of continuity too. If the loop stops because of permissions, ambiguity, or budget limits, the summary should explain:

    • What has been verified
    • What remains unverified
    • Which files changed
    • The smallest next action

    Without this information, the agent merely transfers confusion from the conversation into the workspace.

    Module 6: Verification and Permission Governance

    Without verification, an agent can only appear to have finished.

    Verification should be external wherever possible. Compilation, unit tests, static analysis, and diff review produce objective signals through tools. The model can then interpret failures rather than judge success solely from its own output.

    Orchestration can express completion conditions as executable assertions—for example, that relevant tests return an exit code of zero and the diff touches only approved paths. If the model declares completion while those assertions remain unsatisfied, the loop should continue.

    Permission governance determines whether the loop is suitable for real repositories. Least privilege, traceable operations, and confirmation for destructive commands are general principles, independent of any platform.

    Show patches before writing. Show the working directory and arguments before running commands. Retain logs and diffs after completion to support review and rollback.

    Generated code also requires basic security checks:

    • Do not write secrets into the repository.
    • Do not weaken authorization merely to make tests pass.
    • Do not replace a fix with skipped checks.

    Verification has limits. Passing existing tests does not prove that the requirements are correct. Modules without tests may require diff review and human confirmation instead. Orchestration should make the basis for confidence explicit rather than use a polished summary to conceal missing evidence.

    How the Modules Constrain One Another

    These six modules are not independent pipeline stages. They constrain and support each other:

    • Instructions define acceptance criteria.
    • Retrieval determines what the model can see.
    • Tools produce new evidence.
    • Caching and compaction determine the cost of retaining that evidence.
    • Memory prevents each iteration from starting over.
    • Verification determines whether the loop may stop.

    Excess in any one module creates imbalance. Retrieval that is too broad can bury the objective. Tools that are too powerful amplify mistakes. Aggressive compaction can erase constraints. Overweighted memory can impose outdated habits on the current repository. Narrow verification can reward deleting tests simply to obtain a passing result.

    Evaluation should therefore go beyond whether a single response resembles an ideal answer. More useful measures include:

    • Loop steps required for comparable tasks
    • Proportion of ineffective tool calls
    • Cache hit behavior
    • Changes outside the approved scope
    • Whether tests actually pass
    • Human rework required

    These describe orchestration quality, not just model size.

    A Practical Sequence for Building or Selecting a Coding Agent

    When building a coding loop from scratch, start with a narrow, complete feedback loop before adding capabilities.

    First, support read-only exploration and patch previews. Confirm that the model can locate problems using actual repository files.

    Second, add reversible edits and individual test execution, with explicit completion conditions.

    Third, address long-session compaction, stable prompt prefixes, and optional long-term memory.

    Only then consider multi-agent specialization. Multiple agents add coordination overhead. If context management and verification are not yet reliable in a single loop, dividing the work among roles may simply replicate the same hallucination across more conversations.

    When comparing coding tools, ask the same questions:

    • Can read-only and write permissions be separated?
    • How is failure output truncated, and are critical errors preserved?
    • How does the system prevent goal drift during long tasks?
    • Is the prompt prefix stable?
    • Does completion depend on the model’s claim or external checks?

    A system that can answer these questions is integrating a model into an engineering workflow, rather than merely giving a chat interface a command-line appearance.

    The core logic of a coding agent is straightforward: the model proposes the next step under uncertainty, while orchestration confines that proposal to an observable, executable, and verifiable software workflow.

    Repository context, tools, caching, memory, and permissions are all parts of that loop. The more clearly they are designed, the less the same base model has to rely on luck to complete multi-step code changes.