Dynamic Composition as the Runtime Foundation for Self-Evolving Agents
Self-evolving agents are limited less by a single model call than by the host that registers tools, routes context, recovers from failure, and applies structural change without breaking in-flight work. This article argues for a formal dynamic-composition model—invariants, generations, transactional submit, and rollback—before chasing another model iteration.
The capability ceiling of an agent system is rarely set by one model invocation. It is set by the host: how tools are registered, how context flows, how failures recover, and whether a structural change mid-run tears down work already in progress. If the framework only takes effect after a restart, self-evolution stays an offline script. If it allows live recombination without invariants and rollback, autonomous edits can destroy the current session. Discussion of self-evolving agents should therefore start from the formal basis of dynamically composed programs, not from a single model update.
Why the host matters more than a single inference
One inference answers “what to say now.” Long-running work must also answer where capability comes from, who owns state, and when a change becomes live. The usual pattern is a fixed pipeline for retrieval, code execution, browser actions, and approval. Pipelines are clear, but every new capability forces a change to the main loop and a restart. For always-on assistants, watch processes, and multi-turn collaboration, downtime means lost context, repeated external side effects, or tasks that cannot resume.
A better abstraction: the main loop only schedules and enforces invariants; capabilities attach as composable units. Units have a lifecycle, declared dependencies, and an effect boundary. Model, UI, and language are implementation choices. When the paradigm is right, teams can evolve different runtimes in different languages and still compare the same questions: hot swap, failure isolation, and commit or rollback of a structural change without breaking in-flight tasks.
Models change with pretraining and post-training; interfaces change with product shape. What lasts is the contract for how the runtime may be rewritten safely. Any current stack is one instance of that contract. The community may swap modules, retune policy, or let the agent propose its own extensions—but proposals must pass the host’s validation and commit protocol, not mutate arbitrary in-memory objects.
Invariants dynamic composition must keep
“If it loads, it runs” is not enough for self-evolution. At least these invariants should be explicit.
First, continuity of in-flight work. When a structural change commits, calls already bound to the old implementation must finish or migrate under an explicit policy. Empty references after a module-table swap are not acceptable. Treat a call as executing on a generation: dependency resolution is frozen inside that generation; the new generation only takes new requests. Hot update then cannot splice a half-finished tool call onto an incompatible implementation.
Second, consistency of the dependency closure. Units declare services they need and provide. Before commit, check the closure: required dependencies exist, removing a service does not leave dangling consumers, version constraints are satisfiable. Failure rejects the whole change so the graph is never half-loaded.
Third, effect boundaries. Pure computation, external reads, external writes, and long-lived resources should be graded. Prefer hot-swapping units with no external side effects or with idempotent compensation. Actions that pay, send mail, or change production config should require human confirmation or two-phase commit, not a model rewriting the host.
Fourth, observability and rollback. Each change produces a generation id, a diff, and health-check results. If error rate, timeouts, or leaks exceed thresholds during a grace period, revert to the previous generation. Self-modification without rollback is remote execution of arbitrary code.
A simple model: runtime state is the set of active units and their wiring; a change is a transaction from one consistent state to another; transactions and in-flight calls are isolated by generation. Design notes that state “no restart and no broken current tasks” as a checkable property, not a slogan, outlast feature lists. Engineering then puts that property into the loader, the resolver, and the call proxy.
A runtime skeleton
Neutral pseudocode for the commit protocol, unbound to a framework:
generation = 0active = resolve(graph_v0)submit(next_graph):check_closure(next_graph)check_compat(active, next_graph)candidate = resolve(next_graph)health = probe(candidate)if not health.ok: rejectgeneration += 1# in-flight calls keep the active snapshot captured at entryswap_router(candidate, generation)schedule_retire(previous, after=inflight_done)
On entry, a call captures the current generation’s resolution instead of rereading a global table. Swapping the router then cannot tear a single call. Retirement must release timers, connections, and subscriptions, and confirm there are no dangling cancel callbacks. Units that hold session memory should declare a migrate function; state without one is not hot-migratable, so the change is rejected or forced onto a new session.
For isolation, prefer in-process module boundaries plus a permission list; put high-risk tools in a worker process with restricted messages. The list covers readable config, writable paths, allowed network destinations, and callable services. When the agent proposes “install a new tool,” the host accepts only complete declarations, satisfiable dependencies, and permissions inside policy. Missing declarations are rejected; prompts are not the control plane.
What self-evolution should and should not change
Self-evolution is often read as the model endlessly rewriting its main program. A safer scope is add or remove tools at allowed extension points, tweak prompt fragments, switch retrieval or memory policy, and tighten or loosen timeouts and retries. The main loop, authentication, audit log, and permission decisions should stay read-only or upgrade only under control.
A useful autonomous improvement is a small transaction: observe failure samples, propose a unit-level patch, replay recent traces on a shadow generation, and commit only if metrics do not regress. Replay should cover success paths, tool timeouts, user cancel, and external dependency failure. A patch that only passes the happy path should not enter the active generation.
Evaluation need not fixate on GUI versus terminal or on language. Ask: are changes transactional; are in-flight tasks bound to the old generation; can failure auto-rollback; are external side effects labeled and limited; can audit answer who changed the runtime from A to B and when. If those five have clear answers, the paradigm can be reimplemented elsewhere. A stronger model is still only one participant proposing changes inside that host.
Common mistakes in practice
Treating hot load as hot update: files change, but old closures still call old functions, or new code reads old global singletons; behavior mixes and cannot roll back. Implicit conventions: units “happen” to get services from start order, so the graph cannot be checked. Side effects scattered in ordinary functions, so replay and compensation fail. Letting the model edit core scheduler source and apply it immediately, which hands the host’s safety boundary to one sample.
A better order: split capabilities into units with lifecycle and declared dependencies; bind each call to a generation; add pre-commit closure checks and health probes; only then expose “propose a change” to the model. Reverse the order and self-evolution only amplifies incidents.
Logs and metrics should at least include generation id, change diff, probe results, in-flight call count, and rollback reason. Debug generation first, model output second. Otherwise a torn runtime is misread as model hallucination.
Implications for agent systems
Model iterations will continue. Long-running agents need a host that can be discussed formally: composition is dynamic, commit is transactional, tasks are continuous, failure is rollbackable. Once that meta-layer is stable, implementations can share ideas without locking to one release. Teams that invest in invariants, isolation, and replay—rather than only larger context windows—are more likely to improve on real tasks without wrecking the live system.
Formalization does not require a heavy theorem stack. Write state, generation, transaction, and effects as a shared checklist and enforce it in the runtime, and “self-modifiable” moves from a demo to an operable capability. That is closer to the substrate self-evolution needs than another wrapper of prompts.
