Understanding and Building a Plugin-Based Agent Framework: A Full Walkthrough
This article explains how a plugin-based agent framework works and how to build and ship a plugin for it. It starts from the core idea that the base package is not a privileged library but a declarative manifest that inserts plugin rows into an initially empty configuration tree. It then walks through the practical chain: diagnosing editor type errors, the three key compiler settings, what a build command actually orchestrates, source-based versus artifact-based startup, workspace linking and dependency resolution, publishing checks, configuration override order, and the full module resolution path. The goal is to help developers treat the framework as a configuration-driven plugin runtime and reduce environment and dependency overhead.
1. Why “the Base Is Also a Plugin” Comes First
The most common misconception about a plugin-based agent framework is treating a package named base or core as a low-level library that everything else imports. In reality, it works more like a declarative manifest: the package ships a patch-style configuration file that batch-inserts plugin rows into a configuration tree that starts out empty. Those rows cover scheduling and hot reload, model capability access, session event logging, main loop driving, tool registration, prompt assembly, subprocess and command execution, sandboxing and approval, the file system, settings and credentials, subagents and workflows, retrieval and fetching, and more.
The value of this design is that it removes any “privileged core.” The framework does not need to reserve hooks for extensions, because extensions are part of the runtime itself. For developers, this has three direct effects. First, behavior changes are achieved by combining configuration rather than editing source code. Second, capabilities are pluggable, so trimming and swapping them is cheap. Third, when troubleshooting, you can attribute “who is responsible for this” to a specific plugin row instead of guessing inside a large kernel.
2. Writing Your First Plugin and Diagnosing Editor Errors
The most common obstacle when following a tutorial is seeing red squiggles in the editor, but a red underline does not mean the code is wrong. In most cases it is a type resolution failure: dependencies are not installed yet, type declarations are not included in the compilation scope, or the reference points to a workspace package that has not been built.
Check in a fixed order: first confirm the dependency actually exists in the dependency directory; then confirm the type entry is covered by the compiler configuration; finally confirm the sibling package being referenced has produced declaration files. A minimal illustrative plugin skeleton looks like this — the point is the metadata declaration and export convention, not business logic:
export const name = 'my-plugin'export const inject = ['tools'] // declare the capabilities this plugin depends onexport function apply(ctx) { // the framework calls this during assemblyctx.tools.register(/* ... */)}
A useful habit is to treat “can the editor resolve it” and “can the runtime load it” as two separate problems and verify them independently, so you avoid trial and error at the wrong layer.
3. Three Key Compiler Concepts
Beginners often conflate compile time with run time. Three things need to be separated: the compilation target decides which language version syntax is downleveled to; the module system decides the loading semantics of the output; and declaration output decides whether others get completion and validation. None of the three substitutes for another, and changing only one usually leaves the red squiggles in place.
It also helps to define the boundary between “include” and “exclude”: the declaration directory and the build output directory should normally be excluded, otherwise duplicate type definition conflicts tend to appear. Once these three points are clear, most red-squiggle problems disappear on their own.
4. What the Build Command Actually Does
A build command is usually an orchestration rather than a single step: clean old artifacts, compile in dependency topological order, generate type declarations, copy static assets, and finally bundle everything into a distributable form. Understanding “topological order” is especially important — a dependency must produce its declarations first, otherwise downstream compilation only gets empty types.
The recommended practice is therefore to run a full build once to get the whole chain working, then move into incremental development. If you use continuous compilation mode, make sure it watches source files rather than the output directory, otherwise it will trigger in a loop.
5. Running from Source vs. Build Artifacts
A framework generally supports two startup modes: launching directly from the source entry, or loading the built artifacts. The former iterates faster but requires the loader to support type stripping and path mapping. The latter is closer to a real installation scenario and exposes packaging omissions, missing assets, and undeclared external dependencies early.
The conclusion is clear: use the source path to speed up daily development, and always run one full verification through the artifact path before release. Neither can replace the other.
6. Workspace Mechanism and Dependency Protocols
In a multi-package repository, local packages reference each other through the workspace protocol and are symlinked at install time instead of downloaded as copies. This brings two benefits: changes are visible immediately, and duplicate size is avoided. But note that linking means sharing the same dependency tree, so version constraint conflicts will surface all at once.
If the framework provides an initialization action to “link workspace packages,” its essence is mapping local packages into the runtime’s resolution path so plugin names can be addressed correctly. When you hit “module not found,” first check whether that mapping ran and whether the package name matches the export entry.
7. Publishing: From a Local Directory to an Installable Package
The pre-publish checklist should include: whether the entry and export fields are complete, whether declaration files ship with the package, whether all runtime dependencies are explicitly declared, and whether a configuration patch and asset files need to be bundled. Copying only the code directory often fails at the install stage.
If the target form is a composite bundle, write “which plugins to mount” into the bundled configuration so that installation completes the assembly, rather than requiring users to edit configuration by hand.
8. Configuration Layers and User Directory Overrides
The configuration directory under the user directory usually holds multiple sets of runtime configurations, each deciding which plugins are enabled, which model adapter is used, and which approval and sandbox policies are on. Loading follows the override order “built-in defaults → composite bundle patch → user configuration,” where later layers have higher priority.
Troubleshooting tip: first confirm the final effective configuration tree, then decide whether the problem is a missing assembly or an implementation defect. Many cases of “the feature does not exist” are actually plugin rows that were never inserted or were disabled by a higher-priority configuration.
9. The Full Module Resolution Chain
At runtime, locating a module roughly goes through: name mapping and path aliases, workspace links, upward lookup through the dependency directory, export field and conditional export matching, and only then built-in or global locations. A failure at any step shows up as “module does not exist,” but the root causes are completely different.
It is worth fixing this chain as your troubleshooting order, together with a way to “print the final resolution result” to confirm where it landed, which can significantly shorten diagnosis time.
10. Mental Model Summary
Think of the framework as a “configuration-driven plugin runtime”: the configuration tree decides the capability set, the workspace decides code addressing, the build decides the delivery form, and the override order decides the final behavior. With these four main threads in hand, even a complex plugin system can be broken down into small, verifiable problems. To reduce the cost of environment setup and dependency governance, you can rely on general-purpose cloud container platforms, image registries, and log monitoring services to host the build and runtime environment, and focus your effort on the plugin logic itself.
