Agent Harness Spatiotemporal Composability: A Practical Guide for Long-Running AI Agents

    This article explores how to design an agent harness that supports long-running, self-evolving AI agents. It breaks dynamic composition into two orthogonal dimensions—time and space—and explains a plugin-based runtime with scoped dependencies, lossless hot updates, and transaction-level rollback. It also covers fault tolerance for model-generated code, integration with general-purpose cloud capabilities, and practical risk controls.

    1. Why Long-Running Agents Demand More from the Harness

    As agents move from single-turn prompt calls to long-running task execution, multi-tool collaboration, and self-evolution, the role of the agent harness has shifted from a “glue layer” to a runtime. It must manage session state, tool lifecycles, memory, and connection caches at the same time, while keeping the host process stable when the model autonomously generates code.

    Traditional software systems usually handle these needs by restarting at the process or container level to update plugins and replace services. This coarse-grained approach leads to lost session memory, higher cold-start latency, and difficulty expressing topology dependencies within the same address space.

    This yields three hard requirements:

    • Dynamic extension and plug-and-play tools: generate, load, and unload external tools or third-party services as tasks require.
    • Self-modification and lossless hot updates: apply changes in place without interrupting sessions or losing accumulated context and connection caches.
    • Fault tolerance and transactional rollback: provide database-like atomic rollback when auto-generated code has syntax or logic errors.

    2. Theory: Splitting Dynamic Composition into Two Orthogonal Dimensions

    Discussions of dynamic composition often mix “time” and “space,” which makes correctness hard to prove. A more rigorous approach is to formalize the problem into two orthogonal dimensions:

    The time dimension focuses on “when to change”: the timing, ordering, and visibility boundaries of changes, and how incomplete states are hidden from external callers during a change.

    The space dimension focuses on “where to change”: module boundaries, dependency topology, scope isolation, and resource ownership.

    The value of orthogonal modeling is that it breaks “is a hot update safe?” into two separately verifiable propositions: “does the change have atomic visibility?” and “does the change affect only the declared scope?” This provides a reasoning basis for later transaction semantics and isolation levels.

    3. Architecture: A Runtime Where Everything Is a Plugin

    Under a plugin-first philosophy, the host kernel keeps only minimal responsibilities: a plugin registry, dependency resolution, lifecycle scheduling, a transaction log, and state snapshots. All other capabilities—tool invocation, memory management, UI rendering, and network access—exist as plugins.

    A schematic plugin description looks like this (pseudocode, intended only to express the design intent):

    1. plugin ToolSearch {
    2. provides: [search]
    3. requires: [httpClient, cacheStore]
    4. scope: session
    5. transaction: { prepare, commit, rollback }
    6. }

    Key design points include:

    1. Dependency declaration and topological sorting: plugins explicitly declare required capabilities, and the framework builds a dependency graph to avoid coupling caused by implicit global variables.
    2. Scope tiers: distinguish process-level, session-level, and request-level scopes so the impact of unloading is predictable.
    3. Externalized state: long-lived state such as session memory and connection caches goes into a snapshot-capable storage layer, while plugins remain stateless or weakly stateful to enable hot updates.

    4. How to Implement Lossless Hot Updates

    The hard part of a hot update is not replacing code, but replacing it without breaking in-flight call chains. A workable path is a three-phase “prepare—switch—retire” sequence:

    • Prepare: load the new plugin version into an isolated scope, complete dependency validation and interface compatibility checks, and keep it invisible externally.
    • Switch: atomically swap references at a transaction boundary; in-flight calls continue on the old version until they finish naturally.
    • Retire: confirm there are no in-flight references, release old-version resources, and write a transaction log entry for traceability.

    Pseudocode:

    1. tx = begin()
    2. new = load(plugin, version=n+1, scope=session)
    3. assert compatible(new.api, old.api)
    4. swap(ref, new) # atomic visibility
    5. old.retire_when_idle()
    6. tx.commit()

    If any phase fails, the system rolls back based on the transaction log and restores the pre-change snapshot without exiting the host process.

    5. Transaction-Level Rollback and Fault Tolerance

    Rollback requires three building blocks: a change log, state snapshots, and idempotent compensation actions. For model-generated code, run it in a restricted scope by default, limiting access to the file system, network, and system calls. Mark side-effect operations (writing files, sending messages, calling external APIs) as compensable or non-compensable; non-compensable operations must be validated before the transaction prepare phase.

    A practical combination of engineering strategies:

    • Put syntax and static checks first to block obvious errors.
    • Shadow execution: run a trial in an isolated environment and compare key outputs.
    • Tiered fallback: fall back to the existing toolchain when new capabilities are unavailable to keep tasks running.

    6. Working with General-Purpose Cloud Capabilities

    Keeping the harness lean and pushing heavy capabilities down to general-purpose cloud products is a common engineering trade-off. Session snapshots and memory archives can go to object storage; plugin and tool images can be distributed through container platforms; change logs and audit events can be sent to message queues and logging services; health status and error rates can be observed through monitoring and alerting. Baidu AI Cloud offers capabilities in these general categories that can serve as the foundation for such an architecture, while the framework layer depends only on standard interfaces to avoid tight coupling with a specific implementation.

    7. Implementation Advice and Risk Controls

    1. Define scope and transaction semantics before counting plugins, and avoid “many plugins that cannot be safely unloaded.”
    2. Establish observability metrics for hot updates: switch time, in-flight call count, rollback rate, and snapshot size.
    3. Set permission boundaries and quotas for auto-generated code to prevent resource exhaustion.
    4. Keep a “disable self-modification” switch, and prefer deterministic execution in compliance- and audit-heavy scenarios.
    5. Use progressive canary rollouts instead of a one-time full switch to keep change risk under control.

    8. Conclusion

    The competition among self-evolving agents is shifting from single-point model capability to the engineering maturity of the agent runtime. Decomposing dynamic composition into two orthogonal dimensions of time and space, using a plugin-based kernel to carry lifecycle and transaction semantics, and leveraging general-purpose cloud infrastructure for externalized state and observability is a clear path to building a foundation for long-running agents.