Understanding Agent Runtime Plugin Systems: Development, Building, and Module Resolution End to End

    A practical guide to how modern AI agent harnesses organize everything as plugins. Learn how plugin development, TypeScript configuration, build pipelines, workspace linking, bundles, profiles, and module resolution fit together—and how to debug issues across the whole chain.

    Understanding Agent Runtime Plugin Systems: Development, Building, and Module Resolution End to End

    1. The Big Picture: What a Harness and Its Plugin System Are

    In AI agent development, a harness refers to the “driving layer” built around a large language model. It organizes model invocation, tool execution, session management, and approval policies into a runnable, extensible runtime. The key to understanding a harness is understanding its plugin philosophy: everything is a plugin.

    In many modern agent frameworks, there is no “privileged core” that needs patching. Model adapters, tool invocation, session logging, the agent main loop, filesystem access, web scraping—all of these exist as plugins, mounted onto the runtime through configuration. Even the packages that look like a “framework foundation” are, at their core, plugin collections.

    This is the point newcomers most often misunderstand. Take a common base package as an example: its name usually contains “base,” which makes people assume it is a low-level library to be imported. In reality, it is a bundle—a composite package. Its package.json declares bundle metadata, and an accompanying patch configuration file inserts dozens of plugin entries into an otherwise empty configuration tree, for example:

    • Timer and hot-reload plugins: handle scheduled tasks and development-time hot reloading;
    • Model adapter layer: unifies the LLM invocation interface and connects to specific model providers;
    • Session plugin: records session events and provides in-memory storage;
    • Agent main loop plugin: drives the “think—call tools—observe results—think again” loop;
    • Tool registry and prompt assembly: combines the tools and system prompts contributed by each plugin into the final request;
    • Subprocess, sandbox, and approval policies: control the security boundaries of command execution;
    • Filesystem and web capabilities: restricted I/O and web fetching.

    Why design it this way? Making even the “foundation” a plugin brings three benefits:

    1. No privileged paths: any capability can be replaced, disabled, or recombined; the framework has no backdoor around the plugin system.
    2. Configuration as architecture: what an application looks like is entirely determined by its plugin manifest—auditable and versionable.
    3. A unified ecosystem: third-party plugins go through exactly the same loading, resolution, and lifecycle mechanisms as built-in capabilities.

    2. Your First Plugin: Starting with Editor Errors

    The most common first obstacle when writing a plugin is this: the code logic is fine, but the editor shows red squiggles, complaining that a module or type declaration cannot be found. Many people assume the code is wrong, but in most cases it comes down to TypeScript project configuration and module resolution strategy.

    You can boil the troubleshooting down to four steps:

    1. Confirm the dependency is actually installed in the project’s node_modules, or linked to a local package via a workspace;
    2. Check whether the moduleResolution strategy in tsconfig matches how the dependency package exports its entries (see Section 4);
    3. Confirm the dependency ships type declarations (a .d.ts file or a types field in package.json);
    4. Restart the language server to rule out false errors caused by editor caching.

    3. Clarifying Core tsconfig Concepts

    A few compiler options in plugin projects are especially easy to confuse and deserve a closer look:

    • module and moduleResolution are two different things. The former determines the module syntax of the compiled output (e.g., ESModule); the latter determines how the compiler maps import specifiers to files on disk. Modern packages commonly use the exports field to declare entry points, so you should choose a resolution strategy that understands exports, such as bundler or node16. Otherwise, the editor will “not see” a package’s subpath exports.
    • paths is only a compile-time alias mapping; it does not affect runtime. If your plugin also needs to resolve these aliases at runtime, either compile the aliases away at build time or rely on runtime loader support.
    • Turn on all the strict options. Plugins are loaded by the host in a uniform way, and stricter types mean clearer boundaries when collaborating with the host and other plugins.

    4. The Build System: What a Single Build Actually Does

    When you run a build, three things typically happen:

    1. Type compilation: the TypeScript compiler compiles source code into JavaScript output and generates declaration files for downstream consumers;
    2. Output normalization: module formats are unified (e.g., to ESM), file extensions are handled, and external dependencies are marked (which dependencies are not bundled into the output and are left for runtime resolution);
    3. Metadata cleanup: ensuring that package.json fields such as exports, types, and main match the output structure.

    Understanding “which dependencies are marked as external” is critical. The host framework’s own packages should usually remain external, so the host provides the same single instance at runtime—avoiding the “two framework instances” problem where contexts cannot communicate.

    5. Running from Source vs. Running Build Output: Two Execution Paths

    During development, “running from source” is recommended: the runtime loads TypeScript source directly or transpiles it on the fly via a loader, eliminating repeated builds and giving the best hot-reload experience. For release and production, use build output: it has gone through type checking and format normalization, starts faster, and behaves more predictably.

    The two paths have different module resolution requirements. The source path requires the editor and the runtime to use consistent resolution rules; otherwise you get “it works in the editor but fails at runtime”—or the reverse. Keeping the resolution strategies of tsconfig, the build tool, and the runtime loader aligned is the key to avoiding seemingly random issues.

    6. Workspace Mechanism: A Powerful Tool for Local Integration

    When developing plugins in a monorepo, the package manager’s workspace mechanism plays a central role:

    • Switches like linkWorkspacePackages determine whether local packages reference each other via symlinks. During integration, a change to package A takes effect immediately in package B;
    • The workspace: protocol in package.json declares “this depends on a package inside the workspace,” and is automatically replaced with the real version number at publish time.

    This mechanism closes the loop from “local plugin → integration testing → publishing,” with no manual file copying or repeated releases.

    7. Publishing: From a Local Plugin to an Installable Bundle

    Before publishing, verify that the output is complete, type declarations are included, the exports field is correct, and dependency declarations are precise (use exact version ranges rather than *). If you want others to “install a set of plugins with one command,” you can package multiple plugins into a single bundle: declare a bundle entry in the package metadata and describe the list of plugins to mount in a patch configuration. After a user installs the package, the runtime registers each plugin in the manifest into the configuration tree at load time.

    8. The Profile Mechanism: What profiles in the User Directory Are

    Many harnesses maintain a profile directory under the user’s home directory (e.g., ~/.xxx/profiles/xxx). A profile is essentially a “runtime snapshot”: it records the configuration tree state, installed plugins, credentials, and user settings for that environment. Different profiles are isolated from each other, making it easy to maintain multiple plugin setups—“development,” “testing,” “production”—in parallel on the same machine. When debugging unusual plugin behavior, first confirm which profile is currently active; this often saves a lot of troubleshooting time.

    9. The Complete Module Resolution Chain

    Tying all the previous pieces together, here is the resolution chain a plugin goes through from code to execution:

    1. The editor/compiler resolves imports according to tsconfig’s moduleResolution, finding types and source code;
    2. The build tool produces output using the same rules and marks host dependencies as external;
    3. The runtime loads the plugin output, locating entry files via package.json’s exports;
    4. The loader registers the plugin into the configuration tree, and the host initializes plugins in dependency and lifecycle order;
    5. Plugins consume each other’s capabilities through context injection, not by directly importing each other’s internals.

    If the resolution strategy is inconsistent at any link in the chain, symptoms appear as “red squiggles,” “module not found,” or “runtime instances don’t match.” Walk back through the chain and check each step, and the problem can almost always be located.

    10. Summary and Mental Model

    Finally, here is a transferable mental model:

    • Everything is a plugin: the framework has no privileged core; even the foundation is a plugin manifest;
    • Configuration is architecture: a bundle plus patch configuration describes “which plugins to mount”;
    • Three places must align: the module resolution strategies of the editor, the builder, and the runtime;
    • Two paths, clearly separated: run from source in development, use build output in production;
    • Isolation via profiles: multiple environments are separated by profiles, and troubleshooting starts with the current environment.

    With this model in place, when you next hit compile errors, missing modules, or plugins that don’t take effect, you can quickly determine which link in the chain is at fault instead of blindly tweaking configuration files. The complexity of plugin systems is superficial; their underlying logic is highly consistent: declarative configuration + a unified lifecycle + strict module resolution. Once you understand these three points, plugin development in any mainstream agent framework is merely a matter of syntax.