Plugin Agent Framework: A Practical Guide to Building and Debugging Your First Plugin
The steep learning curve of plugin-based agent frameworks often comes from a simple misunderstanding: there is no privileged core to import. This guide walks through building your own plugin and connects the dots across editor type resolution, TypeScript configuration, build output, publishing, and runtime module resolution. You will learn a layered debugging method that separates editor errors from runtime failures, so you can stop reinstalling dependencies and start pinpointing the broken link in the dependency tree. Requires basic familiarity with Node.js, npm or pnpm, and TypeScript.
Introduction: Why Plugin-Based Frameworks Have a Steep Learning Curve
Many developers feel a sense of mismatch the first time they touch a plugin-based agent framework. The documentation says “everything is a plugin,” so you go looking for the so-called “core API”—only to find that no base layer needs to be imported at all. Your first plugin shows red squiggles in the editor, the build passes but the module cannot be found at runtime, and it works locally but fails to load after publishing. These problems often have different root causes, yet beginners lump them together as “the framework is full of traps.”
This article uses “writing your own plugin” as the through-line to connect several main threads: editor resolution, the TypeScript project, the build, publishing, and runtime module resolution. The prerequisites are modest: a basic understanding of Node.js, package managers (npm/pnpm), and TypeScript.
1. Groundwork: What “Everything Is a Plugin” Really Means
1.1 There Is No Privileged Core
The core philosophy of a plugin-based framework is that there is no “privileged core” that needs to be patched. Model adapters, tool invocation, session logging, and the main agent loop are all composed from plugins through configuration. Even packages with “base” or “core” in their names are themselves plugins.
Take a certain base bundle package as an example. It sounds like a low-level library, but it is actually a bundle: its package manifest declares a bundle flag and ships a patch-style configuration that inserts dozens of plugin entries into an empty configuration tree. It is not an API you call, but a manifest of “which plugins I want to mount”:
# Illustrative: patch configuration of a bundle package (excerpt)plugins:- timer # scheduling capability- hmr # hot reload- llm # model capability abstraction- llm-adapter # concrete model adapter- session # session event logging and storage- agent # agent interface- agent-loop # default main loop driver- tools # tool registry- system-prompt # prompt assembly- subprocess # subprocess execution- sandbox # sandbox policy- approval # approval policy- fs # filesystem capability- settings # user settings- credentials # credential management
1.2 Three Benefits of This Design
Making the “base layer” a plugin buys you replaceability, trimmability, and composability. To swap the model adapter, change one line of configuration instead of forking the framework. For a minimal runtime, mount only the session and tools plugins and drop the web and sub-agent pieces. For an enterprise intranet deployment, tighten the permission boundary with approval and sandbox plugins. The trade-off is that you must understand “configuration is assembly,” not “code is call relationships.”
2. Your First Plugin: A Troubleshooting Order for Editor Errors
The first obstacle beginners hit is editor errors. Troubleshoot from the outside in, and do not suspect the framework right away:
- Are dependencies installed? Check whether the package manager’s dependency tree contains the corresponding declaration and whether the workspace has completed a full install.
- Type resolution path: Does TypeScript know where to find the declaration files, and do the module resolution mode and the package export fields match?
- Package export contract: Do the export fields declare a types entry, or is there a case of “implementation without declarations”?
- Workspace linking: Is the local package actually linked into the dependency tree, rather than still pointing to a remote version.
Illustrative check commands (generic form):
# Inspect where the package actually points in the dependency treepm ls <package-name># Trace resolution to pinpoint the real reason types cannot be foundtsc --noEmit --traceResolution
Key rule: if the build passes but the editor shows errors, the problem is almost always in the type resolution layer; if the editor is fine but the module cannot be found at runtime, the problem is in the runtime resolution layer. Do not treat the two with the same fix.
3. Project Configuration: Three Concepts You Must Clarify
3.1 Compile Target and Module System
The compile target determines how far syntax is down-leveled, and the module system determines which loading semantics the output uses. Both must be consistent with the runtime’s loading strategy; otherwise you get “the build succeeds but loading fails.”
3.2 Types Entry and Implementation Entry
A package’s export fields can declare both a types entry and an implementation entry. When only the implementation entry is declared, the editor often cannot get the types and shows errors. Filling in the types entry is the most common one-shot fix.
3.3 Workspace Protocol
When referencing a local package inside a workspace, use the workspace protocol rather than a fixed version number. A fixed version number makes the package manager fetch from the remote, so local changes never take effect—this is the number one cause of “I changed the code but nothing happens.”
4. The Build: What a Single Build Actually Does
A typical build has four steps: type checking, transpilation, output bundling, and declaration file generation. Understanding it helps you locate the failure surface:
- Type check failure: the contract does not match, and the output should not be produced at all.
- Transpile failure: the syntax does not match the target.
- Bundle failure: the entry or external dependency configuration is wrong.
- Missing declarations: it runs, but the editor shows errors.
It is recommended to split “type checking” and “output generation” into two separate stages, so errors are clearly attributed and do not mask each other.
5. Two Run Paths: Source Startup and Build Output
The framework usually supports two startup methods. Source startup loads the implementation directly from the workspace, so changes take effect immediately—good for development. Build-output startup loads the bundled files, behaves closer to the published form, and is good for acceptance checks.
The two paths use different module location rules, which is why you see “works in development, fails in acceptance.” The recommended practice is to iterate quickly with the source path during development, then run a smoke test with the output path before committing.
6. Publishing: From a Local Plugin to an Installable Package
Before publishing, confirm four things: the output is complete, the declaration files ship with the package, dependencies have been narrowed down to what is truly needed at runtime, and the export fields map one-to-one to the actual files. Missing any of these shows up as “installs successfully but fails to load.”
A minimal self-check list:
- The output directory contains only the files needed at runtime;
- The dependency list contains no packages used only for building;
- The version number matches the changelog;
- Install and start once in a clean environment.
7. Configuration Loading and the User-Level Config Directory
The user-level config directory usually holds multiple configuration profiles, each describing “which plugins to mount and with what parameters.” Its value is decoupling assembly from code: the same output presents a different capability set under different profiles.
When troubleshooting loading problems, first check whether the profile actually declares your plugin, then check whether the package name referenced by the plugin entry can be resolved, and finally check whether the parameters satisfy the plugin’s declared required fields.
8. The Complete Module Resolution Chain
Look at the chain end to end: a successful plugin load requires all of the following at once—the package is in the workspace dependency tree, the export fields point to files that exist, the runtime’s resolution conditions match the package’s declarations, the profile contains the corresponding plugin entry, and the required parameters are complete. If any link breaks, the error message may be the same “module not found,” so you must verify link by link rather than repeatedly reinstalling dependencies.
9. Summary: Build a Reusable Mental Model
Remember three sentences: the base is also a plugin, and configuration is assembly; for editor errors check type resolution, for runtime failures check module resolution; use the source path in development and the output path for acceptance. With this layered troubleshooting method, what you face is no longer “framework magic” but a dependency tree you can locate layer by layer.
