Understanding the Plugin-Based Agent Harness: Design and Practice
This article explains the core design of a plugin-based agent framework, commonly called a harness, where model adapters, tool calls, session logging, and the main loop are all plugins assembled through configuration rather than a patched privileged core. It walks through the built-in source packages, how to troubleshoot editor errors when adding a plugin, key TypeScript configuration concepts, the build pipeline, the two runtime paths of source versus build artifacts, workspace linking, publishing an installable bundle, layered configuration, and the full module resolution chain. Readers will gain a reusable mental model for extending and debugging this class of "everything is a plugin" agent runtime.
Understanding the Plugin-Based Agent Harness: Design and Practice
Prerequisites: basic familiarity with Node.js and package managers (npm/pnpm), plus the ability to read TypeScript type declarations and tsconfig configuration. This article does not focus on any specific vendor product. Instead, it abstracts the common design of a class of “everything is a plugin” agent runtime frameworks (referred to below as a harness) and provides reusable methods for troubleshooting and extension.
1. The Foundation: The Meta-Framework and Its Built-In Source
The core philosophy of a harness is “everything is a plugin”: there is no privileged kernel that needs patching. Model adaptation, tool invocation, session logging, and the main loop are all plugins, composed through configuration. Even the base package that looks like the foundation is itself a bundle: its manifest declares packaging markers, and a companion patch configuration inserts dozens of plugin lines into an initially empty configuration tree. These include scheduled tasks and hot reload, model capabilities and model adapters, session event logging, the agent interface and default driver, the tool registry and prompt assembly, subprocess and command execution, sandbox and approval policies, filesystem capabilities, settings and credentials, sub-agents and workflows, and network retrieval capabilities.
Making the “foundation” a plugin brings three benefits. First, replaceability: any capability can be overridden by an implementation with the same name. Second, trimmability: lines you do not need are simply not inserted. Third, observability: the configuration tree is the runtime topology, so troubleshooting does not require guessing at implicit dependencies. The so-called “built-in source” usually refers to the original implementation and declaration files bundled inside dependency packages, which makes breakpoint debugging and type navigation easier and avoids receiving only minified output.
2. Your First Plugin: Starting from an Editor Error
A common issue for beginners is that the editor flags errors after adding a new plugin. The recommended troubleshooting order is: confirm the package is declared in the dependency manifest, verify the workspace link has been established, check that the type entry field points to an existing declaration file, and ensure the plugin line name in the configuration tree matches the export. Example:
// Plugin entry: the exported name must match the configuration lineexport const name = 'tool-demo';export function apply(ctx) {ctx.tool('demo', async (args) => ({ ok: true, args }));}
3. Clarifying Key Configuration Type Concepts
Common fields in tsconfig each have a distinct role: include/exclude determine the set of files that participate in compilation, paths only performs type-level path mapping, references describes build dependencies between projects, and the compile output directory and module resolution mode determine the structure of the output. The key point is: being able to navigate types does not mean the module can be resolved at runtime; the two must be verified separately.
4. The Build System: What the Build Command Actually Does
A typical build flow is: clean the output directory → compile each package in dependency topological order → generate declaration files → produce an installable bundle. If the build fails, first check whether the topology contains a cycle, then check whether a cross-package reference declaration is missing.
5. Source Startup vs. Build Artifacts: Two Runtime Paths
The source path loads the original implementation directly. It is suitable for development and debugging, starts slightly slower, but takes effect immediately on changes. The artifact path loads the bundled result; it starts fast, behaves stably, and is suitable for acceptance testing and release. The differences between the two mostly come from module resolution conditions and file existence. When you hit “works in development but errors from the artifact,” prioritize comparing the entry fields and resolution conditions.
6. Workspace Mechanics: Local Linking and Protocol
A workspace maps local packages into the dependency directory through links. The workspace protocol in the manifest is replaced with a real version number at publish time. If a link breaks, the symptom is that the module cannot be found at runtime; rebuilding the link restores it.
7. Publishing: From a Local Plugin to an Installable Bundle
Before publishing, verify the version number, export entries, declaration files, whether dependencies have been replaced, and whether the bundle’s patch configuration is complete. It is recommended to install and verify in a clean environment first, then proceed to the formal release process.
8. Configuration Layers: What the User-Level Config Directory Is
The user-level configuration directory usually stores multiple sets of runtime configurations (such as a default configuration and an experimental configuration), with the currently active one specified by startup arguments or the environment. The layering order is generally built-in defaults → user configuration → startup argument overrides, which makes it easy to isolate experiments from a stable baseline.
9. The Full Module Resolution Chain
The resolution chain can be summarized as: entry field → workspace link → dependency directory → walking up parent directories level by level. Once you understand this chain, most “module not found” problems can be traced to a missing link somewhere along it.
10. Summary and Mental Model
Think of a harness as a “configuration tree + resolver + plugin collection”: the configuration tree describes the topology, the resolver determines the loading source, and the plugins provide capabilities. Mastering the two paths of build and startup, along with layered configuration and the resolution chain, is enough to extend and troubleshoot reliably. If cloud hosting is needed, common capabilities such as container platforms, object storage, and log monitoring can carry the runtime and observability.
