Designing a Model-Agnostic Agent Runtime: Patterns, Sandboxes, and Versioned Traces
A practical guide to building an agent runtime (harness) that decouples LLM reasoning from product logic. Covers model-agnostic adaptation layers, preset execution modes, versioned session formats, narrow plugin extension points, layered autonomy with budgets, and observability practices for taking agents from tool-calling demos to production systems.
What a Runtime Actually Solves
Wiring an LLM directly into an editor or CLI only gets you single-turn Q&A. Once a task spans multi-file edits, external system queries, long-horizon planning, and human confirmation, an agent without a runtime quickly exposes three problems: context gets buried under irrelevant history, tool calls lack permission and idempotency constraints, and failures cannot resume from an inspectable state. The job of an agent runtime (often called a harness) is to pull “model reasoning” out of the product and turn it into a replaceable capability provider, while keeping sessions, tools, memory, policies, and observability inside a controlled execution environment.
A workable runtime must answer at least five questions: What is the goal of the current task and its completion criteria? Which context must enter this turn, and what should be externalized? Which tools can the model call, with what parameters and permissions? On failure, does it retry, roll back, degrade, or escalate to a human? Can the entire trajectory be recorded, replayed, and audited? Turning these into explicit protocols—rather than scattering them across prompts—is what makes the system engineering rather than prompting.
Model-Agnostic Does Not Mean Interface Homogeneity
“Model-agnostic” means the runtime does not hard-code any single vendor’s conversation format, tool protocol, or billing assumptions into its core loop. The adaptation layer is responsible for message-role mapping, tool schema conversion, streaming delta merging, context-window trimming, and normalizing refusals and safety filters. The core loop depends only on stable abstractions: observe, plan, act, verify, commit.
In practice, do not chase “identical behavior across all models.” Models genuinely differ in tool adherence, long-context degradation, and parallel calling. Safer approaches include:
- Use capability probing instead of brand branching. Probe and cache at session start whether a model supports structured tool calling, image input, or long outputs.
- Version prompt templates separately from vendor parameters, so a single upgrade does not change the semantics of both layers at once.
- Keep a regression task set for critical paths: same repository snapshot, same tool stubs, same success criteria—only swap the model adapter, then compare step counts, failure types, and final diffs rather than subjective “feel.”
Common cloud capabilities—model inference, object storage, logging, and monitoring, such as those available on platforms like Baidu AI Cloud—work well behind the adaptation layer: the inference endpoint is swappable, traces and artifacts live in object storage, and runtime metrics flow into monitoring and alerting. The core protocol should still stay neutral, avoiding leaking fields from any specific inference API into the business session format.
Constrain Complexity with Modes, Not Prompt Luck
The same runtime facing “edit one function” versus “refactor across modules and verify” should not offer the same degrees of freedom. A preset mode is essentially a policy package: the allowed tool set, maximum steps, whether code may be written and executed, the context budget, and when it must stop and ask a human.
Four reference policy types:
- Standard mode: interleaves planning and tool calls, suited to information retrieval plus small scoped edits. Every step must have an observable tool result—the model may not claim an action that the runtime has no record of.
- Programmatic tool calling: hands a batch of deterministic steps to a controlled executor (e.g., run tests from a manifest, format, lint), while the model only generates the plan and interprets failures. This reduces token round-trips and concentrates side effects in an auditable executor.
- Minimal mode: a very small tool surface, short context, few turns—used as a baseline for comparison and regression. Its value is reducing variables, not feature completeness. If evaluation write-ups mix in implicit tools from the full agent, results are no longer comparable.
- Creative mode: relaxes exploration (sketches, multiple proposals, prototype scripts), but by default does not auto-merge into the main branch. Exploratory output goes into an isolated workspace and can only be promoted to a formal change after verification.
Modes are not marketing labels—they are switches for permissions and cost. Mode switches should be written into session metadata; otherwise you cannot explain later why the same task behaved so differently.
Sessions, Artifacts, and Compatibility
The most underestimated piece during preview stages is the session format. If the runtime bundles internal events, tool results, and raw model output into one giant JSON that cannot evolve, old records become unreadable the moment a new version adds fields or changes event order. Recommendations:
- Use an append-only event log with a schema version number; the reader migrates by version rather than requiring all history to be compatible forever.
- Separate replayable facts (tool inputs and outputs, file hashes, command exit codes) from disposable presentation (streamed tokens, UI collapse state).
- Separate workspace from conversation: express code changes as patches or commits; the conversation only references artifact IDs. Upgrading the conversation format then cannot destroy code that has already landed.
- State it clearly: developer previews may break compatibility. If production treats the runtime as the sole entry point, bring your own export and freeze strategy.
The pseudocode below expresses control flow only, not any specific product’s interface:
loop until budget_exhausted or goal_met:observation = assemble(goal, selected_memory, tool_facts)action = model.propose(observation, policy.mode)if action.needs_human: pause_and_checkpoint()result = executor.run(action, sandbox, allowlist)trace.append(versioned_event(action, result))if result.violates_invariant: rollback_or_stop()
Plugins and Cross-Platform: Keep Extension Points Narrow
Once plugin volume grows, the risk shifts from “not enough features” to “arbitrary code running in the user’s environment.” A healthy plugin system should restrict extension points to: tool declarations, prompt fragments, event subscriptions, and UI panels. Plugins must not replace core permission checks or silently rewrite other plugins’ tool results.
Recommended boundaries:
- Declarative manifest: name, version, required permissions, input/output schemas, and whether it has side effects.
- Deny network and secret directories by default; grant least privilege per task, with timeouts and output size limits.
- Dependency locking plus signature or hash verification; a marketplace or directory solves discovery, not review.
- Desktop, web, bot, or HPC job entry points can differ, but should share one session protocol and one sandbox semantics—avoid “runs on desktop, different semantics on the server.”
- Treat multimodal input as just another observation channel: images and terminal screenshots should be tagged with source and timestamp before entering context, so untrusted pixels are not mistaken for instructions.
With roughly 60% of users building or installing their own extensions, once such an ecosystem forms, the official side should invest in directories, ratings, permission tiers, and uninstall/rollback—rather than piling more capability into the core. Experimental compatibility layers (e.g., aligning with some external coding agent’s extension conventions) must be isolated inside an adapter and marked as stability-not-promised, so the core is not held hostage by an external product’s private conventions.
From “Can Call Tools” to a More Autonomous System
More autonomy does not mean fewer constraints—it means moving constraints from human babysitting into architecture. A reference layering:
- Goal layer: user intent, acceptance criteria, prohibitions.
- Planning layer: decompose goals into verifiable subtasks, each with inputs, outputs, and stop conditions.
- Execution layer: tools and programmatic steps, all through the sandbox.
- Critique layer: checks independent of the generation step—tests, static rules, diff review; failure here means the task may not be declared complete.
- Memory layer: keep only facts and failure reasons useful for later decisions, compressed periodically—do not treat the entire chat as a database.
Autonomous loops must have budgets: steps, time, cost, and file-write scope. Hitting the budget means stop, leaving a recoverable checkpoint. Irreversible operations (pushes, deletions, outbound email, production config changes) require human confirmation by default. In “Super-agent”-style exploration, what matters is whether these loops actually close—not how many files a single demo can auto-edit.
Observability, Evaluation, and Release Gates
No traces, no improvement. At minimum, record: mode, model capability summary (not vendor marketing names), per-step tools, exit codes, patch hashes, human intervention points, and failure classification. Metrics should focus on task success rate, wasted-step ratio, rollback counts, and human takeover rate—not just call volume. DAU and token consumption reflect scale but cannot substitute for correctness.
Before launch:
- Fix a baseline in minimal mode, then enable standard or programmatic modes to see whether the gains justify the complexity.
- Scan plugins for permissions and malicious descriptions, so prompt injection cannot hijack the agent through tool descriptions.
- Write session export, secret scanning, and workspace cleanup into the ops runbook.
- Preview builds are for evaluation and internal experiments only. Before using the runtime as the sole production entry point, have a compatibility policy, a degradation path, and on-call observability.
Summary
What separates agent products is whether the runtime treats the model as a replaceable component and contains side effects through modes, sandboxes, versioned traces, and a narrow plugin surface. Build the minimal path into a regression-grade yardstick first, then gradually enable programmatic execution and exploration modes. Autonomy presupposes stoppability, replayability, and auditability. With these boundaries in place, the team gets an execution system that can evolve—rather than yet another prompt script that cannot be upgraded.
