Agent Harness Design: Practicing Spatiotemporal Composability for Long-Running AI Agents

    This article examines why long-running AI agents require a new kind of host framework, and how spatiotemporal composability addresses the limits of coarse-grained restarts. It breaks dynamic composition into two orthogonal dimensions—time (when components can change) and space (at what granularity they combine)—and describes a plugin-based architecture with a meta-framework engine, transactional hot updates, lossless state handling, and rollback. It also covers implementation approaches for dynamic loading, hot updates, and transactions, plus risks and practical engineering recommendations.

    1. Background: New Requirements that Long-Running Agents Place on the Host Framework

    Early agent applications mostly stayed at the stage of “single-turn prompt calls.” Their runtime behaved like a stateless function call: take in context, produce a result, and exit. Once agents began taking on long-running tasks, multi-tool coordination, and self-evolution, however, the assumptions behind that runtime were completely broken. The Agent Harness is no longer just “a container that loads a model”; it must become a software foundation that can evolve at runtime.

    The requirements fall into three areas.

    First, dynamic extensibility. Agents need to generate, load, or unload external tools and third-party services on demand for the current subtask. The tool set changes with the task phase instead of being statically fixed at startup.

    Second, self-modification and lossless hot updates. During long runs, an agent may autonomously write code to extend its capabilities or fix defects in its tools. Such updates must take effect in place: they can neither interrupt an ongoing session nor lose accumulated memory, connection pools, or cached state.

    Third, fault tolerance and transactional rollback. Model-generated code is inherently uncertain; syntax errors, missing dependencies, and logic exceptions can all occur. The host must provide database-like atomicity guarantees that keep failures within the smallest possible blast radius.

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

    Common industry approaches each have their limits. Plugin systems in AI coding tools emphasize extensibility, but the loading unit of a plugin is tightly bound to the process lifecycle. Container orchestration is good at elastic scaling, but its isolation granularity stops at the container level. Process-level isolation offers reliable memory boundaries, at the cost of communication overhead and state-synchronization complexity.

    Their shared weakness can be summarized as “coarse-grained restarts”: updating one component often requires restarting the entire process or container. This leads to three kinds of loss—session memory is discarded, cold-start latency is high, and fine-grained topology dependencies cannot be accurately expressed within the same address space. In other words, existing systems lack an intermediate form that preserves the efficiency of same-address communication while supporting component-level hot replacement.

    3. The Core Idea: Splitting Dynamic Composition into Two Orthogonal Dimensions

    The value of spatiotemporal composability is that it does not treat dynamic composition as one vague problem. Instead, it splits the problem into two orthogonal dimensions and solves each separately.

    The time dimension focuses on “when things can change”: at which stages of the runtime lifecycle components may be replaced, how the replacement process keeps in-flight requests and shared state consistent, and how changes are atomically committed or undone.

    The space dimension focuses on “at what granularity things combine”: how composition units declare dependencies, how they are addressed and resolved, how references stay valid when the topology changes, and where isolation boundaries are drawn.

    The point of the orthogonal split is engineering verifiability: a problem in either dimension can be modeled and tested independently, without waiting for the entire system to be correct at once. This is also the prerequisite for turning engineering intuition into a provable programming paradigm.

    4. Architecture: Everything Is a Plugin, Plus a Meta-Framework Engine

    Under the philosophy that “everything is a plugin,” model calls, tool adapters, memory storage, and logging and monitoring integrations are all abstracted uniformly as plugins. The host itself keeps only minimal scheduling and lifecycle-management responsibilities. The meta-framework that carries this model handles dependency resolution, lifecycle orchestration, and change transactions; structurally, it resembles a “runtime dependency injection container plus a transaction manager.”

    The following code is illustrative and only expresses structural relationships:

    1. Plugin {
    2. id, version
    3. deps: [id@range]
    4. state: session memory / connection pool / cache
    5. activate() / suspend() / dispose()
    6. }
    7. Transaction {
    8. begin() // freeze the change point and record a dependency snapshot
    9. apply(plan) // load the new version and establish new references
    10. verify() // health checks and contract validation
    11. commit() | rollback()
    12. }

    There are three key design points. First, dependencies are declared through explicit contracts, and resolution results can be cached and validated. Second, state is separated from code, so a hot update replaces only behavior and does not rebuild state. Third, changes are wrapped in a transaction; if validation fails, the system rolls back to the topology snapshot from before the change.

    5. Implementation Approaches for Three Key Capabilities

    Dynamic loading and unloading follow “build before you tear down”: only after the new version is activated and passes contract validation are old references cut, which avoids a time window with no available implementation.

    Lossless hot updates follow “state externalized, behavior swapped in place”: session context, connections, and caches are kept in a host-managed state area, and replacing a plugin affects only execution logic, so no cold start is needed.

    Transaction-level rollback follows “snapshot + validation + compensation”: record a snapshot of the topology and dependencies before the change, run health checks after the change, and if any step fails, restore from the snapshot and keep the error confined to that plugin’s boundary.

    6. Working with General-Purpose Cloud Capabilities

    In engineering practice, this kind of host usually needs external foundational capabilities: object storage to hold model artifacts and version snapshots, message queues to decouple long-running tasks from tool calls, container platforms to run stateless execution units, and logging and monitoring/alerting services to observe hot-update success rates and rollback counts. Baidu AI Cloud offers corresponding capabilities in these general categories and can serve as an external support layer for the host framework.

    7. Risks and Engineering Recommendations

    Three risks need to be recognized clearly. First, same-address hot replacement enlarges the blast radius, so contract validation and canary rollout must be mandatory. Second, externalizing state raises the requirements for serialization compatibility, so version evolution needs a predefined migration strategy. Third, provable theoretical guarantees depend on assumed premises; in practice, you must make clear which constraints are guaranteed by the framework and which by business code. The recommendation is to start with hot updates for read-only plugins, gradually open up self-modification capabilities, and always keep a one-click rollback path available.