AI Agent Harness Architecture: Plugin Graph and Event Stream

    This article examines the source-level architecture of an AI coding agent harness built on an "everything is a plugin" model. It explains how a single runtime handles visibility, dependency resolution, scoping, lifecycle cleanup, and configuration, and how the system runs as two parallel layers: a runtime plugin graph and an append-only event stream. Readers will learn how configuration becomes a runtime plugin tree, why the main loop stays small, and what to evaluate when assessing frameworks of this kind.

    AI Agent Harness Architecture: Plugin Graph and Event Stream

    In an environment with a Node.js toolchain, a one-off command can launch the web interface of an AI coding tool without a global install first. This article uses that kind of harness, where everything is a plugin, as the object of study and discusses its architecture and implementation at the source level. One caveat up front: frameworks like this are mostly in developer preview, so neither the current interfaces nor the paper-style target model should be treated as stable commitments. The discussion focuses on structure rather than version-specific features.

    One Plugin Package Is Not a Harness

    “Everything is a plugin” is the self-description these projects offer most often. The source code broadly supports the claim, but a large package count is not what gives the architecture its identity. What actually gets pluginized goes well beyond the tool set: model adapters, system prompts, the tool catalog, sessions, storage, sandboxes, the main loop, the web interface, and even several preset working modes are all assembled through the same mechanism.

    The distinctive part is that the runtime layer hosting those plugins also handles five problems that are usually kept separate:

    • Visibility: which capabilities a plugin can see from its current position.
    • Dependencies and startup timing: whether a plugin should start when a required capability is not yet present.
    • Scope resolution: whether services with the same name can resolve to different implementations in different sessions or scopes.
    • Lifecycle cleanup: who reclaims registrations, listeners, child processes, and file handles when a plugin exits.
    • Configuration to runtime state: how static configuration becomes a runtime plugin tree that can be updated and inspected.

    In traditional designs, these five concerns land in a dependency injection container, a service registry, module scoping, process management, and a configuration loader respectively. Pulling them into one mechanism is what makes composition a fact that can be verified at runtime, rather than a convention that exists only in the directory layout.

    Two Systems Running in Parallel

    A better way to understand this kind of harness is as two parallel systems.

    The first is the runtime plugin graph. It describes what the system is currently made of: which capabilities are online, what they depend on, which scope they take effect in, and how they are cleaned up on unload.

    The second is an append-only event stream. It records what actually happened during an agent run, and the model context, the interface trace, and the data needed for restore and fork are all projected from it.

    The main loop sits between the two: it obtains the model, tools, prompts, and session services from the plugin graph, then writes the result of each step back to the event stream. Put in one line: the plugin graph answers “what is the system made of right now,” and the event stream answers “what did the system just do.” Together, the two lines are the actual subject.

    This distinction also explains why a product-level framework cannot focus on the main loop alone. A minimal loop only needs to assemble the prompt, call the model, execute tools, and send results back to the model. A complete product also has to handle models and credentials, session restore and compaction, tool policies and approvals, sandboxes and remote execution, multiple host environments, sub-agents, plugin start and stop, and how the interface observes the same body of runtime facts. Compositional complexity is handed to the plugin graph, historical continuity is handed to the event stream, and the main loop therefore stays short.

    From Configuration to the Runtime Graph

    Startup does not directly construct a fixed application object. Instead, the loader first reads the Profile and the Bundle, layers the user Patch on top, and mounts configuration entries one by one as plugin instances. It can be understood as declarative assembly:

    1. Profile (base capability set) + Bundle (optional capability packs) + Patch (user overrides)
    2. ↓ loader mounts entries line by line
    3. runtime plugin tree (queryable, updatable, unloadable)

    This layering yields three direct benefits. First, the capability set can be trimmed, so a different host environment does not require changes to the main loop code. Second, override relationships are explicit: user changes are concentrated in the Patch layer, which makes review and rollback easier. Third, the runtime graph is inspectable, because the assembly result is a real tree rather than implicit initialization order scattered across modules.

    Visibility and Dependencies: Making “Later” Safe for Plugins

    The most common failure mode in plugin systems is initialization order coupling: A needs B to be ready, so delayed checks and retries get written everywhere. When visibility and dependency declarations are handled centrally by the runtime, a plugin only declares what it needs, and the framework decides when to start it and which implementation to inject. When a required capability is absent, the plugin stays inactive instead of exiting with an error, and it is brought up once the capability comes online. Adding or removing optional capabilities therefore does not disturb existing plugins.

    Scopes and Same-Name Services

    Resolving same-name services to different implementations across sessions or scopes is a key capability of this architecture. It lets parallel sessions, sub-agents, and temporary sandboxes each hold their own model client, tool allowlist, and storage handles, while plugin code does not need to know which scope it is in. Once resolution rules are centralized, permission boundaries have a single place to land: the scope is the boundary, and an out-of-bounds access shows up as a resolution failure rather than as scattered if statements.

    Lifecycle and Cleanup

    An append-only architecture is most afraid of leaks. When a plugin exits, event subscriptions, timers, child processes, and network and file handles degrade a long-running session if nobody reclaims them. Binding cleanup responsibility to the plugin unload action makes “installs and unloads” a verifiable property: hot updates, mode switches, and session teardown all go through the same reclamation path.

    The Event Stream: Source of Truth for a Single Run

    The event stream is append-only and never rewritten in place, and every record carries a type and a sequence number. Its value is that it serves several consumers at the same time:

    • Context projection: select and compact historical events by policy to form the model input for the current turn.
    • Interface trace: the interface subscribes to the same log and therefore shows runtime facts consistent with what the model sees.
    • Restore and fork: replay or copy from any position to obtain a new session branch.
    • Audit and replay: locating a problem does not depend on a snapshot of process memory.

    A sketch of the structure:

    1. {"seq": 12, "type": "tool.result", "scope": "session/s-7", "payload": {"ok": true}}

    Context compaction is therefore an adjustment to a projection policy rather than a destructive rewrite of history files, and forking means copying the prefix and appending a new branch, so the two histories do not interfere with each other.

    The Responsibility Boundary of the Main Loop

    The main loop does only four things: obtain capabilities, call the model, execute tools, and write events. It does not know how plugins register, and it is not responsible for how history is compacted. The clear boundary keeps replacement costs controllable: swapping the model adapter does not change the loop, swapping the storage implementation does not change the loop, and adding an approval step is just inserting a tool policy plugin.

    Engineering Takeaways

    • Draw the two lines first: model capability composition and execution facts separately, so state does not contaminate itself.
    • Declare dependencies: replace “wait for who is ready” with “what is needed.”
    • The scope is the permission boundary: resolve same-name services per scope, and make out-of-bounds access a resolution failure.
    • Give cleanup equal weight to loading: the unload path must be covered by tests.
    • Keep history append-only: context, interface, restore, and fork share one body of facts.
    • Layer configuration: base set, optional packs, user overrides, with an inspectable assembly result.

    Limitations and Assessment

    The structure above comes from reading and summarizing preview-stage source code; interface naming and assembly details may change, and the paper-style goal of composability in space and time is a direction rather than an existing capability. When evaluating frameworks of this kind, three questions are a useful test: whether capability visibility is managed centrally, whether scopes are genuinely isolated, and whether unload is verifiable. Only when all three hold is “everything is a plugin” more than a slogan. In actual deployments on cloud environments such as Baidu AI Cloud, model access, credential handling, logging and monitoring alerts, and containerized deployment should still follow general product categories and established best practices rather than the private conventions of any single framework.