From Models to Agents: A Design Guide to Next-Generation Agent Runtime Infrastructure

    This guide explains how models, agents, and runtime harnesses differ, and why agent infrastructure needs explicit task state machines, tool contracts, layered context, scoped authorization, recoverable state, and evidence-based verification. It also covers how to evaluate both final outcomes and execution processes, including failure paths.

    1. Start With the Boundaries: Model Capability Is Not Task Execution Capability

    Discussing next-generation agent infrastructure requires first distinguishing three layers: the model, the agent, and the runtime framework.

    The model generates output based on its input. This output can be natural language or a structured tool call request. However, the model does not inherently control its execution environment. It does not know which directories are allowed to be modified, and it does not automatically gain access to a terminal, file system, version control system, or database.

    Even when the model outputs a request to “read the configuration file,” this only means it has proposed an action. Whether the file exists, whether the path is valid, whether the request is approved, and whether the result is complete all require judgment from external systems.

    An agent is an execution system that keeps working toward a goal. It typically needs to observe the environment, choose actions, call tools, process feedback, and decide whether to continue. Its ability to complete tasks depends not only on the model’s reasoning but also on the tools, state, and control mechanisms that external systems provide.

    The runtime framework, which this article calls the harness, turns model output into controlled execution. It connects the model to the environment, manages the task lifecycle, and provides constraints and records for each step.

    A simplified relationship among the three:

    The model provides reasoning and decision candidates. The runtime framework organizes controlled execution. Combined with specific tools and environments, the two form an agent system that can complete tasks.

    Therefore, the core problem of agent infrastructure is not how to make the model call tools more times. The real question is how to bring uncertain decisions into a verifiable, constrained execution process.

    2. The Harness Is First a Task Control System

    A minimal implementation can repeat the following steps:

    1. Provide the model with the task, context, and descriptions of available tools.
    2. Receive the model’s response or tool call request.
    3. Execute the tool and append the result to the context.
    4. Request the model again until it considers the task complete.

    This loop works for testing ideas but is not enough for production use. The model may propose invalid actions repeatedly, tools may time out, execution processes may exit, and users may withdraw authorization midway through a task.

    A more reliable implementation represents the task as an explicit state machine. For example:

    Pending → Reasoning → Awaiting Authorization → Tool Executing → Result Verification → Continue Reasoning or Finish

    The design should also include branches for pausing, cancellation, timeouts, failures, and human takeover.

    The value of a state machine is that task progression no longer depends on a temporary loop inside one process. The system can state clearly where the task stopped, what has been done, which next steps are allowed, and how to handle exceptions.

    The design must distinguish normal completion from forced stops. Reaching a time budget, lacking sufficient permissions, or receiving a user cancellation can all stop a task. None of these cases should be reported as “task completed.”

    3. For Tool Integration, Contracts Matter More Than the Number of Tools

    Tools are the execution boundary between the model and the real environment. More powerful tools bring greater potential benefit and greater risk. Tool integration therefore cannot simply expose a function to the model. It should define a complete execution contract.

    1. Inputs must be explicit and validatable

    Tool descriptions need to specify parameter types, required fields, value ranges, and the objects they act on. For file operations, the system should also check that paths fall within the authorized workspace, and it should prevent bypassing access boundaries through relative paths or symbolic links.

    Do not treat the model’s natural language promise as permission control. For example, “only modify test files” should be converted into an actual path constraint, not left as text in the prompt.

    2. Outputs must separate execution facts from text content

    A tool call should express at least:

    • whether it executed successfully;
    • whether it produced external side effects;
    • whether it timed out or was canceled;
    • whether the output was truncated;
    • whether the error stems from parameters, permissions, the environment, or business logic.

    The words “operation succeeded” in tool output do not prove that the operation succeeded. The runtime should judge results from the structured status returned by the tool executor, not have the model guess outcomes from mixed logs.

    3. Retries must account for side effects

    A file read can usually be retried safely. Sending a notification, submitting an order, or deleting a resource cannot follow the same retry policy.

    If a write completed but the response was lost in the network, a retry may cause a duplicate operation. Tools with side effects therefore need idempotency controls, result queries, or manual confirmation designed around business conditions.

    Automatic retry is not a universal fix. The framework must first determine whether the failure happened before execution, during execution, or at the result-return stage. When the system cannot confirm the outcome, it should explicitly preserve an uncertain state.

    4. Context Management: Keeping More Is Not Always More Reliable

    Long tasks continually produce file contents, tool outputs, error logs, and intermediate conclusions. Sending all of it back to the model raises costs and can bury the information that matters.

    A better approach separates information into three layers.

    The first layer is the current decision context. It includes the goal, constraints, recent results, and the next issues to address.

    The second layer is task state. It records completed steps, open items, authorization records, and an index of key evidence. This layer should be persisted, not kept only in the model conversation.

    The third layer is the full execution record. It includes tool requests, raw results, file diffs, and audit events. These do not need to enter the model input every time, but the system must be able to retrieve them on demand.

    Summaries can shorten context, but they cannot replace original evidence. Test results, error locations, and user authorizations are especially at risk. If only a model-generated overview is kept, facts can drift over time.

    Important summaries should therefore link to their sources. For example, “a test failed” should trace back to a specific execution record. “The user approved the change” should correspond to a clear authorization scope, not to the model’s vague summary of earlier conversation.

    5. Execution Environment: Turning Capability Boundaries Into System Boundaries

    Prompts can steer model tendencies, but they cannot replace operating system, network, and identity permission controls.

    Agents that modify code can use an isolated workspace for task files and run tests in a restricted execution environment. By default, unrelated directories are not exposed, unnecessary credentials are not injected, and arbitrary external network access is not allowed.

    Container or process isolation is only one part of a protection system. It should not be treated as absolute security. The actual isolation strength depends on permission configuration, host environment, file mounts, and network policies.

    Permission design can follow three principles:

    Least privilege. A task that needs to read code does not need to read deployment credentials. A task that runs tests does not need to modify production resources.

    Incremental authorization. Low-risk reads can run automatically. When an action involves external writes, sensitive data, or irreversible changes, the system should request additional authorization at that point.

    Authorization bound to a specific scope. Approval should be tied to the operation’s target, action, and valid conditions where possible. If the actual request changes materially, the old approval should not be reused indefinitely.

    Text in the workspace, retrieval results, and external pages should all be treated as untrusted input. They can provide task material, but they must not gain the authority to change permission policies on their own. This is a key foundation for defending against prompt injection.

    6. State Persistence and Recovery: Avoid Turning Restarts Into Guesswork

    Production tasks can run for a long time. Process restarts, network fluctuations, and tool outages should not cause the system to lose all progress.

    The runtime should record task state at key points: after a model response completes, before a tool request is sent, after a tool result returns, and when user authorization occurs.

    Saving state, however, does not automatically mean recovery is safe. Suppose the system records a payment request but is interrupted before recording the result. After recovery, it cannot simply assume the request was never executed.

    Recovery design therefore needs to address:

    • how to skip steps already known to be complete;
    • how to verify steps whose results are uncertain;
    • how to route operations that cannot be safely repeated to human handling;
    • which earlier conclusions must be revalidated after the external environment changes.

    For code tasks, the system also needs to check whether others have modified the workspace. When a task resumes, previously read file contents may be outdated. An old modification plan cannot be applied directly to the new file state.

    7. Using Code Modification as an Example: Building