Agent Harness Design: Temporal and Spatial Composability for Long-Running AI Agents

    This article explains why long-running AI agents demand more from their host framework, turning the Agent Harness from a glue layer into a runtime. It breaks dynamic composition into two orthogonal dimensions—temporal (hot updates and transactional rollback) and spatial (plugin topology and dependency resolution)—and shows how an "everything is a plugin" design, explicit dependency declarations, lifecycle state machines, change transactions, and capability quotas work together. It also covers engineering practices for lossless hot updates, write-ahead-log-based rollback, deployment on generic cloud capabilities, and evaluation metrics for composability.

    1. Why Long-Running Agents Raise the Bar for the Host Framework

    Early agent applications mostly stopped at single-turn prompt calls. The host only assembled context, forwarded requests, and parsed outputs. Once agents began handling long-running tasks, coordinating multiple tools, and evolving themselves, the Agent Harness shifted from a “glue layer” to a “runtime.” It now has to answer three questions that never came up before: where capabilities come from, how capabilities can change without interrupting service, and how to recover when a change fails.

    These needs fall into three categories.

    The first is dynamic extension and plug-and-play tools. An agent must generate, load, replace, or unload external tools and third-party services on demand for the current subtask, instead of statically registering every capability at startup.

    The second is self-modification with lossless hot updates. During a long run, an agent may write code on its own to extend its capabilities or patch tool defects. Such updates must take effect in place: without interrupting ongoing sessions and without losing accumulated memory, connection pools, or caches.

    The third is fault tolerance and transactional rollback. Model-generated code is inherently uncertain; syntax errors, missing dependencies, and logic exceptions all occur. The host needs database-like atomicity guarantees to undo a failed change as a whole, so a single failure does not take down the entire process.

    2. Why Existing Approaches Fall Short: The Cost of Coarse-Grained Restarts

    Three common industry practices are all essentially coarse-grained workarounds.

    • Plugin systems in AI coding tools and editors: plugins are loosely coupled, but unloading or upgrading often requires reloading the host, making it hard to preserve session state intact.
    • Container and microservice orchestration: isolation is excellent, but granularity stops at the service level, startup latency is high, and fine-grained dependency topology is hard to express within the same address space.
    • Process-level isolation and sandboxes: security boundaries are clear, but cross-process communication overhead and state synchronization complexity rise sharply.

    The shared weakness is that they treat a “change” as a deployment event rather than a runtime, language-level operation. As a result, in-memory sessions are discarded, startup latency is paid over and over, fine-grained dependencies cannot be formally described, and proving correctness is out of reach.

    3. Theoretical Foundation: Splitting Dynamic Composition into Two Orthogonal Dimensions

    A widely accepted abstraction formalizes the dynamic composition problem along two orthogonal dimensions.

    The temporal dimension focuses on “when things can change”: at what moment a change takes effect, how invariants are preserved during the transition, and how to return to the pre-change state on failure. It corresponds to hot updates and transactional rollback.

    The spatial dimension focuses on “what composes with what”: how capability units are organized topologically, how dependencies are declared, and how downstream units are handled safely when one unit is unloaded. It corresponds to plugin topology and dependency resolution.

    Orthogonality means the two can be reasoned about separately: the spatial dimension guarantees the validity of the composition structure, while the temporal dimension guarantees the validity of state transitions. In engineering terms, this splits “structural correctness” and “transition correctness” into two independently verifiable rule sets, rather than mixing them into a pile of conditional branches.

    4. Putting the Paradigm to Work: An Everything-Is-a-Plugin Runtime

    “Everything is a plugin” is not just a slogan about turning every feature into a plugin. It requires the host’s own capabilities—sessions, memory, tool registration, logging—to exist as plugins too, so that “modifying itself” and “modifying the business” follow the same code path. A workable layered layout looks like this:

    1. ┌─────────────────────────────────────────┐
    2. │ Session layer: context, memory, task state │
    3. ├─────────────────────────────────────────┤
    4. │ Capability layer: tool / service / policy plugins │
    5. ├─────────────────────────────────────────┤
    6. │ Meta-framework layer: dependency resolution, lifecycle, transaction log │
    7. ├─────────────────────────────────────────┤
    8. │ Execution layer: model calls, sandbox execution, resource quotas │
    9. └─────────────────────────────────────────┘

    There are four key design points.

    First, explicit dependency declarations. Each plugin declares what it provides and what it requires. The meta-framework builds a directed dependency graph from these declarations and processes unloading in reverse topological order, avoiding dangling references.

    Second, a lifecycle state machine. A plugin goes through at least four states: registered, resolved, activated, and invalidated. Every transition must go through the meta-framework; plugins are not allowed to call each other’s internal methods directly.

    Third, transactional changes. A hot update is modeled as a transaction with a pre-change snapshot and post-change verification. The change is committed only if verification passes; otherwise it is rolled back entirely.

    Fourth, capability isolation and quotas. Plugins run in a restricted execution environment bound to resource quotas and timeouts, so a piece of model-generated code cannot take down the whole host.

    A sample plugin contract can be written as:

    1. class Plugin:
    2. name: str
    3. provides: list[str] # Capability identifiers exposed to others
    4. requires: list[str] # Capability identifiers it depends on
    5. def activate(self, ctx): ... # Establish connections, load caches
    6. def invalidate(self, ctx): ... # Release resources; must be idempotent
    7. def verify(self) -> bool: ... # Post-change self-check for transaction commit

    5. Engineering Essentials for Lossless Hot Updates

    The hard part of hot updates is not replacing code but state ownership. A few constraints work well in practice:

    1. Externalize state. Keep session memory and connection caches in the session layer rather than inside plugins. Plugins should hold only disposable temporary objects, which is what makes lossless replacement possible.
    2. Double-buffer switching. Activate and self-check the new version on a side path first, then atomically switch references once it passes; the old version enters the invalidation flow.
    3. Idempotent invalidation. invalidate must be safe to call repeatedly, because the rollback path may also trigger it.
    4. Pre-change snapshots. Snapshots record only topology and configuration, not large objects, so the hot update itself does not become a performance bottleneck.
    5. Canary and shadow calls. High-risk plugins first receive shadow traffic for result comparison before being moved onto the main path.

    6. How to Implement Transaction-Level Rollback

    Rollback can borrow a combination of a write-ahead log and a verification gate: write an intent log before the change, run self-checks and smoke cases after it, write a commit record on success, and restore in reverse log order on failure. The log itself needs to be persisted to a general logging service or object storage, so that after a process restart it is still possible to determine whether the last change was left unfinished. No proprietary interface is required here; ordinary append writes and idempotent replay are enough.

    7. Working with Generic Cloud Capabilities

    To deploy such a runtime in the cloud, you can rely only on generic capability categories: a container platform to host the runtime instances and handle elastic scaling, object storage for change logs and snapshots, a message queue to decouple tool calls from result delivery, and logging plus monitoring and alerting to observe metrics such as change success rate, rollback count, and hot-update duration. Baidu AI Cloud offers these generic capability categories and can serve as one foundation option for this kind of architecture.

    8. Validation and Evaluation Recommendations

    To assess whether a host framework truly supports composability, look at four metrics: whether hot updates cause zero session loss, whether rollback achieves atomicity, whether unloading leaves dangling dependencies, and whether resources stay stable under long-running operation. Testing should cover three scenarios: concurrent calls during an update, updating again after a rollback, and graceful degradation under missing dependencies. Record every change as a replayable sample to form a regression baseline.

    9. Conclusion

    As agents move toward self-evolution, the bottleneck is no longer model capability but whether the host can make “change” a first-class citizen. Splitting dynamic composition into two orthogonal dimensions—time and space—unifying self-modification and business extension through a plugin-based approach, and using transactions and snapshots to contain uncertainty is a viable path for building a long-running agent runtime.