Dual-Engine Architecture of AI Coding Tools: Runtime Plugin Graph and Append-Only Event Stream

    This article breaks down the dual-engine architecture behind production-grade AI coding agents: a runtime plugin graph and an append-only event stream, connected by a narrow execution loop. It explains how configuration becomes an inspectable plugin tree, how scoped service resolution, dependency readiness, and cleanup keep plugins pluggable, and how an event log plus projections support context compression, UI rendering, recovery, and forking. It closes with practical engineering guidance and risk notes for teams building similar systems.

    Dual-Engine Architecture of AI Coding Tools: Runtime Plugin Graph and Append-Only Event Stream

    1. Why “lots of plugins” does not explain a production-grade coding agent

    AI coding tools are often marketed with a simple message: everything is a plugin. But plugin count alone does not explain where the real complexity of a production system comes from. A minimal working agent loop needs only four steps: assemble the prompt, call the model, execute tools, and feed tool results back to the model. A shippable product must also handle model and credential management, session recovery and context compression, tool policies and approvals, sandboxes and remote execution, multiple host environments, sub-agent orchestration, dynamic plugin startup and shutdown, and how the UI observes the same runtime facts.

    These capabilities are tightly coupled. Stacking them in a monolithic codebase quickly leads to a state where changing one thing breaks everything. A more reasonable abstraction is to view the system as two mechanisms that run at the same time with orthogonal responsibilities:

    • A runtime plugin graph: describes which capabilities exist, what they depend on, where they take effect, and how they are cleaned up on unload;
    • An append-only event stream: records what actually happened during a task and projects the data needed for model context, UI traces, recovery, and forking.

    The execution loop sits between the two: it obtains the model, tools, prompts, and session services from the plugin graph, then writes the execution back into the event stream. The graph answers “what the system is made of right now”; the stream answers “what the system just did.” Together they form a complete agent.

    2. Runtime plugin graph: turning static configuration into an inspectable runtime structure

    2.1 From configuration to the runtime graph

    At startup, the system does not directly construct a fixed application object. It first reads a Profile and Bundles, then layers user Patches on top, and a loader mounts configuration entries one by one as plugin instances. The key design here is configuration as an assembly script: configuration is not a pile of switches, but a runtime plugin tree that can be updated and inspected.

    Illustrative configuration (neutral pseudocode):

    1. profile: default
    2. bundle:
    3. - model-adapter
    4. - prompt-registry
    5. - tool-catalog
    6. - session-store
    7. - sandbox-runner
    8. - web-host
    9. patch:
    10. - id: tool-catalog
    11. options: { allow: [read, write, search] }

    The loader resolves dependencies line by line and instantiates them layer by layer. Any line can be overridden by a Patch, producing an assembly result that is reproducible and auditable.

    2.2 Five problems the plugin runtime solves at once

    What makes this design distinctive is not “many packages” or “every package has an apply()”, but that the same mechanism handles five problems that are usually kept separate:

    1. Visibility: which capabilities a plugin can see at its current position, avoiding global namespace pollution;
    2. Dependency readiness: whether a plugin should wait when a required capability is not yet available, instead of crashing;
    3. Scope resolution: whether services with the same name can resolve to different implementations in different sessions or scopes;
    4. Lifecycle cleanup: who reclaims registrations, listeners, child processes, and file handles when a plugin exits;
    5. Dynamic configuration: how static configuration becomes a runtime tree that can be updated and inspected.

    Together, these five points turn “pluggable” from a slogan into an engineering constraint.

    2.3 The practical value of scoped service resolution

    Resolving the same service name to different implementations across sessions is the foundation for multi-session isolation and sub-agents. For example, two sessions can each bind a different credential context and tool allowlist, while plugin code does not need to know which session it runs in. A common implementation uses a scope chain plus service tokens: a plugin declares the token it needs, and the runtime walks up from the current scope to find the nearest implementation.

    1. scope(session-A) -> service(model) = adapter-A
    2. scope(session-B) -> service(model) = adapter-B
    3. scope(global) -> service(log) = shared-logger

    2.4 Graceful unload and resource reclamation

    When a plugin exits, cleanup responsibility must be explicit; otherwise long-running processes develop handle leaks and ghost listeners. A workable approach is to register all four resource classes—registrations, listeners, processes, and handles—in a cleanup list owned by the plugin itself, release them in reverse order on unload, and emit warnings for anything left unreleased, so problems can be located quickly during development previews.

    3. Append-only event stream: making “what happened” replayable

    3.1 The basic shape of the event stream

    The session layer maintains an append-only event log that is never modified. Each event contains at least a sequence number, a type, a timestamp, and a payload. Event types can cover user input, model requests, model responses, tool calls, tool results, approval decisions, errors, and recovery markers.

    1. #1 user.message
    2. #2 model.request
    3. #3 model.response(tool_calls)
    4. #4 tool.call(read)
    5. #5 tool.result
    6. #6 model.request
    7. #7 model.response(final)

    3.2 Projections: from log to multiple views

    The event stream itself is not the context; it is the source of truth. Projections derive:

    • Model context: a message sequence trimmed and summarized according to window and compression policies;
    • UI trace: a timeline the host UI renders entry by entry;
    • Recovery and forking: replay from any sequence number, or copy the log from a given point into a new branch.

    This “log plus projections” structure keeps context compression, UI rendering, and recovery logic from interfering with each other.

    3.3 Recovery, compression, and forking

    Recovery means replaying events from persistent storage and rebuilding projections. Compression summarizes at the projection layer without changing the original log. Forking copies the tail of the log from a given sequence number to form a new session. All three share the same source of truth, which prevents the “what the UI shows” and “what the model sees” from diverging.

    4. Execution loop: between the plugin graph and the event stream

    The execution loop has a narrow but critical job: get services from the plugin graph, write facts to the event stream. Pseudocode:

    1. loop(session):
    2. ctx = projector.build(session)
    3. req = prompt.compose(ctx)
    4. resp = services.model.call(req)
    5. append(session, model.response(resp))
    6. for call in resp.tool_calls:
    7. if services.policy.need_approval(call):
    8. append(session, approval.request(call))
    9. continue
    10. result = services.tools.run(call, scope=session)
    11. append(session, tool.result(result))

    The loop itself is unaware of any specific model, tool, or storage; everything is resolved through service tokens. That is exactly where the value of the plugin graph lies.

    5. Engineering recommendations and risk notes

    1. Define the event schema before writing the loop. Once event types are stable, projections, recovery, and the UI have a shared foundation.
    2. Make dependency declarations explicit. Deferred startup is better than crashing at startup, but “waiting” must be observable.
    3. Cleanup responsibility travels with the plugin. Every registration and listener goes into the plugin’s cleanup list.
    4. Scope boundaries must be testable. Write concurrency and cross-talk test cases for multi-session isolation.
    5. State preview boundaries clearly. Such systems are typically in early preview, and interfaces and target shapes may change, so they should not be treated as stable commitments. For production selection, rely on publicly available, stable general capability categories as external dependencies (such as object storage, message queues, container platforms, logging services, and monitoring and alerting), and avoid binding to interfaces that are not yet finalized.

    6. Conclusion

    Understanding an AI coding tool as a dual-engine structure of “plugin graph + event stream + execution loop” is closer to the engineering reality than “lots of plugins.” The plugin graph handles composition and lifecycle, the event stream handles history and replayability, and the execution loop only connects them. With clear boundaries among the three, the system gains production-grade capabilities: pluggability, recoverability, and observability.