Agent Orchestration Architecture: A Dual-Track Design with Runtime Plugin Graph and Append-Only Event Stream

    This article presents an orchestration architecture for production LLM agents in which model adapters, prompts, tools, session state, storage, sandboxes, the agent loop, and web interfaces are composed through a unified plugin mechanism. It explains how a runtime plugin graph manages system composition and state, how an append-only event stream preserves session history for recovery and projection, and how the agent main loop connects both systems. It also covers how configuration becomes a runtime tree, deployment considerations, and the trade-offs readers should evaluate before adopting this design.

    LLM applications are moving from single-turn question answering to multi-step autonomous execution. A production-ready agent framework must go beyond the basic loop of stitching prompts, invoking models, and executing tools. It must also handle model and credential management, session recovery, tool approval, sandbox isolation, sub-agent scheduling, and observation across multiple interfaces.

    This article discusses an orchestration architecture in which “everything is a plugin” and explains how two parallel systems handle this complexity. After reading, readers should be able to evaluate three design points—the runtime plugin graph, the append-only event stream, and the agent main loop—and understand when to adopt this architecture.

    1. How Five Engineering Problems Map to the Plugin Mechanism

    “Everything is a plugin” means that model adapters, system prompts, tool catalogs, session state, persistent storage, execution sandboxes, the agent main loop, and the web interface are all composed through the same mechanism. The value of a unified mechanism is that it centralizes the solution to five problems. The table below lists each problem, common risks, the corresponding plugin mechanism, and validation points.

    Problem Common risk Plugin mechanism Validation point
    Capability visibility Plugins access upstream and downstream capabilities beyond their permissions, deepening coupling Scope isolation and dependency injection A plugin can resolve only services within its authorized scope
    Startup prerequisites Plugins start before the model or storage is ready and then fail Declarative dependencies; delay mounting or degrade when dependencies are unmet When a dependency is missing, the system reports a clear status instead of crashing
    Polymorphic service resolution Implementations override each other under multi-tenant or multi-model routing Context-aware service lookup An interface with the same name resolves to different implementations in two sessions
    Lifecycle cleanup Listeners, child processes, and file handles leak Plugins must provide destroy hooks After unloading, process and handle counts return to baseline
    Static configuration to runtime After configuration changes, it is hard to locate which subtree is affected The loader maps configuration to an object graph After a hot update, topology matches configuration

    The cost of the plugin mechanism is debugging difficulty. As the number of plugins grows, dependency resolution, scope rules, and startup order become more complex. Teams need visualization tools for the dependency graph and startup logs; otherwise, troubleshooting costs can offset the benefits of the architecture.

    2. How the Runtime Plugin Graph Manages System State

    The runtime plugin graph answers the question: what does the system currently consist of? Nodes in the graph are active plugins, and edges are dependency relationships. Each node also records its scope, activation time, and the cleanup action to run when it is unloaded.

    For example, a session scope may contain a model adapter, a toolset, and a sandbox. When the user switches to another model, the framework only needs to replace the model node and revalidate dependencies; the tool and sandbox nodes remain unchanged. This local replacement depends on clear boundaries, so dependency declarations between plugins must be complete. Otherwise, replacement can leave invalid references behind.

    3. How the Append-Only Event Stream Preserves Session History Continuity

    The event stream answers the question: what did the system just do? Each reasoning result, tool call, and tool output is appended to the log as an event. Written events are not modified; changes are expressed only by appending new events.

    To make the event stream genuinely support session recovery, the following points need to be handled:

    1. Event versioning: each event type carries a schema version. After an upgrade, old logs remain readable, and conversion functions fill in new fields during reads.
    2. Idempotent replay: replaying the same log must produce consistent results. Tool call events record call identifiers, and recovery uses these identifiers to skip completed operations.
    3. Projection rebuild: the model context window and UI trace are both projected from the event stream. Projection functions should be pure, which makes them testable and allows a full rebuild after projection logic changes.
    4. Sensitive field redaction: credentials, personal information, and secrets returned by tools are redacted before writing. If raw content must be preserved, it should be encrypted in controlled storage and kept separate from ordinary logs.
    5. Retention policy: define the retention period for each event type. Events that path forking and session recovery depend on should be kept long term, while debug logs can be cleaned up daily.

    The boundary of the event stream also needs to be stated. It can guarantee traceable history, but it cannot guarantee that external side effects are reversible. Operations such as sending email, charging a payment, or deleting files require an additional compensation flow even when the event has been recorded.

    4. How the Agent Main Loop Connects State and History

    The agent main loop sits between the plugin graph and the event stream. It obtains services from the plugin graph, obtains context from the event stream, executes one reasoning and action cycle, and then writes the process back to the event stream. The following simplified pseudocode shows the key steps and exception handling:

    1. async def run_turn(session, graph, timeout_s):
    2. agent = graph.resolve("agent", scope=session.scope)
    3. model = graph.resolve("model_adapter", scope=session.scope)
    4. tools = graph.resolve_all("tool", scope=session.scope)
    5. ctx = project(session.events)
    6. append(session, Event("turn_started"))
    7. try:
    8. async with timeout(timeout_s):
    9. while True:
    10. reply = await model.generate(ctx, tools)
    11. append(session, Event("model_reply", reply))
    12. if not reply.tool_calls:
    13. break
    14. for call in reply.tool_calls:
    15. if not await approval.check(call):
    16. append(session, Event("tool_denied", call))
    17. continue
    18. result = await tools.run(call, retries=2)
    19. append(session, Event("tool_result", result))
    20. ctx = project(session.events)
    21. except CancelledError:
    22. append(session, Event("turn_cancelled"))
    23. raise
    24. except Exception as err:
    25. append(session, Event("turn_failed", error=redact(err)))

    This code has three key points. First, timeout is controlled by the outer layer to prevent the model or tools from waiting indefinitely. Second, tool calls have a limited number of retries, and retries apply only to retryable errors. Third, whether the turn succeeds, is cancelled, or fails, the outcome is written to the event stream, so replay shows the complete process. The cancellation event must re-raise the exception so the upper layer knows that the turn has ended.

    The main loop itself remains lightweight. It does not handle model authentication or manage sandbox processes. This decoupling allows tests to use fake models and fake tools without real services.

    5. How Configuration Becomes a Runtime Tree

    At startup, the framework first reads base configuration and feature packs, then overlays user patch configuration. Merging follows a fixed priority: user patches override feature packs, and feature packs override base configuration. The merge result must record the source of each value so it is clear which layer it came from.

    The loader then parses every configuration item, validates its type and value, and checks the dependency graph for cycles and missing required nodes. If any step fails, the system should roll back to the previous usable version and output the exact error location. Health checks run after mounting, and new nodes are marked available only after the checks pass.

    Hot updates have explicit boundaries. Adding plugins, modifying parameters, and replacing model adapters can be hot-updated. Changing the scope structure or removing a depended-on core plugin requires a session restart. Knowing these boundaries prevents a production runtime from mixing old and new states.

    6. Deployment and Cloud Landing

    In production, high-risk execution can be placed in containers. The sandbox plugin dispatches tasks to a container platform, which handles scheduling and isolation. Startup speed depends on image size, scheduler load, and network configuration, typically ranging from seconds to minutes. Isolation strength depends on the container runtime and security configuration, such as whether privileged mode is disabled.