Agent Harness Design: Composable Space and Time for Long-Running AI Agents
This article breaks down the composability problem in agent harness design into two orthogonal dimensions: time (when changes happen) and space (which unit carries a capability). It explains a plugin-based runtime skeleton, the four-stage pipeline behind lossless hot updates, and how database-style transactions map to fault tolerance and rollback. A selection checklist and common pitfalls are included for teams building self-evolving agents on general-purpose cloud infrastructure.
1. Why Long-Running Agents Demand More from the Harness
As agents move from single-turn prompt calls to long-running task execution, the agent harness is no longer just a container that runs a script. It becomes a runtime that must carry session state, a tool ecosystem, and the ability to evolve itself. Three requirements stand out in practice.
The first is dynamic extensibility with plug-and-play tools. An agent needs to generate, load, and unload external tools or third-party services on demand while a task is in progress. The tool set changes with the task phase instead of being fixed once 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 fix a defective tool. Such updates must take effect in place: without interrupting the current session and without losing accumulated memory or cached connections.
The third is fault tolerance with transactional rollback. Model-generated code can naturally contain syntax errors and logic exceptions, so the harness needs guarantees close to database atomicity, preventing one failed update from bringing down the whole process.
Traditional approaches, such as the plugin systems of coding assistants, container orchestration, and process-level isolation, mostly offer coarse-grained workarounds based on restarts. Updating a single plugin or service often means restarting the entire process or container. The cost is lost session memory, higher cold-start latency, and no way to express fine-grained dependency topology within the same address space.
2. Theoretical Foundation: Splitting Dynamic Composition into Two Orthogonal Dimensions
A widely adopted formal approach projects the dynamic composition problem onto two orthogonal dimensions, so each can be solved separately and then combined.
The time dimension is about when changes happen: the timing of a change, how it interleaves with calls already in flight, and the atomic boundary at which it takes effect. The core question is how the same state stays consistently visible before and after a change.
The space dimension is about which unit carries a capability: the granularity at which capabilities are split into replaceable units, how dependencies between units are declared, and where isolation boundaries are drawn. The core question is how the upstream and downstream of a unit remain intact when that unit is replaced.
The value of orthogonality is composability. Atomic commits in the time dimension can be designed independently of the dependency graph in the space dimension, and the product of the two covers most dynamic evolution scenarios. In engineering terms, this reduces to three invariants:
- Change atomicity: an update is either visible in full or has no effect at all.
- Explicit dependencies: units communicate only through declared contracts, with implicit global access forbidden.
- State portability: the state of a replaced unit must be handed over explicitly to the new unit.
3. Architecture: A Runtime Skeleton Where Everything Is a Plugin
Treating “everything is a plugin” as the guiding principle means the harness itself, tools, policies, and storage adapters are all isomorphic replaceable units. A minimal skeleton looks like this (illustrative):
class Plugin:name: strdeps: list[str] # Space dimension: explicit dependenciesdef setup(self, ctx): ... # Initialize and register capabilitiesdef teardown(self, ctx): ...# Release resources and hand back stateclass Harness:def __init__(self):self.graph = {} # name -> Pluginself.state = {} # Session memory, connection cachedef load(self, p: Plugin):for d in p.deps: # Load after topological sortingassert d in self.graphp.setup(self) # Assemble within the same address spaceself.graph[p.name] = pdef hot_swap(self, name, new: Plugin):old = self.graph[name]new.state_in = old.export_state()# Explicit state migrationnew.setup(self)old.teardown(self) # Roll back as a whole on failureself.graph[name] = new
Three points matter here. Assembly happens in the same address space, avoiding cross-process communication overhead. Dependency declarations drive load order, avoiding cycles and dangling references. State migration is a precondition for hot updates: without portable state, there is no such thing as a lossless update.
4. Key Mechanisms Behind Lossless Hot Updates
A lossless hot update breaks into a four-step pipeline, and a failure at any step returns to the pre-change snapshot:
- Preflight: syntax and static checks, dependency closure validation, contract compatibility comparison.
- Shadow assembly: the new unit initializes on a side path, taking traffic without affecting the main path.
- State handover: session memory, connection cache, and the context of unfinished tasks are serialized and transferred.
- Atomic switch: reference pointers flip in one operation, and the old unit’s resources are reclaimed afterward.
An illustrative transactional wrapper:
def transactional_update(h: Harness, name, new):snap = h.snapshot() # Snapshot before the changetry:h.preflight(new)h.shadow_assemble(new)h.migrate_state(name, new)h.commit(name, new) # Atomic switchexcept Exception:h.restore(snap) # Atomic rollback, session unaffectedraise
The practical recommendation is to keep snapshot granularity at the unit level rather than the process level; otherwise the cost of rollback cancels out the benefit of hot updates.
5. Fault Tolerance and Rollback: Bringing Database Thinking into the Runtime
Transaction semantics map onto the harness layer as follows: atomicity corresponds to “visible in full or not at all,” consistency corresponds to “dependency contracts are never broken,” isolation corresponds to “the main path is unaffected during shadow assembly,” and durability corresponds to “state is recoverable after handover.” Implementation recommendations include assigning a monotonically increasing version number to each change, retaining the last few versions for fast rollback, setting resource quotas and timeout circuit breakers for model-generated code, and writing failed changes to logging and monitoring alerts to close the observability loop.
6. Common Pitfalls and a Selection Checklist
Pitfall one is equating isolation with process isolation. Process isolation is safe but expensive; fine-grained topology needs unit-level isolation within the same address space, combined with contract validation.
Pitfall two is writing the implementation first and adding dependency declarations later. Dependencies must come first, otherwise the topology cannot be determined during a hot update.
Pitfall three is overlooking state migration. Stateless plugins are easy to replace; the real difficulty lies in stateful units.
When evaluating options, check item by item: does it support unit-level loading and unloading; does it provide state export and import interfaces; do changes support atomic commit and rollback; are dependencies explicit and verifiable; does it offer versioning and observability; and on top of general cloud capabilities such as container platforms, object storage, message queues, logging, and monitoring alerts, can the framework itself stay portable.
7. Conclusion
The competitive focus of agent harnesses is shifting from “getting a single call to work” to “evolving safely during long runs.” Splitting dynamic composition into two orthogonal dimensions, time and space, with an everything-is-a-plugin skeleton and three pillars of explicit dependencies, state migration, and transactional rollback, gives agents the ability to evolve sustainably on general-purpose infrastructure such as Baidu AI Cloud, while keeping change risk within a rollback-able and observable range.
