Agent Harness Architecture Explained: The Dual System of Plugins and Sessions

    This article breaks down the architecture of an agent harness as two parallel systems connected by an execution loop: a runtime plugin graph and an append-only event stream. It explains why "everything is a plugin" fails to capture the real architectural challenge, then examines five core plugin-graph mechanisms—capability visibility and dependency resolution, startup strategies for missing dependencies, scoped resolution of same-named capabilities, lifecycle and resource cleanup, and the compilation of static configuration into an inspectable runtime plugin tree. It also covers why the event stream must be append-only, the gap between a minimal loop and a production-grade harness, and practical implementation recommendations. Readers will gain a verifiable framework for reasoning about recoverability, extensibility, and observability in AI coding and agent systems.

    Agent Harness Architecture Explained: The Dual System of Plugins and Sessions

    1. Why “So Many Plugins” Does Not Explain a Harness

    In discussions of AI coding tools and general-purpose agent frameworks, a common summary is that the whole system is “all plugins.” That claim usually holds up at the source-code level, but it only describes how code is organized; it does not explain where the real architectural difficulty lies. A large number of plugins, each exposing a uniform installation entry point, is an engineering convention rather than an architectural signature.

    The questions that actually need answering are five interlocking ones:

    1. Which capabilities can a plugin see from its current position?
    2. Should a plugin start when a required capability is not yet available?
    3. Can the same capability name resolve to different implementations across sessions or scopes?
    4. When a plugin exits, who cleans up its registrations, listeners, child processes, and file handles?
    5. How does static configuration become a runtime plugin tree that can be updated and inspected?

    These five points belong to five distinct domains: dependency injection, startup sequencing, scope isolation, resource reclamation, and dynamic configuration. Most frameworks solve only one or two of them and leave the rest to developers to fill in with conventions and boilerplate. A production-grade harness is complex precisely because all five must be solved at the same time.

    2. Two Systems Running at Once

    A more useful way to understand this kind of harness is to view it as two systems running in parallel, joined by an execution loop.

    2.1 The Runtime Plugin Graph: What the System Is Made Of Now

    The plugin container maintains a directed graph. Nodes are plugin instances, and edges are capability dependencies. The graph records which capabilities are currently registered, what each plugin depends on, where it takes effect, and what must be reclaimed on unload. It is a present-tense structural snapshot of the system, changing continuously as plugins start and stop.

    2.2 The Append-Only Event Stream: What the System Just Did

    The session layer maintains an append-only log that is never modified. It records what actually happened during a unit of agent work: user input, model responses, tool calls and results, state changes, and errors and retries. The model context, the UI trace, and the data needed for recovery and forking are all projections of this log rather than separately stored copies.

    2.3 The Execution Loop: Sitting Between the Two

    The execution loop pulls the model adapter, tool registry, prompts, and session service out of the plugin graph, drives one round of “reason—call—write back,” and then writes the process back into the event stream. It holds no capability implementations itself and defines no log format; it only orchestrates.

    In one sentence: the plugin graph answers “what the system is made of,” and the event stream answers “what the system has done.” Together, the two lines form the actual subject.

    3. Five Key Mechanisms of the Plugin Graph

    3.1 Capability Visibility and Dependency Resolution

    Plugins should not reach for each other through global variables or direct references. Instead, they declare the capabilities they need, and the container resolves and injects them. Sketch:

    1. Plugin declares: { requires: ["model", "toolRegistry", "session"],
    2. provides: ["agentLoop"] }
    3. Container: resolve provider by scope -> inject -> call apply()

    The benefit is that swapping an implementation requires no change on the caller side: replacing the model adapter or the storage backend is just swapping one provider for another.

    3.2 Startup Strategy When a Required Capability Is Missing

    When dependencies are unmet, there are three strategies: wait (suspend until the capability appears), degrade (start in a restricted mode), or fail (exit with an explicit error). Production-grade implementations usually let a plugin declare a dependency as optional, so it can run in both a full environment and a minimal one. The key is that the strategy is declarative rather than scattered through business code as null checks.

    3.3 Scopes and Same-Named Capabilities

    The same configuration may exist in parallel across multiple sessions and multiple subtasks. If a capability is a global singleton, credentials, context, and tool policies will contaminate one another. Scoped resolution is therefore required: the same service name resolves to instance A in session A and instance B in session B, parent scopes can be inherited, and child scopes can override.

    3.4 Lifecycle and Resource Reclamation

    Plugin unload must be idempotent and thorough: unregister entries, remove event listeners, terminate child processes, and close handles and connections. A workable approach is for the container to maintain a .dispose stack per plugin, with the plugin registering a cleanup action at the same time it registers a resource, executed in reverse order on unload. Without this layer, a long-running host develops handle leaks and “ghost tools.”

    3.5 From Static Configuration to a Runtime Plugin Tree

    Declarative configuration (templates, manifest files) is instantiated into a plugin tree at startup, and nodes can still be added or removed afterward. Because the tree is inspectable, the operations side can query which capabilities are currently enabled, whether dependencies are complete, and which plugin provides a given capability, which significantly lowers troubleshooting cost.

    4. Why the Event Stream Must Be Append-Only

    Being append-only yields four direct benefits:

    • Context is projectable: the model context is a view computed from the event stream according to window and summarization rules, so compression does not destroy the original facts;
    • Recovery and forking: replaying from any event position produces a new branch, making it easy to compare different strategies;
    • The UI is a view: the interface subscribes to the same log instead of building a separate state channel, avoiding inconsistency between display and execution;
    • Auditability: errors, retries, and approval records leave a natural trace.

    Three engineering concerns need attention: versioning the event structure, external references for oversized results (keeping only a pointer and a summary), and incremental computation of projections, to avoid a full replay on every render.

    5. The Gap Between a Minimal Loop and a Production-Grade Harness

    A minimal loop takes only four steps: assemble the prompt, call the model, execute tools, and write results back. A production-grade harness must additionally handle model and credential management, session recovery and compression, tool policies and approvals, sandboxing and remote execution, multi-host adaptation, sub-agent orchestration, plugin hot-swapping, and how the UI observes the same body of runtime facts.

    If each of these capabilities maintained its own state, the system would quickly spiral out of control; assigning them separately to the two lines of the plugin graph and the event stream is what keeps the complexity bounded.

    6. Implementation Recommendations

    1. Define the capability list and naming conventions before writing plugins, to avoid capability fragmentation;
    2. Make all dependencies declarative injections, and prohibit direct cross-plugin references;
    3. Introduce scopes from day one instead of refactoring once multiple sessions appear;
    4. Pair resource registration with cleanup, and verify in tests that nothing is left behind;
    5. Reserve a version field in the event structure, and decouple projection logic from storage;
    6. Carry infrastructure such as storage, logging, and monitoring and alerting on general-purpose cloud service categories, keeping them replaceable;
    7. Accept the architecture on “inspectability”: whether you can answer at any time what the system is made of and what it just did.

    7. Conclusion

    Understanding a harness as “plugin graph + event stream + execution loop” is closer to engineering reality than “everything is a plugin.” The former provides verifiable design constraints; the latter is only a code style. In AI coding and agentic automation scenarios, this distinction determines whether a system can recover, can scale, and can be observed—and it is exactly the dividing line between production-grade and demo-grade.