Spatiotemporal Composability: A Runtime Architecture for Dynamically Composable and Self-Evolving Agents
Long-running agents cannot rely on process restarts as a universal recovery mechanism. This article examines the runtime design problem behind dynamically composable and self-evolving agents, introduces the concept of spatiotemporal composability, and analyzes a lightweight runtime framework that implements atomic component replacement, state migration, validation, rollback, dependency checks, and temporal isolation. It also explains how this approach differs from conventional plugin systems and outlines open problems such as generalized state migration, sufficient validation, cyclic dependency deadlocks, and observability.
1. Starting Point: When “Restart” Is No Longer a Cure-All
In traditional software engineering, the most direct fallback for state corruption, plugin crashes, or version upgrades is to restart the process. Containerization makes this operation cheap and thorough: delete the old container, pull the new image, and start from zero. But for an Agent that needs to run for a long time, what does a restart mean? Session context is lost, short-term memory is cleared, the task chain in progress is broken, and the user experiences an interruption. More seriously, if the Agent already has a certain degree of autonomy—it can install tools on its own, replace memory modules, create sub-agents, switch sandbox environments, or even modify its own runtime logic—then once it “breaks itself,” who triggers the restart? Who completes the repair after the restart? If it performs a self-change during an unattended nighttime task, the human manager the next morning may face a wreck that can neither be recovered nor rolled back.
This is not a science fiction scenario. More and more agent systems support dynamic plugin loading, remote policy updates, and hot-swapping of inference engines. But most implementations still remain at the “plugin framework” level: all components are mounted in the same context and can be added, removed, or replaced, but the granularity, timing, and safety of replacement lack system-level guarantees. Once a component’s interface contract changes, or a new component has an implicit dependency on old state, the entire runtime falls into an unpredictable intermediate state. An open-source community once experienced an incident: an Agent replaced its memory retrieval module during operation. The new module’s vector dimension was incompatible with the old cache index, causing all subsequent queries to return empty results. The Agent could not detect this degradation by itself, and eventually became completely stuck after dozens of conversations.
Therefore, the real question is: how can we design a runtime architecture that allows components to be composed online, decomposed online, and replaced online while guaranteeing state consistency, timing correctness, and fault recoverability across the system? This requires rethinking from the foundation of the programming paradigm.
2. Core Paradigm: Spatiotemporal Composability
In recent years, an academic paper has specifically discussed this problem and proposed the concept of “Spatiotemporal Composability.” Its core idea is not complicated: any software component occupies certain “time” and “space” resources. Space refers to physical resources such as memory, file handles, and network connections. Time refers to the order and duration of state operations during component execution. Traditional composition methods only focus on spatial dependencies—for example, module A calls module B—but ignore temporal constraints: can B be replaced while A is executing? Will B’s replacement affect A’s unfinished transactions? Spatiotemporal composability requires that every component in the system explicitly declares its “time boundary” and “space boundary,” and the runtime uses these boundaries to decide when composition is allowed, when isolation is required, and when replacement is safe.
Specifically, a component is split into three parts:
- State Container: stores all mutable state required for component operation. It is managed uniformly by the runtime; the component itself does not hold it directly.
- Behavior Function: a pure functional logic implementation that receives input only through parameters and returns output without touching external state.
- Lifecycle Hooks: callbacks including pre-start, pre-stop, on-replace, and on-rollback, used for resource cleanup, state migration, and dependency checks.
Under this model, replacing a component is no longer a simple matter of unloading the old module and loading the new module. It is a controlled “transaction”: the runtime first serializes the old component’s state and migrates it to the new component’s state container, then runs a “smoke check” on the new component to confirm that its behavior meets expectations, and only then switches routing. During the entire process, calls to the replaced component from other components are briefly blocked or redirected to a shadow instance, thereby ensuring temporal atomicity.
3. From Paradigm to Implementation: Anatomy of a Runtime Framework
To validate the above theory, an open-source community developed a lightweight runtime called Cordis (a neutral label used here for a dynamic composition library). It is designed to be embeddable in any host application and to serve as the underlying scheduler for agent frameworks. Using Cordis’s core code structure as an example, we analyze how it implements spatiotemporal composability.
3.1 Context and Composition Units
All components in Cordis are treated as composition units (Units). Each Unit has a unique identifier and a set of dependency declarations. The runtime maintains a global Context. This Context is not a simple key-value store, but a versioned state graph. Each Unit can read or write specific nodes in the Context, but it must use the API provided by the runtime rather than directly referencing memory addresses.
// Pseudocode illustrationinterface Unit {id: string;dependencies: string[]; // IDs of other Units this Unit depends onstate: Record<string, any>; // Mutable state hosted by the runtimeactivate(ctx: Context): Promise<void>;deactivate(ctx: Context): Promise<void>;migrate(ctx: Context, from: Unit, to: Unit): Promise<void>;invoke(ctx: Context, input: any): Promise<any>;}
The key point is the migrate method: it is responsible for migrating the old Unit’s state to the new Unit. Note that the new Unit does not need to be fully compatible with the old Unit’s state structure; it only needs to implement the migration logic. This means we can replace an exact-match string memory module with a vector-retrieval-based semantic memory module, while the old cache can be discarded or converted.
3.2 Atomic Transactions for Dynamic Replacement
When an external instruction (or the Agent itself) requests replacement of a Unit, the runtime executes the following transaction steps:
- Freeze calls: mark the Unit as “migrating.” New incoming call requests enter a waiting queue, or the runtime returns a “temporarily unavailable” notice.
- Export state: call the old Unit’s
exportState(internal implementation) to serialize state into JSON or binary format. - Instantiate the new Unit: create a new Unit instance, inject dependencies, and call its
importStateto receive the old state (conversion is allowed). - Validate: run preset smoke test cases (such as a set of input-output pairs) to ensure that the new Unit’s core behavior is correct. This step is optional but strongly recommended.
- Switch references: map the old Unit’s identifier to the new instance in the Context and release all resources of the old instance.
- Unfreeze: process calls in the waiting queue and route them to the new instance.
During the entire transaction, other Units do not perceive that replacement has occurred, because they always access the Unit through the runtime Context rather than holding direct references. This guarantees isolation in “space”—replacement happens only internally.
3.3 Safety in Self-Evolution Scenarios
The above mechanism allows an Agent to safely modify itself. Suppose an Agent decides to upgrade its prompt template (which is also a Unit). It only needs to call the replaceUnit API provided by the runtime and pass in the code of the new template. But to prevent it from “breaking itself,” the runtime also provides the following safety protections:
- Rollback snapshots: before each replacement, automatically save an image of the previous Unit (including state and code). If the new Unit fails during validation, or triggers an exception-rate threshold after running for a period of time, it can be automatically rolled back.
- Dependency conservation check: the dependency set declared by the new Unit must cover all dependencies of the old Unit; otherwise, replacement is rejected. This rule prevents indirect crashes caused by missing dependencies.
- Temporal isolation: each Unit’s
invokemethod has a soft limit on maximum execution duration. If it times out, the runtime forcibly interrupts it and marks the Unit as “unhealthy,” prioritizing replacement. - Session event log: all replacement operations, state migrations, and validation results are written to an immutable log. This supports post-hoc auditing and also provides data for training Agents in the future to identify which replacement strategies are optimal.
4. Essential Differences from Conventional Plugin Systems
Many people will ask: isn’t this just a plugin system? The difference lies in three dimensions:
- State ownership: traditional plugin systems usually let plugins manage their own state (such as global variables or their own databases), and the host is only responsible for loading and invoking them. Here, state is extracted into the hands of the runtime, and plugin code is only stateless functions, making migration and rollback feasible.
- Replacement timing: traditional plugins can only be unloaded when not in use (for example, stopping the service before replacement) and cannot achieve “hot replacement.” Spatiotemporal composability allows replacement while the service is running, even in the middle of a request (through temporal boundary constraints), as long as the old and new versions agree on the state interface.
- Autonomy: traditional plugin systems are oriented toward human managers, and replacement is decided by humans. Here, the goal is for the Agent to initiate replacement instructions based on environmental feedback or its own policy, while the runtime is responsible for determining whether replacement is safe and whether rollback is possible.
5. Current Implementation and Open Problems
Using a real case as a reference, the repository of an agent framework has fully implemented the above runtime and applied it to the following scenarios:
- Dynamically switching large language model backends (for example, from a general model to a code-specialized model) without restarting the session;
- Adding a web search tool during a conversation and then automatically uninstalling it based on error rate;
- Replacing the short-term memory module with layered long-term memory, with smooth state transition;
- Running sub-agents in isolated sandboxes that can be dynamically created or destroyed by the parent Agent without affecting each other.
However, several key problems remain unsolved:
- Generalization of state migration: current migration logic must be manually written by developers for old and new versions; fully automatic state mapping has not yet been achieved.
- Sufficiency of validation: smoke tests can only cover limited scenarios and cannot guarantee that the new version is correct under all unknown inputs. How to generate richer test sets remains an open problem.
- Cyclic dependencies and deadlocks: when an Agent replaces certain foundational runtime components (such as the event loop scheduler), it may fall into a self-referential deadlock. The runtime needs an additional watchdog mechanism to detect such anomalies.
- Visualization of long-running state: there is no intuitive tool for human managers to observe internal state flows and replacement processes, and debugging remains difficult.
6. Conclusion
Understanding “spatiotemporal composability” and the runtime built on it is key to breaking the “restart dependency.” It gives Agents the ability to safely transform themselves during operation without causing the entire system to collapse due to loss of control. This design philosophy applies not only to Agents but also to any distributed system that needs hot updates and zero-downtime evolution. In the future, as self-evolving Agents gradually move into production environments, this underlying paradigm will become an infrastructure-level necessity that every developer should master early.
References and Further Reading
- For the complete theory of spatiotemporal composability, consult the relevant academic paper repositories.
- The official documentation of an open-source framework provides detailed component migration tutorials and transaction log format descriptions.
- Readers are encouraged to simulate a modular service that supports hot replacement in a local sandbox to experience state migration and rollback mechanisms firsthand.
