Plugin-Based AI Agent Frameworks: A Beginner's Guide and Hands-On Practices

    This article explains how plugin-based AI agent frameworks work and how to troubleshoot them in practice. It covers why "everything is a plugin" causes confusion for newcomers, how to locate type resolution errors when writing a first plugin, how to separate dependency declarations, path mapping, build configuration, and module modes, what happens during a build, the difference between source startup and artifact startup, how workspace linking works, a pre-publish checklist, user-level configuration profiles, the full module resolution chain, and a four-part mental model for diagnosing errors quickly.

    1. Why “Everything Is a Plugin” Creates a Learning Gap

    The core design principle of a plugin-based agent framework is that there is no privileged kernel that must be patched to extend the system. Model adapters, tool invocation, session recording, main loop scheduling, and permission approval all exist as plugins, assembled into a runnable whole through a configuration tree.

    What most often misleads beginners are bundles whose names contain words like “base” or “core.” They sound like low-level libraries you import, but they are actually bundles: the package manifest declares a bundle marker and carries a patch-style configuration that inserts dozens of plugin entries into an empty configuration tree. In other words, it is not an API you call, but a declaration of which plugins need to be mounted.

    A typical base bundle configuration covers these capability domains:

    • Scheduled tasks and hot reload
    • LLM access and specific model adapters
    • Session event logs and in-memory storage
    • Agent interfaces and the default driver (main loop)
    • Tool registry and prompt assembly
    • Subprocess and command-line execution
    • Sandbox isolation and approval policies
    • Filesystem capabilities and access policies
    • User settings and credential management
    • Sub-agents and workflow orchestration
    • Web search and content fetching

    Making the base a plugin has clear benefits: the kernel needs no special-case branches reserved for extensions; capabilities are pluggable, replaceable, and trimmable; the same assembly logic supports both a minimal viable form and a full form. The cost is a longer debugging chain—an error may come from the plugin itself, the assembly order, module resolution, or the artifact form, rather than from a central function.

    2. Your First Plugin: Locating the Problem from Editor Errors

    The practical recommendation is to start by writing a minimal plugin, and the first step is often not coding but resolving type resolution errors in the editor.

    Recommended troubleshooting order:

    1. Confirm dependencies are installed in a resolvable location. Most red squiggles are not syntax problems but missing type declarations.
    2. Confirm the package entry and type entry match. When runtime resolution works but type resolution fails, it usually points to a missing types/typings field or one that references a nonexistent declaration file.
    3. Confirm you are in the same workspace. Cross-package references without workspace links are treated as ordinary external dependencies by the editor, causing resolution to fail.
    4. Restart the language service and clear caches. When incremental indexing is corrupted, a restart is often more effective than continuing to edit code.

    A minimal plugin skeleton (pseudocode, structure only):

    1. // A plugin exports an "assembly function" that receives a context and registers capabilities
    2. export const myPlugin = (ctx) => {
    3. ctx.on('session.start', (payload) => {
    4. // Log or modify session behavior
    5. })
    6. return { name: 'my-plugin', version: '0.1.0' }
    7. }

    The key insight is that a plugin is not a “module called by the main program” but a “module that registers capabilities with the context.” Therefore a plugin’s behavioral boundary is determined by the interfaces the context exposes, not by the exported function signature.

    3. Engineering Configuration: Separating Commonly Confused Concepts

    Most confusion at the beginner stage comes from mixed configuration semantics. Separate them by responsibility:

    • Dependency declaration: describes “what I need,” not “how it is resolved.”
    • Path mapping: affects resolution only during type checking and does not change runtime behavior.
    • Build configuration: determines artifact form (single file, multiple files, whether dependencies are bundled).
    • Module mode: determines the semantics of import/require and extension requirements.

    A common mistake is “fixing” the editor with path mapping and assuming runtime resolution will follow the same rules. In fact, path mapping only takes effect at compile time; runtime still resolves by package entry and module resolution rules. If the two disagree, you get “all green in the editor, crash on run.”

    The practical advice is to keep a single source of truth across all three: the package entry field, build output path, and type declaration path should point consistently, avoiding two sets of truth.

    4. Build: What Happens Behind a Single Command

    Running a build command usually involves at least four things:

    1. Dependency graph resolution: determining the boundary between local packages and external dependencies.
    2. Type checking and declaration output: generating or validating type declarations.
    3. Transpilation and bundling: producing executable files according to the target module mode.
    4. Artifact output and metadata alignment: ensuring entry fields point to files that actually exist.

    When troubleshooting, separate “type errors” from “artifact errors”: the former surface during checking, the latter usually surface at startup. If the build succeeds but startup fails, suspect the entry field, module mode, and extensions first, not business logic.

    5. Two Run Paths: Source Startup and Artifact Startup

    Plugin-based frameworks usually support two run forms:

    • Source startup: assembles directly from workspace source, with changes taking effect immediately; suitable for development and debugging, but more sensitive to resolution rules.
    • Artifact startup: loads built files, with behavior closer to the real published state; suitable for pre-release verification.

    Build a “dual-track verification” habit: use source startup during development for fast feedback, and do a cold-start verification with artifact startup before committing. When the two disagree, the problem almost always lies in the resolution and artifact layers, not the plugin logic layer.

    6. Workspace Mechanism: How Local Packages Are Linked Correctly

    Multi-package collaboration relies on workspace capabilities, which come down to two things:

    • Linking local packages: making the framework resolve packages inside the workspace first, rather than an external package of the same version.
    • Workspace protocol declaration: explicitly expressing “use the local version” in dependencies to avoid version drift.

    Example:

    1. {
    2. "dependencies": {
    3. "my-plugin": "workspace:*"
    4. }
    5. }

    If linking fails, the typical symptom is “I changed the source but nothing changed at runtime,” because an external copy is actually loaded. In that case, check whether the link is established, whether multiple copies of the same package exist, and whether the lockfile points resolution to the wrong location.

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

    A pre-publish checklist should include:

    • Entry field, type field, and artifact path are consistent;
    • The workspace protocol is not carried into the published artifact (replace it with a real version range before publishing);
    • The artifact contains no traces of development-time path mapping;
    • A minimal reproducible assembly configuration snippet is included so others can mount and verify it.

    Publishing is not the endpoint but the starting point of “installability.” An installable unit must be resolvable, assemblable, and removable in a clean environment without leaving side effects.

    8. User-Level Configuration Directory at Runtime

    Most frameworks maintain configuration and profiles under the user directory to distinguish different usage scenarios, such as a form oriented toward UI interaction and a form oriented toward batch processing. Three points to understand:

    • A profile is a snapshot of the assembly result, not source code;
    • Priority is usually “user level overrides project level, project level overrides default”;
    • When troubleshooting “why my plugin didn’t take effect,” first confirm whether the currently active profile actually mounts it.

    9. The Full Module Resolution Chain

    Broken down, the resolution order is roughly: entry field → module mode → extension completion → workspace link → external dependency lookup → cache. Any misalignment shows up as “module not found” or “wrong version loaded.”

    An efficient troubleshooting method: reproduce with a minimal sample first, then print resolution results layer by layer; do not change configuration, dependencies, and artifacts at the same time, or you cannot attribute the cause.

    10. Mental Model and Summary

    Consolidate the understanding with four sentences:

    1. The base is a plugin, and assembly is the system;
    2. Type resolution and runtime resolution are two separate rule sets;
    3. Source startup and artifact startup must be verified on both tracks;
    4. A published artifact must be resolvable, assemblable, and removable in a clean environment.

    With this model, facing any “red squiggle—build—startup” problem, you can quickly determine whether it falls in the assembly layer, the resolution layer, or the artifact layer, compressing troubleshooting time from hours to minutes.