A Practical Guide to Plugin-Based Agent Harness Architecture

    This article explains how a plugin-based agent harness works and how to develop, debug, and ship against it. It covers why a configuration-driven plugin container avoids a privileged core, how to diagnose editor errors when building your first plugin, common misconceptions about project configuration, what a standard build produces, the difference between source startup and artifact startup, workspace linking, release and installation checks, layered configuration and user profiles, and the full runtime module resolution chain. Readers will gain a mental model that stays useful across implementation changes.

    1. Why “Everything Is a Plugin” Comes First

    The central claim of a plugin-based agent harness is that there is no privileged kernel that needs patching. Model adapters, tool invocation, session logging, and main-loop scheduling all exist as plugins, composed through a configuration tree. Even packages whose names suggest a foundation, such as those containing base or core, are often not libraries you import but composition manifests: their package descriptor declares a bundle property and ships a patch-style configuration that inserts dozens of plugin rows into an empty configuration tree.

    This design offers three benefits. First, replaceability: swapping a model adapter, a sandbox policy, or a logging backend means changing configuration, not source code. Second, trimmability: capabilities you do not need are not mounted, so the dependency tree and startup overhead shrink accordingly. Third, evolvability: new capabilities are inserted incrementally as plugins, avoiding repeated refactoring of the core. The tradeoff is a longer debugging path, since an error may originate in parsing, building, publishing, or runtime lookup.

    2. Your First Plugin: Start with the Red Squiggles

    The first obstacle for newcomers is usually a wall of red in the editor: modules not found, type mismatches, unresolved import paths. The recommended troubleshooting order works from the outside in:

    1. Confirm the dependency is actually installed locally and that the package manager selected the correct workspace.
    2. Confirm type declarations are being resolved, and check for a missing type entry or conditional export.
    3. Confirm the project configuration includes the directory and that it is not excluded by a rule.
    4. Only then suspect the framework itself.

    A minimal illustrative plugin skeleton needs just three pieces: a package descriptor (name, version, entry point, and type entry), a configuration fragment (the plugin rows to mount and their default parameters), and an implementation file (an exported install function that registers services or tools).

    1. // Pseudocode: the plugin entry exports an install function
    2. export const name = 'demo-plugin';
    3. export function apply(ctx, config) {
    4. ctx.on('ready', () => ctx.logger.info('plugin ready'));
    5. ctx.tools.register({ name: 'echo', run: async (s) => s });
    6. }

    The key point is that a plugin is not called by something; it is mounted by configuration and invoked by the container at lifecycle points.

    3. Three Common Misconceptions About Project Configuration

    First, compile configuration is not the same as bundling configuration. The former governs type checking and output directories; the latter governs artifact shape and dependency handling. Second, the module resolution mode must match the runtime module system, or things will pass locally and fail at runtime. Third, declaration files must be published alongside the artifact, or consumers will still see red in their editors. Clearing up these three points resolves most strange cases of “red in the editor, green on the command line,” or the reverse.

    4. What the Build Actually Does

    A standard build typically cleans old artifacts, runs type checking, compiles or bundles, generates declaration files, and copies non-code resources such as configuration fragments and prompt templates. If the framework uses a bundle mechanism, the build also validates that the plugin rows referenced by configuration fragments can be resolved. It is advisable to keep type checking and bundling as separate steps so failures surface quickly and are easy to locate.

    5. Two Startup Paths: Source and Artifact

    During development, source startup loads the project directory directly and pairs with hot reload for fast feedback. After release, artifact startup loads the build output from the install directory. The two paths begin module lookup from different roots, so “works locally, breaks after install” usually means dependencies did not land in the artifact, or a workspace protocol was used without correct linking.

    6. Workspaces and Linking

    In a multi-package repository, packages often reference each other through a workspace protocol, which is replaced by local links at install time. Confirm three things: whether the link was created, whether the link target has been built, and whether the runtime can follow the link to the real dependency. If the target package has only source and no artifact, the runtime will report a missing module.

    7. Publishing and Installation

    Before publishing, run a clean-install verification: clear the dependency directory, reinstall, build, and then start from the artifact path. The artifact should be self-contained with the resources it needs at runtime, complete declaration files, and a clear version number and changelog. On the installation side, pay attention to the install location, the user-level configuration directory, and cache invalidation.

    8. Configuration Layers and the User Directory

    The user-level configuration directory usually holds multiple profiles, each containing a list of enabled plugins and parameter overrides. Once you understand the precedence order (built-in defaults < bundle < user profile < command-line arguments), behavioral differences stop being mysterious. When troubleshooting, print the effective configuration first, then narrow things down item by item.

    9. The Full Runtime Module Resolution Chain

    The complete chain is: locate the entry point, read the configuration tree, resolve plugin rows, select implementations via conditional exports, look up dependencies and resolve links, and run lifecycle callbacks. A failure at any step shows up as “the plugin did not take effect,” so retaining the resolution result of each step in the logs is a foundational practice for build observability.

    10. The Mental Model

    Think of the framework as a configuration-driven plugin container: bundles supply the default manifest, plugins supply capabilities, the build ensures the artifact is self-consistent, and the runtime assembles everything according to configuration. Once you have this main thread, you can develop, troubleshoot, and ship with the same method regardless of how the underlying implementation changes. If you use a cloud container platform or a logging service for runtime and observability, you can also integrate through generic capability categories without depending on vendor-specific interfaces.