A Complete Guide to Agent Plugin Systems: From Plugin Development to Runtime Module Resolution

    This guide explains how modern AI agent frameworks use an “everything is a plugin” architecture. It covers the first steps of plugin development, TypeScript configuration, build outputs, workspace dependencies, publishing, profile isolation, and the complete path from source imports to runtime module resolution. It also provides a practical troubleshooting model for editor errors, build failures, and runtime module issues.

    A Complete Guide to Agent Plugin Systems: From Plugin Development to Runtime Module Resolution

    1. The Core Philosophy of Plugin-Based Frameworks: Everything Is a Plugin

    Modern AI agent frameworks commonly use a plugin-based architecture. Its central idea can be summarized as follows: there is no privileged core; every capability is assembled through plugins.

    Model integrations, tool execution, session logging, the Agent main loop, filesystem access, and web search can all exist as plugins that are loaded through configuration. Even packages that appear to be the framework foundation are essentially collections of plugins.

    Consider a typical “base” package. Its name may suggest that it is a low-level API library imported directly by applications, but it is actually a bundle. Its package metadata declares a bundle type, and a patch-style configuration file inserts dozens of plugin entries into an initially empty configuration tree. These entries may include:

    • Timer and hot-reload plugins
    • LLM capabilities and model adapters
    • Session event logging and in-memory storage
    • Agent interfaces and default main-loop drivers
    • Tool registries and system-prompt assembly
    • Child-process and shell execution
    • Sandboxing and approval policies
    • Filesystem capabilities and policies
    • User settings and credential management
    • Sub-agents and workflow orchestration
    • Web search and content fetching

    Why use this design? Turning the framework foundation into a plugin provides three main benefits:

    1. Replaceability: Any capability can be replaced or extended by a custom plugin, so framework upgrades do not have to remain black-box changes.
    2. Observability: The framework kernel manages plugin lifecycles—including loading, startup, and destruction—in a consistent way, making behavior easier to trace.
    3. Selective deployment: Unnecessary capabilities can be removed from the configuration, reducing runtime size and the attack surface.

    Once this principle is understood, issues involving editor errors, builds, publishing, and runtime resolution can be analyzed using a consistent mental model.

    2. Your First Plugin: Troubleshooting Editor Errors

    One of the first obstacles for new plugin developers is seeing red error markers in the editor after following an official tutorial. Although these errors often look like type problems, the underlying cause is frequently module-resolution configuration rather than incorrect code.

    A practical troubleshooting path is:

    1. Identify the source of the error: Determine whether it comes from the TypeScript language service or from an editor extension such as ESLint.
    2. Verify that dependencies are actually installed: In a workspace, a dependency may be linked to a local package. If that package has not been built, its type declaration files (.d.ts) may not exist, resulting in errors such as “module not found” or missing types.
    3. Check the module-resolution mode: The framework may rely on a newer resolution strategy, such as bundler. Older configurations, such as node, may not correctly resolve a package’s exports field.
    4. Restart the language service: After changing tsconfig, the TypeScript language service may need to be restarted. This step is frequently overlooked.

    A useful rule of thumb is to run the following command in the terminal when an editor reports errors:

    1. npx tsc --noEmit

    If the command succeeds while the editor still shows errors, the problem is likely related to the editor state or language-service cache rather than the project configuration.

    3. Clarifying Core tsconfig Concepts

    Several tsconfig options are especially easy to misunderstand during plugin development.

    3.1 The Difference Between module and moduleResolution

    • module determines the module syntax used by the compiled output. For example, esnext preserves ESM syntax, while commonjs converts modules to require calls.
    • moduleResolution determines how the compiler locates modules, including how it finds package entry points and type declarations in node_modules.

    Plugin frameworks commonly recommend:

    1. {
    2. "module": "esnext",
    3. "moduleResolution": "bundler"
    4. }

    The bundler mode can correctly read conditional exports in a package’s exports field and is widely used in modern frontend and Node.js toolchains.

    3.2 types and typeRoots

    The types field explicitly declares which type packages should be injected globally. If global types—such as types added through declaration merging—do not take effect, check first whether the relevant package is missing from this field.

    3.3 The strict Family of Options

    Enabling strict checking is recommended:

    1. {
    2. "strict": true
    3. }

    Plugins interact extensively with the framework kernel through types. Strict mode can expose many incorrect lifecycle-hook signatures during compilation instead of at runtime.

    4. The Build System: What Does a Build Command Actually Do?

    Running a build command such as pnpm build usually performs three types of work:

    1. Generates type declarations: tsc or a related tool produces .d.ts files so downstream consumers receive type information and editor support.
    2. Compiles the application output: TypeScript source is compiled into JavaScript, often in both ESM and CommonJS formats. The package’s exports field then distributes the appropriate format under different conditions.
    3. Prepares metadata: Plugin manifests and configuration patch files are copied or generated so the framework can identify the plugin during loading.

    Understanding the structure of build output is essential. The package repository contains build artifacts rather than source files, so runtime “module not found” errors should be investigated from the perspective of output directories and exports mappings—not only from the source-code perspective.

    5. Source Startup vs. Build Output: Two Runtime Paths

    Plugin development typically involves two execution paths:

    • Source path: The framework loads the plugin’s TypeScript source directly through a loader such as tsx or ts-node. Changes take effect quickly, making this path suitable for rapid iteration.
    • Build-output path: The framework loads the compiled JavaScript output. This path more closely matches the final published package and is therefore useful for release validation.

    The two paths do not resolve modules in exactly the same way. In the source path, TypeScript files are interpreted according to source-level semantics. In the build-output path, resolution follows the package’s main and exports fields strictly.

    A plugin that works correctly through the source path may still fail after publication. To avoid the classic “works locally, fails after installation” problem, run a regression test against the build output before publishing.

    In a monorepo, workspace features manage dependencies between local packages.

    • link-workspace-packages: The package manager prioritizes matching local packages and places them in node_modules through symbolic links instead of downloading them from a remote registry.
    • The workspace: protocol: A dependency declaration explicitly indicates that the dependency comes from the current repository. During publishing, the protocol is replaced with an actual version number.

    One important detail is that workspace:* is replaced with the current package version during publishing. In a coordinated multi-package release, this requires the correct publishing order: publish lower-level packages first, followed by plugins that depend on them. Otherwise, the published artifacts may contain an outdated version number.

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

    The publishing process can be summarized in four steps:

    1. Review package.json: Verify name, version, exports, and files. The files field controls which content is included in the package and can exclude source files and tests.
    2. Validate locally: Use npm pack to generate a tarball, then install it in an independent project. This simulates the experience of a real consumer.
    3. Publish the package: Push the validated package to the package registry.
    4. Consume it as a bundle: The published plugin can be used as a dependency by other plugins. It can also insert entries into the framework’s configuration tree through a configuration patch file, making a group of capabilities available as a single unit.

    8. Profiles: Isolating Configuration in User Directories

    Frameworks commonly maintain a dedicated directory under the user’s home directory, such as:

    1. ~/.xxx/profiles/...

    This directory stores configuration profiles for different scenarios. Each profile is an independent configuration snapshot containing enabled plugins, model credentials, tool policies, and other settings.

    Profiles provide several benefits:

    • Environment isolation: Development, testing, and production can each use a separate profile without interfering with one another.
    • Credential separation: Sensitive credentials do not need to be stored in the project repository.
    • Fast switching: A command-line argument can select a profile, allowing the framework to start with different configurations on the same machine.

    When debugging a plugin, a useful technique is to create a minimal profile that loads only the target plugin and its required dependencies. This helps eliminate interference from unrelated plugins.

    9. The Complete Module-Resolution Path

    Putting the previous sections together, the module-resolution process from source code to runtime looks like this:

    1. Source import declaration
    2. → TypeScript resolves types according to moduleResolution (editor experience)
    3. → Build tools compile or bundle according to exports (package output)
    4. → Package manager links local dependencies according to the workspace protocol (development)
    5. → Node.js loads the actual file according to conditional exports (runtime)

    If any part of this chain is configured inconsistently, the result may appear as an editor error, a build failure, or a runtime exception. The most efficient troubleshooting strategy is to first identify which stage of the chain is failing.

    10. Summary and Mental Model

    The following mental model can make plugin-based frameworks easier to understand:

    1. Everything is a plugin: A base package is a plugin manifest or bundle, not necessarily a low-level API library.
    2. The configuration tree is the framework skeleton: Runtime behavior is represented by a configuration tree populated by plugins. A bundle is a convenient way to insert multiple nodes at once.
    3. Validate both execution paths: Use source startup for development and build-output startup for release validation. Both are necessary.
    4. Think in four resolution layers: The editor, compiler, package manager, and runtime each follow different rules. Locate the failing layer before changing configuration.
    5. Treat profiles as isolation units: Use minimal profiles for plugin debugging and multiple profiles for environment management.

    With these five principles, you can not only build your first plugin more confidently but also narrow down module-resolution, build, and publishing problems much faster.