Plugin-Based AI Agent Framework: Design and Development Practices

    This article explains how a plugin-based AI agent framework is designed around a simple principle: everything is a plugin, assembled through declarative configuration rather than a privileged core. It walks through the core design philosophy, how to troubleshoot the first plugin errors, key TypeScript configuration options, what a standard build does, the two runtime paths, workspace linking for local development, publishing checks, and the full module resolution chain. Readers will learn a practical mental model for building, running, and publishing plugins in a configuration-driven agent framework.

    1. Why “Everything Is a Plugin” Is the Starting Point

    The most important design philosophy of a plugin-based AI agent framework (referred to below as “the framework”) is that there is no privileged core that needs to be patched. Capabilities such as model adaptation, tool registration, session logging, main-loop scheduling, subprocess execution, file access, and web retrieval all exist as plugins, and they are assembled together through a composable declarative configuration.

    The part that most often confuses beginners is this: the bundles whose names contain words like “base” or “foundation” are not low-level libraries referenced directly by code. They are assembly manifests. Take a common bundle as an example. Its package description declares that it is of the “bundle” type and carries a configuration patch file that inserts dozens of plugin assembly entries into a configuration tree that starts out empty. Typical assembly entries include:

    • Scheduling and hot reload: provide periodic tasks and change detection during development;
    • Model capabilities and model adaptation: abstract a unified inference interface and connect to specific model services;
    • Session and event logging: record inputs, outputs, and tool-call traces to support replay and troubleshooting;
    • Agent interface and default driver: define the abstract contract of the main loop and its default implementation;
    • Tool registry and prompt assembly: manage the available tool set and generate the system prompt;
    • Subprocess and command-line execution: run external commands in a controlled environment;
    • Sandbox and approval policies: isolate high-risk operations and require human confirmation;
    • File system capabilities and policies: provide a unified read/write interface and enforce boundary constraints;
    • Settings and credential management: store user preferences and access credentials in one place;
    • Sub-agents and workflows: support task decomposition and multi-stage orchestration;
    • Web retrieval and fetching: supply external information to the agent.

    Making the foundation a plugin brings three direct benefits. First, replaceability: any capability can be replaced by another implementation with the same contract. Second, tailorability: capabilities that are not needed can be left unassembled, reducing the attack surface and resource usage. Third, evolvability: new capabilities are added by inserting one assembly entry, avoiding invasive changes to core code.

    2. Your First Plugin: Start Troubleshooting from Editor Errors

    The first obstacle beginners usually hit is red squiggly lines in the editor: types not found, modules that cannot be resolved, missing declarations. The recommended troubleshooting order is from the outside in:

    1. Confirm that dependencies are fully installed and that the package manager is pointed at the correct project root;
    2. Confirm that the sub-package the current file belongs to declares a dependency on the referenced package;
    3. Confirm that type declarations can be resolved (whether the type packages are installed and the appropriate resolution mode is enabled);
    4. Confirm that the paths, export names, and package export maps referenced in the configuration file are consistent.

    A high-value habit is to hand the error message, the relevant configuration snippets, and the reproduction steps to an AI coding tool that understands code, ask it for “possible root causes plus verification steps,” and then verify them one by one. This is more reliable than blindly changing configuration.

    A minimal plugin structure is shown below (it only expresses structure and is not tied to a specific implementation):

    1. my-plugin/
    2. ├── package.json # Declares package name, exports, dependencies, and the "bundle/plugin" marker
    3. ├── cordis.patch.yml # Declarative assembly: inserts this plugin into the configuration tree
    4. ├── src/
    5. │ └── index.ts # Plugin entry: registers tools and listens for events
    6. └── tsconfig.json # Used only for type checking and declaration output

    3. Configuration and Types: The Key tsconfig Options

    For type configuration, developers only need to firmly grasp a few frequently used options:

    • target and lib: determine syntax downleveling and which built-in types are available;
    • module and moduleResolution: determine the module resolution strategy, which must match the runtime resolution method;
    • The strict family: enables null checks and suppresses implicit any, exposing many problems early;
    • declaration and outDir: whether to emit type declarations and the output directory;
    • paths and baseUrl: development-time path aliases that must stay consistent with build and runtime resolution; otherwise you get “no error in the editor, but module not found at runtime.”

    Rule of thumb: the resolution strategy in your type configuration must share the same mental model as your runtime module resolution strategy; otherwise troubleshooting costs multiply.

    4. The Build System: What a Build Actually Does

    A standard build usually has four steps: type checking, transpilation, declaration file generation, and artifact organization. It solves the problem of “turning source code into modules and metadata that can be loaded at runtime.” It is worth stressing that a successful build does not mean a successful run, because at runtime the code still has to go through module resolution and assembly.

    5. Two Runtime Paths: Running from Source and Running from Build Output

    • Running from source: suitable for development; it relies on runtime transpilation and resolution, and changes take effect immediately;
    • Build output: suitable for release and stable operation; it loads the organized modules and declarations.

    The two paths have different requirements for “how modules are found,” and many “works locally but fails after installation” problems come from this difference.

    6. Workspaces: The Key to Local Integration

    Developing multiple packages together relies on workspace capabilities: workspace links point local packages at each other, and the workspace protocol is used to declare dependencies, avoiding publishing unfinished packages prematurely. The key point is that the link relationships, dependency declarations, and resolution strategy must all be consistent.

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

    Before publishing, check the following: whether the package export map is complete, whether all dependencies are declared, whether the bundle marker and assembly files are published with the package, and whether the output directory is clean. After publishing, verify once with a “fresh environment installation,” which can reveal hidden dependencies early.

    8. The Runtime Configuration Directory and the Full Module Resolution Chain

    At runtime, the framework usually reads a configuration area under the user directory (such as a profiles subdirectory), which determines “which plugins are assembled for this run and with what parameters.” The full module resolution chain can be summarized as: entry location → dependency declaration lookup → workspace links → package export map → artifact files. A missing link at any stage shows up as “module not found.”

    9. Summary of the Mental Model

    Understand the framework as “a configuration-driven plugin assembler plus a set of capabilities with unified contracts”: assembly comes first, then execution; contracts come first, then implementations; consistent resolution comes first, then stable publishing. With this main thread in mind, plugin development turns from trial and error into reasoned engineering.