Plugin Agent Framework: A Beginner's Guide to Architecture and Practice

    This guide explains how a plugin-based agent framework is assembled from configuration trees, patch files, and bundles, and walks through building your first plugin, TypeScript build setup, module resolution, workspace linking, and publishing. It also covers the two runtime paths, profiles, and a step-by-step mental model for debugging silent failures.

    1. Start Here: Everything Is a Plugin

    The most misunderstood aspect of a plugin-based agent framework is that the “base” is not a privileged core. Model adapters, tool registration, session logs, main loop scheduling, file access, subprocess execution, sandbox and approval policies—all of these exist as plugins and are composed through a configuration tree. Even bundle packages with names like base or core are essentially a mount manifest, not a function library called directly by business code.

    This design delivers three direct benefits:

    • Replaceable: any capability can be overridden by a plugin with the same name, without modifying the framework source.
    • Trimmed: capabilities you do not add to the configuration tree are never loaded at runtime.
    • Composable: different profiles map to different plugin sets, keeping development and delivery environments isolated.

    Understanding this is the prerequisite for all troubleshooting: an error usually does not mean “the framework is broken,” but rather “a line is missing from the configuration tree, or one line failed to parse.”

    2. The Foundation: Configuration Trees, Patch Files, and Bundles

    Assembly is typically handled by two types of files: the base configuration describes which lines exist initially, and the patch file describes which lines to insert, replace, or delete, and where. A bundle packages a set of plugin lines together with their dependencies for distribution, expanding into configuration entries once installed.

    A typical bundle declaration:

    1. {
    2. "name": "my-agent-base",
    3. "version": "0.1.0",
    4. "dsh": { "bundle": true },
    5. "dependencies": {
    6. "plugin-timer": "workspace:*",
    7. "plugin-llm": "workspace:*"
    8. }
    9. }
    1. # cordis.patch.yml (illustrative)
    2. insert:
    3. - id: timer
    4. - id: hmr
    5. - id: llm
    6. - id: session
    7. - id: agent-loop
    8. - id: tools
    9. - id: system-prompt
    10. - id: subprocess
    11. - id: sandbox
    12. - id: approval
    13. - id: fs
    14. - id: settings
    15. - id: credentials

    The key point is that insertion order affects dependency resolution and initialization timing. Infrastructure such as hot reload and timers usually goes first; capability plugins (model, tools, filesystem, network) go in the middle; policy plugins (sandbox, approval, credentials) go last so they can read the capability manifest registered before them.

    3. Your First Plugin: Starting from Editor Errors

    The first wall most beginners hit is a screen full of red in the editor: module not found, type not found, command not found. A fixed four-step checklist is recommended:

    1. Confirm the package is actually installed in node_modules, not just listed in the manifest.
    2. Confirm the workspace protocol is linked correctly (see Section 6).
    3. Confirm the type entry field matches the build output path.
    4. Confirm the plugin is written into the configuration tree; otherwise it will not load at runtime.

    A minimal plugin skeleton:

    1. import { definePlugin } from 'cordis';
    2. export default definePlugin({
    3. id: 'tool-echo',
    4. inject: ['tools'],
    5. apply(ctx) {
    6. ctx.tools.register({
    7. name: 'echo',
    8. description: 'Echo the input, for integration testing',
    9. async run(text: string) { return text; }
    10. });
    11. }
    12. });

    inject declares dependencies, and apply runs the registration once those dependencies are ready. If tools does not appear in the configuration tree, the plugin stays in a waiting state, showing up as “no code errors, but the feature does nothing.”

    4. Clarifying Configuration and the Build System

    Three common misconceptions about TypeScript configuration need to be separated: type checking is not the same as producing output; path aliases only apply at compile time and still require real files at runtime; references only solves type navigation across multiple packages and is not responsible for bundling.

    The build step usually does four things: type checking, generating output per entry, generating declaration files, and cleaning and copying static assets. Example commands and output structure:

    1. pnpm build
    2. # dist/index.js runtime entry
    3. # dist/index.d.ts type declarations

    If the output is missing or the declaration file points to the source directory, the editor and runtime will show a split where “the same module resolves two different ways.” This is why Sections 4 and 5 must be read together.

    5. Two Runtime Paths: Source Startup and Output Startup

    • Source startup: runs directly from the source entry, relies on workspace links, and picks up changes immediately—suitable for development.
    • Output startup: loads only the built files, with shorter paths and stable behavior—suitable for verifying release artifacts.

    The difference between the two paths comes down to module resolution: the source path relies on aliases and workspace symlinks, while the output path relies on package export fields. Re-testing with the output path before release surfaces most “works locally, fails after install” problems early.

    6. Workspace Mechanism and Dependency Linking

    A multi-package repository declares internal dependencies through the workspace protocol, creating links at install time rather than downloading copies:

    1. { "dependencies": { "plugin-tools": "workspace:*" } }

    Once the link is created, confirm that the link target’s actual entry matches its export fields. A common failure is a successful link with an empty entry, causing runtime resolution to an empty module.

    7. Publishing: From Local Plugin to Installable Bundle

    Pre-publish checklist: complete build output, correct declaration files, reasonable dependency version ranges, patch file paths consistent with in-package paths, and inclusion of required asset files. After publishing, verify once with a “clean environment install” to avoid relying on the local cache.

    8. Profiles and the Full Module Resolution Chain

    A profile is a snapshot of the runtime plugin set, usually located in a configuration area under the user directory, and it determines which lines are mounted for this startup. The full resolution chain can be summarized as: entry field → export conditions → workspace link → patch expansion → configuration tree assembly → dependency injection → plugin apply. A missing link anywhere shows up as a silent feature failure, and verifying the chain segment by segment will locate it.

    9. Mental Model Summary

    Think of the framework as an assembly line: bundles provide the parts list, patch files determine the assembly order, the profile decides which set to assemble this time, and module resolution delivers the parts to each station. Once you grasp this line, taking a custom plugin from development to release is just a matter of completing each link along the chain. If you need cloud hosting and canary releases, general-purpose capabilities such as container platforms, object storage and logging services, and monitoring and alerting can handle build artifacts and runtime observability.