A Complete Guide to AI Agent Plugin Development: From Editor Errors to Module Resolution
This guide explains the full lifecycle of developing, building, testing, and publishing plugins for AI agent frameworks. It covers editor diagnostics, TypeScript configuration, build outputs, workspace dependencies, package metadata, profiles, and the complete runtime module-resolution chain.
1. Why Plugin Development Can Feel Difficult
When building custom plugins for an AI agent framework, beginners often struggle with issues that seem unrelated to business logic: type errors in the editor, uncertainty about tsconfig settings, confusion about where build artifacts are generated, or “module not found” errors after installation even though local development works correctly.
These problems arise because plugin development spans several technical layers, including editor language services, TypeScript project configuration, build tooling, package management, and runtime module resolution. If any layer is misunderstood, development can become difficult to troubleshoot.
This article uses the process of building a custom plugin as a guide and connects these separate concepts into one complete workflow.
2. The Foundation: Everything Is a Plugin
Modern AI agent frameworks commonly follow a core design principle: everything is a plugin. Instead of relying on a privileged core that must be patched, capabilities such as model integration, tool execution, session logging, and the Agent loop are implemented as plugins and assembled through configuration.
One common source of confusion is that packages that look like framework foundations are often plugin bundles themselves. For example, a package named base might declare a bundle identifier in its package.json and use a patch-style configuration file to insert dozens of plugin entries into the configuration tree.
Typical components include:
- Scheduling and hot-reload plugins: Provide scheduled tasks and development-time hot reloading.
- Model capabilities and adapters: Offer a unified large language model interface together with adapters for specific model providers.
- Session management: Handle session event logs and in-memory storage.
- The Agent loop: Define the Agent interface and provide default execution logic.
- Tooling: Include a tool registry, system prompt assembly, filesystem tools, and web search or scraping tools.
- Execution environments: Support child processes, shell execution, sandboxing, and approval policies.
- Extension capabilities: Provide user settings, credential management, sub-agents, and workflow orchestration.
This architecture means that the framework foundation has no special status. Any capability can be replaced, removed, or extended. The plugin system is essentially a configuration list that describes which plugins should be mounted, rather than a conventional API library that is simply imported.
3. Your First Plugin: How to Investigate Editor Errors
When following a tutorial to create your first plugin, you may see type errors highlighted in the editor. Instead of changing the code immediately, investigate the problem in the following order:
- Check that all dependencies are installed: Plugins usually depend on type definition packages provided by the framework. Missing dependencies will naturally cause editor errors.
- Check TypeScript and SDK compatibility: The framework may use newer type syntax that an outdated local TypeScript version cannot parse.
- Confirm that the editor is using the correct
tsconfig: Monorepos often contain multiple TypeScript configuration files, and the editor may load the wrong one. - Distinguish editor errors from build errors: In some cases, the editor reports an error while the command-line build succeeds. This usually indicates a language-service cache or workspace-detection issue. Restarting the TypeScript language service may resolve it.
A useful general practice is to discuss questions about the framework’s execution layer with an AI assistant and document the resulting understanding. Turning exploration into written documentation is itself an efficient way to learn the system.
4. Clarifying the Core tsconfig Concepts
Several TypeScript configuration fields are particularly easy to confuse in plugin projects:
moduleandmoduleResolution:moduledetermines the module syntax generated by the compiler, such as ESM.moduleResolutiondetermines how TypeScript locates type declarations and modules. These settings must be compatible. For example, ESM output commonly uses abundler- ornode16-level resolution strategy.typesandtypeRoots: These fields control which@typespackages are loaded automatically. Incorrect settings can cause missing global types or duplicate type registrations.paths: Path aliases affect type checking and editor navigation, but they do not change runtime behavior. This is a common reason an import works in the editor but fails when the application runs.
Whenever possible, inherit the framework’s recommended TypeScript configuration instead of writing one from scratch. This helps avoid subtle inconsistencies between the framework and the plugin project.
5. What Does build Actually Do?
A command such as pnpm build usually performs more than simply compiling TypeScript into JavaScript. A complete plugin build process often includes the following steps:
- TypeScript compilation: Convert TypeScript source code into JavaScript that follows the target module format.
- Declaration generation: Produce
.d.tsfiles so downstream consumers receive type information and editor support. - Artifact packaging or organization: Arrange source entry points into a directory structure that follows package conventions.
- Metadata processing: Write or validate fields such as
exports,main, andtypesso the package can be resolved correctly.
Understanding how build artifacts correspond to the source tree is essential when investigating runtime problems.
6. Two Execution Paths: Source Code vs. Build Artifacts
Plugin systems commonly support two ways to run a plugin:
- Source execution: The framework loads the plugin source directly, usually with the help of a TypeScript runtime or on-the-fly compilation. This provides fast feedback when code changes and is suitable for development.
- Artifact execution: The framework loads compiled files from a directory such as
dist. This more closely simulates a real installation and is suitable for validating the published package.
Many “it works locally but fails after installation” problems are caused by the difference between these paths. The source path may succeed because workspace symlinks provide additional resolution support, while the artifact path depends strictly on the entry points and dependency declarations in package.json.
To verify that a plugin is publishable, always test it through the build-artifact path.
7. Workspace Dependencies: The Key to Local Integration
In a monorepo, two mechanisms must be distinguished:
linkWorkspacePackages: A package-manager setting that determines whether dependencies in the workspace should be linked locally through symlinks instead of being downloaded from a registry.- The
workspace:protocol: An explicit dependency declaration indicating that the dependency belongs to the same workspace. During publishing, it is replaced with the corresponding real version number.
A common failure occurs when a dependency resolves successfully through a local symlink during development but the link is unavailable to consumers after publication. If the version declaration is also incorrect, installation will fail.
The recommended approach is to declare inter-plugin dependencies with the workspace: protocol and let the publishing workflow replace those references with actual versions.
8. Publishing and Profiles
Publishing a plugin means sending its build artifacts and correct package metadata to a registry. Before publishing, verify the following:
- Whether the
exportsfield covers every public entry point; - Whether
peerDependenciescorrectly declares the plugin’s dependency on the framework core; - Whether the type declaration files are included in the published package.
Many frameworks also support a profile mechanism. A profile maintains an isolated set of configuration files and plugin environments in the user’s home directory. Different profiles can mount different combinations of plugins.
Profiles are useful for testing a plugin in a clean sandbox that reflects a real installation. This helps prevent local configuration or previously installed packages from hiding deployment problems.
9. The Complete Module-Resolution Chain
Putting all the previous concepts together, a plugin-loading sequence can be summarized as follows:
Startup entry point→ Read the configuration tree and bundle manifest→ Resolve each plugin package name→ Locate the package on disk according to package-manager rules→ Use the package.json exports field to find the actual entry point→ Load the JavaScript artifact or source code and instantiate the plugin→ Allow the plugin to inject its services and child plugins into the configuration tree
A failure at each stage produces a different type of error:
- Failure to resolve the package name usually indicates an installation or dependency problem.
- Failure to find an entry through
exportsusually indicates incorrect package metadata. - Abnormal behavior after loading usually points to plugin lifecycle or initialization logic.
Troubleshooting each stage in sequence is the key to replacing trial-and-error debugging with an engineering-based process.
10. The Plugin Development Mental Model
The plugin system can be summarized in four principles:
- Everything is a plugin: The framework foundation is also a plugin bundle. Understanding the configuration tree means understanding the framework.
- Validate both execution paths: Use source execution during development and artifact execution for release validation. Neither replaces the other.
- Metadata is a contract:
tsconfig,package.jsonexports, and dependency declarations determine whether a plugin can be consumed correctly. - Debug the chain step by step: Trace the process from the configuration tree to the files loaded from disk instead of relying on intuition.
With this mental model, most plugin-development problems can be narrowed down to a specific stage within minutes, leaving more time to focus on the actual capabilities the plugin is intended to provide.
