Plugin Agent Harness Architecture: Runtime Plugin Graph and Append-Only Event Stream

    This article breaks down a plugin-based Agent Harness architecture for production AI coding tools and multi-agent platforms. It explains why a minimal agent loop is not enough, how a runtime plugin graph handles capability visibility, dependency startup policies, scoped resolution, lifecycle cleanup, and hot updates, and how an append-only event stream supports context projection, UI traces, recovery, and forking. It also covers startup from configuration and practical engineering recommendations.

    Plugin-Based Agent Harness Architecture Explained

    1. Background: Why a Production Harness Is More Than an Agent Loop

    In AI coding tools and multi-agent platforms, the minimal working agent loop usually has four steps: assemble the prompt, call the model, execute tools, and return the results to the model. That loop is enough for a demo, but it is not enough for production. A real system must also handle model and credential management, session recovery and compaction, tool policies and approvals, sandboxes and remote execution, multiple host environments, sub-agent orchestration, plugin startup and shutdown, and how the UI observes the same runtime facts.

    If all of these capabilities are written into one fixed application, the system quickly becomes a hard-to-maintain monolith: any capability change can affect the startup flow, and any historical state change can affect execution logic. A more reasonable approach is to split the complexity into two cooperating main lines.

    The first main line maintains “what the system is currently composed of.” It is a runtime plugin graph that describes which capabilities exist, what they depend on, where they take effect, and how they are cleaned up when unloaded. The second main line maintains “what the system just did.” It is an append-only event stream that records what actually happened during an agent run and projects the data needed for model context, UI traces, recovery, and forking. The agent loop sits between them: it obtains models, tools, prompts, and session services from the plugin graph, then writes the execution process back to the event stream.

    The key value of this split is that composition complexity and historical continuity are governed separately. The plugin graph solves capability assembly; the event stream solves fact recording. The two connect through explicit interfaces rather than leaking into each other.

    2. Runtime Plugin Graph: Five Problems That Are Usually Separate

    “Everything is a plugin” is not enough to explain a mature harness. What makes it distinctive is that the same plugin mechanism handles five problems that are usually treated separately.

    2.1 Capability Visibility

    Which capabilities a plugin can see at its current location determines whether it can call models, read and write sessions, access storage, or start child processes. Visibility should not be a global-variable style “available everywhere”; it should be computed by the plugin graph according to scope. This way, a tool plugin can only see the authorized tool registry, and a UI plugin can only see the session views it is allowed to project.

    An illustrative configuration can be expressed as:

    1. plugins:
    2. - id: model-adapter
    3. provides: [model]
    4. - id: tool-registry
    5. depends: [model]
    6. provides: [tools]
    7. - id: web-ui
    8. depends: [session]

    2.2 Startup Policy When Dependencies Are Missing

    Whether a plugin should start when a required capability is not yet available is a question that production systems must answer. There are three common strategies: wait until the dependency appears and then start, fail to start and report the missing capability, or run in a degraded mode. The plugin graph should make the policy explicit instead of hiding it in code branches.

    2.3 Scoped Resolution for Same-Named Capabilities

    Whether the same service name can resolve to different implementations in different sessions or scopes directly determines whether multi-tenant and multi-session isolation are reliable. For example, different sessions can bind to different model adapters, different sandboxes, or different approval policies. Resolution rules should support “nearest override,” meaning a child scope first matches its own registrations and falls back to the parent scope when there is no match.

    2.4 Lifecycle and Resource Cleanup

    When a plugin exits, who cleans up registrations, listeners, processes, and handles is central to the stability of a long-running system. The plugin graph should maintain ownership for each instance and release resources in reverse registration order during unloading, avoiding listener leaks, leftover temporary directories, and runaway child processes.

    2.5 From Static Configuration to an Inspectable Runtime Tree

    How static configuration becomes a runtime plugin tree that can be updated and inspected determines whether the system supports hot updates and observability. After configuration entries are mounted one by one as plugin instances, the runtime tree should support querying the current node, dependency status, scope, and version, so that operations and debugging no longer rely on guesswork.

    3. Append-Only Event Stream: Recoverable and Projectable Runtime Facts

    The event stream is append-only and is never modified in place. Every model call, tool execution, approval result, error, and retry becomes an event. Its value is not just logging; it is a data source that can be projected.

    • Model context: project messages and tool results in order, with support for compaction policies.
    • UI traces: project the same facts into readable steps, avoiding separate state maintenance in the UI and the execution logic.
    • Recovery and forking: rebuild a session from a given event position, or copy history and take a different branch.

    An illustrative event structure:

    1. {"type":"tool_call","id":"t1","name":"read_file","args":{"path":"a.txt"}}
    2. {"type":"tool_result","id":"t1","ok":true,"data":"..."}
    3. {"type":"approval","id":"t1","decision":"allow"}

    Because events are immutable, the recovery process can repeatedly execute projection logic, reducing the risk of “state drift.”

    4. From Configuration to Runtime Graph: Startup and Hot Updates

    At startup, the system should not directly construct a fixed application. Instead, it first reads the Profile and Bundle, then layers on the user Patch, and the loader mounts configuration entries one by one as plugin instances. The benefit is that environment differences are absorbed by configuration rather than by code branches.

    During a hot update, only the affected subtree is replaced: first mount the new instance and validate dependencies, then switch the resolution entry point, and finally unload the old instance and clean up resources. The whole process can be verified through runtime tree checkpoints, and rolled back to the previous version if it fails.

    5. Engineering Recommendations

    1. Define capability contracts before writing plugin implementations to avoid implicit global dependencies.
    2. Establish test cases for missing dependencies, same-name overrides, and unload cleanup.
    3. Keep the event stream immutable and test projection logic separately.
    4. Connect observability to common logging services, monitoring and alerting, and object storage for long-term archiving and auditing.
    5. In cloud environments such as Baidu AI Cloud, container platforms and message queues can be used to isolate plugin instances and distribute events asynchronously, but interfaces should remain neutral to avoid tight coupling with a specific implementation.

    Overall, the competitiveness of a plugin-based harness lies not in the number of plugins but in the coordinated governance of the plugin graph and the event stream. The former answers “what it is composed of,” and the latter answers “what it did.” The agent loop only handles orchestration, so the system gains product-grade capabilities that are composable, recoverable, and operable.