Plugin-Based Agent Frameworks: Architecture and Practice

    A practical architecture for plugin-based LLM agent frameworks: a small kernel handles orchestration, an event bus and plugin contracts keep capabilities replaceable, and permissions, sandboxing, cancellation, traces, model adapters, and subtask isolation turn an LLM-driven workflow into an auditable and operable system. The article also provides an implementation checklist for teams building agent runtimes.

    Why a Harness, Not Just a Chat Shell

    Connecting an LLM directly to a file system, terminal, or browser may look like a few additional function calls. The real difficulty is concurrency and loss of control: the agent may be retrieving multiple files, running tests, accepting user interruptions, and supporting cancellation at any moment. Without a unified runtime, permissions, retries, audit trails, and context management scatter across the system, making failures very hard to reconstruct later.

    The industry often calls this runtime a harness. Its responsibility is to connect the model’s generation capability to a working mechanism, while recording what was done, limiting what can be done, and deciding whether to retry or abort on failure. It is not another foundation model, nor a single-vendor chat client. It is the SDK and application framework for building, running, and extending agents.

    Conceptual Boundaries: Model, Session, and Execution Surface

    It helps to separate three layers so that product form is not confused with architecture.

    • Model layer: This layer only generates the next action from context: text, tool calls, or structured plans. Providers should be replaceable. Default routing and fallback routing should be configuration, not hard-coded business logic.
    • Session layer: This layer maintains goals, history, workspace state, and user interruptions. A task usually spans multiple turns, and each turn contains many steps: checking the environment, decomposing a plan, calling tools, and replanning based on results.
    • Execution surface: This is where real side effects happen: reading projects, modifying files, running commands, fetching assets, and spawning subtasks. The execution surface must be auditable, budgetable, and cancellable.

    The interaction form can vary: a web UI, a full-screen terminal, a headless CLI, or an automation integration based on a JSON-RPC-like protocol. All of them should share the same kernel events instead of each implementing a separate agent loop.

    Microkernel: The Kernel Orchestrates, Capabilities Stay External

    “Everything is a plugin” is not just a slogan; it is a dependency direction. The kernel should stay small and only provide:

    1. Lifecycle: start, pause, cancel, and end, including propagating cancellation signals to child processes and subtasks.
    2. Event bus: planning, tool start, tool end, user messages, and errors are published as events. UIs and audit systems only subscribe to events.
    3. Plugin contract: register capabilities, declare permissions, and declare input/output schemas. The kernel validates before invocation.
    4. Context assembly: trim history, tool results, and file fragments according to a budget, instead of stuffing the entire repository into context.

    File systems, shells, task boards, subagents, model adapters, and UI adapters are all plugins. Adding a new model or tool should not require changing the kernel loop. Large workspaces with dozens to hundreds of collaborative units can evolve because plugin boundaries remain stable, not because logic is piled into the main process.

    A simplified registration flow can be very plain:

    1. register(plugin):
    2. assert plugin.name unique
    3. assert permissions subset of policy
    4. kernel.on(plugin.events, plugin.handle)
    5. tools.extend(plugin.tools)

    The calling side always follows the same path: the model produces a tool name and arguments → permission and schema validation → execution with a time limit → structured results written back to context → trace recorded. No plugin may bypass this path and modify the user workspace directly.

    Permissions, Sandboxing, and Cancellation: Make Runaway Behavior Impossible by Design

    Models make mistakes. The value of the framework is to make those mistakes reversible and explainable.

    • Least privilege: Read, write, execute, and network access are authorized separately. A read-only troubleshooting task should not automatically receive disk-write permission or arbitrary command execution. Write operations should be constrained to the workspace root, and path traversal should be rejected.
    • Explicit confirmation: High-risk actions such as deletion, publishing, credential changes, or external network writes enter a pending confirmation queue. The model should not be able to perform them unilaterally.
    • Resource limits: Steps, wall-clock time, output volume, and concurrent tool calls should all have caps. Long-running tasks should use checkpoints rather than infinite loops.
    • Cancellation semantics: User cancellation must become cooperative cancellation: stop further planning, terminate child processes, and either roll back writes that have already started or mark them incomplete. Stopping the animation in the UI while the backend continues running is a common source of incidents.
    • Failure policy: Distinguish retryable failures, such as transient network issues or lock contention, from non-retryable failures, such as permission denial or failed test assertions. Retries need backoff and a maximum attempt count, and the reason should be written into the trace.

    These mechanisms may look like overengineering. But when an agent modifies multiple files in parallel and runs tests, they are exactly the parts you wish had existed before an incident.

    Traces and Observability: From Demo to Operable System

    Even a successful one-shot generation—for example, building a browser-runnable interactive page from a single request—often includes environment checks, planning, asset fetching, scene setup, and logic writing. It can involve hundreds of steps. Without traces, it is impossible to answer where the process stalled or which tool result misled the model.

    At minimum, record: turn and step IDs, model routing, tool names with redacted parameters, latency, exit codes, the list of written files, and user interruption timestamps. The trace panel in the UI, the logging service, and monitoring alerts should align on the same event stream rather than maintaining three separate views. In enterprise environments, traces must not contain credentials or full secrets. Command output should be truncated and leveled.

    Evaluation should not only check whether the final page opens. It should also examine whether the plan covered environment dependencies, whether unauthorized network access occurred, whether the agent self-corrected after failure, and whether cancellation left partial artifacts. Tasks such as reproducing 3D fragments from text or reconstructing character relationships from descriptions can be useful subjective quality samples, but they do not replace permission and stability testing.

    Multi-Model and Subtasks: Adapters Instead of Forked Code

    The correct approach to using one model provider by default while retaining the ability to switch providers is a unified message and tool protocol: system prompts, tool schemas, streaming deltas, and usage statistics all pass through an adapter. Business plugins only see a normalized “next action.”

    Subtasks need independent contexts and permission subsets. The parent task assigns goals and acceptance criteria, and the subtask returns a summary plus a change list, avoiding the need to pour all raw subtask output back into the parent context. When concurrent subtasks share a workspace, file locking or a change-merging strategy is required; otherwise, two steps can overwrite each other.

    For cloud deployment, generic building blocks can carry the runtime surface: a container platform for isolated execution environments, object storage for assets and build artifacts, a message queue for cancellation and task events, and logging and monitoring for traces. These capabilities do not need to be hard-coded to a proprietary interface. Policies—who can execute, how long to retain data, and how to alert—are the parts that should be configured according to organizational rules in a cloud environment such as Baidu AI Cloud.

    Implementation Checklist

    1. Define kernel events and the cancellation model before connecting the first tool.
    2. Make all tools plugins; declare permissions at registration time and enforce them at call time.
    3. Keep workspace, command, and network boundaries separate, and default to deny.
    4. Ship traces, limits, retries, and human confirmation together, not after the system “works.”
    5. Let the UI, headless mode, and automation protocols share one kernel to avoid creating a second agent loop.
    6. Protect the main path with short-task regression tests: environment checks, single-file modifications, failure retries, and mid-task cancellation. Then use long generative tasks to observe step count and cost.

    The professionalism of a plugin-based agent framework is not measured by how many tools it can call. It is measured by whether every capability can be replaced, limited, cancelled, and explained afterward. When the model’s power is connected to a mechanism with a harness, the system moves from demo script to maintainable engineering.