Building a Plugin-Based Agent Runtime Framework: Architecture Breakdown and Design Trade-offs
An agent runtime built around large language models needs to separate how the execution loop operates from what each step actually does. This article breaks down a plugin-based agent framework design, covering its five-layer architecture, core concepts such as Session, Turn, and Step, append-only session logging for replay, branching, and resumable execution, a comparison of four common agent implementation approaches, and practical considerations around permissions, sandboxing, and idempotency when deploying such a system.
Why the Execution Framework Matters
A large language model (LLM) based agent typically combines model calls, tool execution, context management, state tracking, and permission control. Early-stage projects often cram all of this logic into a single main loop. As features accumulate, that loop becomes increasingly hard to modify. Adjusting tool selection strategy, inserting a human approval step, or switching models usually means touching core code, with changes rippling in unpredictable ways.
The core problem an execution framework solves is separating “how the loop runs” from “what each step does.” The framework provides a stable foundation, while business capabilities plug in as modules. This way, changing one capability never requires touching the whole execution flow.
Three Principles of Plugin-Based Design
Plugin-based design generally follows three principles.
1. Capabilities are replaceable
File I/O, command execution, sandbox isolation, sub-agents, permission approval, and log persistence each exist as independent modules. Operations teams decide through configuration which modules to enable; disabled modules neither run nor consume resources.
2. The kernel contains no business logic
The kernel handles only three things: plugin lifecycle management, dependency resolution and load ordering, and event dispatching. It never decides business questions like “is this tool call safe?”—those judgments belong to the corresponding plugin. The thinner the kernel, the lower the risk of upgrading or replacing it.
3. The loop itself is replaceable
The agent’s execution loop is itself a swappable unit. The default loop can be replaced with a “plan first, execute later” strategy, or one with multi-step self-checking. Replacement only involves a configuration change and a new module—no need to fork the entire project.
Here is an illustrative configuration snippet to show the structure; it is not the real syntax of any specific product:
loop: default-loopplugins:- file-io- sandbox-shell- approval- session-log
Layered Architecture
A typical reconfigurable foundation is organized into five layers. Upper layers depend on lower ones, plugins depend on interfaces defined by the core layer, and the core layer never depends on any concrete plugin.
Product entry layer
Provides interaction surfaces such as a web interface and a command-line program. This layer only receives input, renders output, and calls core-layer interfaces—it carries no execution logic.
Core layer
Defines data models such as Session, Turn, and Step, manages the tool registry, and assembles system prompts. It is the business center of the framework, but it doesn’t care which model or sandbox is actually in use.
Kernel layer
Loads configuration, resolves plugin dependencies, starts and stops plugins in order, and connects modules through an event bus. Kernel code is usually small in size but held to high stability standards.
Model adaptation layer
Provides a unified abstraction over different LLM service APIs. Each new model service requires only one adapter plugin; upper-level business logic stays unchanged, and switching models is a configuration change.
Plugin layer
Includes command execution, file operations, sandbox isolation, sub-agents, permission approval, and session persistence. Each plugin focuses on one class of capability and communicates with the core layer through interfaces.
Additionally, such frameworks often provide SDK wrappers in other languages to ease integration with existing systems.
Core Concepts
To understand the framework, start with these concepts.
Session
The context container for a complete interaction, holding message history, tool call records, and current state. A session can span multiple rounds of user input.
Turn
The process from one user input to the agent’s final reply. A single Turn may contain multiple rounds of model inference and tool calls.
Step
The smallest recordable unit within a Turn, typically corresponding to “one model inference plus a batch of tool calls.” Step is the base granularity for replay, branching, and resuming from checkpoints.
The relationship can be summarized as: a Session contains multiple Turns, and a Turn contains multiple Steps.
Tool registration
Tools are registered declaratively, including name, parameter schema, and execution function. The model only sees the declaration; the framework invokes the execution function in a controlled environment. This separation means adding or removing tools never affects the core loop.
System prompt assembly
The system prompt is concatenated from multiple fragments in a fixed order—for example, role description, tool descriptions, project rules, and current runtime state. Each fragment can be supplied by a different plugin, making scenario-based composition easy.
The following pseudocode shows how these concepts interact:
# Illustrative code, for structure onlysession = create_session()turn = session.start_turn(user_input)while not turn.finished:prompt = assemble_prompt(fragments=[role, tools, rules, state])step = turn.new_step()reply = model.generate(prompt) # provided by the model adaptation layerfor call in reply.tool_calls:result = tool_registry.invoke(call) # the approval plugin can intercept herestep.record(call, result)turn.commit(step)session.save()
Append-Only Session Logs: Replay, Branching, and Resumable Runs
Session logging is a defining feature of this kind of framework. Every Step’s input, model output, tool call arguments, and execution results are written to the log in an append-only, never-modified fashion. This design enables three capabilities.
Replay
Read the log sequentially to reconstruct the execution process step by step, useful for debugging or reviewing decisions. Replay should use the recorded model outputs and tool results directly, not re-invoke the model. Model output is inherently non-deterministic; re-calling may yield different results from the original run.
Branching
Copy a new branch from a historical Step, change a decision made after that point, and continue execution from there. The original branch remains intact, allowing side-by-side comparison of the two paths.
Resuming from breakpoints
If a process is interrupted, the framework restores state from the last complete Step. One critical issue: if the interruption occurs mid-tool-execution, the tool may have already produced side effects. Therefore, side-effecting tools should carry a unique call identifier; on recovery, the framework first checks execution status before deciding whether to retry.
A sample log record structure:
{"session": "s-001", "turn": 3, "step": 2,"type": "tool_call", "tool": "file_write","args": {"path": "notes.md"}, "status": "done", "call_id": "c-88"}
Comparing Four Design Approaches
Common agent implementation approaches fall into roughly four categories. The table below describes general characteristics; specific implementations vary by version and configuration, so consult the official documentation when making a selection.
| Dimension | Off-the-shelf tools | Open-source coding agents with fixed loops | Reconfigurable foundations | State-graph orchestration runtimes |
|---|---|---|---|---|
| Onboarding cost | Low; install and use | Low to medium; usable as-is | Medium; requires understanding the plugin system | Medium to high; requires designing nodes yourself |
| Is the core loop replaceable | Usually not; requires source changes | Usually not; substantial changes needed | Yes; the loop itself is a plugin | Yes, but the graph must be re-orchestrated |
| Extension method | Hooks and external protocols | Secondary development | Plugin configuration and replacement | Programming nodes and edges |
| Session records | Mostly in-memory; limited replay | Support replay; components not dynamically replaceable | Append-only logs with branching and resumable runs | State saved as checkpoints |
| Coding capability | Built-in | Built-in | Provided via plugins | Not built-in; requires integration |
The four approaches have different priorities:
- For quickly obtaining standardized coding assistance, off-the-shelf tools are the most efficient.
- For customizing execution strategy while keeping complete execution records, a reconfigurable foundation fits better.
- When workflows are dominated by deterministic state transitions with little reliance on coding capability, a state-graph orchestration runtime is more natural.
The key selection question is: does the team need to modify the agent’s most fundamental execution logic? If not, off-the-shelf tools or fixed-loop solutions usually mean lower maintenance costs. If yes, evaluate the maturity of the plugin system and the team’s ability to maintain it.
Example Repository Layout
A typical plugin-based repository might be organized like this:
agent-runtime/├── apps/ # Product entries: web app, CLI├── packages/│ ├── core/ # Sessions, execution loop, tool registry, prompt assembly│ ├── boot/ # Kernel startup, config loading, plugin resolution│ ├── llm/ # Model adapters with a unified invocation interface│ └── plugins/ # Files, command execution, sandbox, sub-agents, approval, persistence├── vendor/ # Vendored copies of kernel dependencies├── examples/ # Configuration samples and plugin development examples├── docs/ # Architecture docs and plugin development guides└── sdk/ # Wrappers for other languages
The point of this layout is to make dependency direction explicit. core should not reference concrete implementations in plugins; plugins only depend on interfaces exposed by core. When vendoring kernel source into the repository, pin versions and establish a clear upgrade process so upstream changes don’t silently affect your business.
Practical Considerations for Production
Once you adopt a plugin-based foundation, the following points directly affect system stability and security.
1. Keep plugin boundaries clear
Each plugin does one thing. Plugins interact through events or interfaces, never by reading or writing each other’s internal state. Only with clear boundaries can the impact of replacing a plugin be predictable.
2. Approval before execution
Approvals should happen before a tool actually runs. High-risk operations—deleting files, sending data externally, modifying configuration—should be denied by default and allowed only with explicit authorization. Approval records should also go into the session log for later auditing.
3. Constrain execution with sandboxes
Command execution should run in a restricted environment with limited file path access and network egress. Sandbox policies need to work hand in hand with permission approval—neither alone is sufficient.
4. Log redaction and access control
Session logs may contain keys, tokens, and personal information. Filter before writing, encrypt at rest, and enforce authentication on read. Log retention periods should also be defined up front.
5. Ensure idempotent replay and recovery
Side-effecting tools must carry a call identifier, and recovery should verify status first to avoid executing the same operation twice. Duplicate order creation or duplicate message sending, for example, cause real damage.
6. Respect the limits of model adaptation
A unified interface shields most differences, but models still vary in parameters, context length, and output formats. The adaptation layer should retain a parameter pass-through channel and maintain regression test cases for each integrated model to ensure predictable behavior after switching.
7. Deployment and observability
When deploying on a cloud platform, you can run the runtime in a container service, archive session logs in object storage, and use logging services and monitoring alerts to track tool call failures.
