Understanding the Plugin-Based Agent Harness: Architecture and Practice
This article explains the harness, the runtime shell that assembles and drives an AI agent system under a "everything is a plugin" philosophy. It covers how base composition packages and config patches declare plugins, why compile-time configuration is not runtime configuration, what the build command produces, and how source startup differs from artifact startup. It also walks through workspace linking, publishing a self-contained plugin package, config profiles, and the full module resolution chain, ending with a mental model for extending and troubleshooting agent harnesses.
1. Why the Harness Matters
In agent application development, capabilities such as model invocation, tool execution, session recording, and main-loop scheduling are usually wrapped inside a “runtime shell” known as the harness. Its job is not to provide a specific capability, but to define how capabilities are assembled, resolved, and driven. Understanding the harness means understanding the assembly diagram of an agent system.
The core philosophy of the harness is “everything is a plugin”: there is no privileged kernel that needs patching. Model adapters, tool registration, log storage, and the main loop are all plugins, composed through configuration. Even the base package that looks like the foundation is itself a composition manifest rather than an interface library being called. This point is the easiest to misunderstand and is the root cause of all later build, startup, and publishing problems.
2. The Foundation: Composition Packages and Config Patches
Take a base composition package as an example. Its package descriptor declares a composition marker and ships with a config patch file that inserts dozens of plugin entries into an empty config tree. These entries roughly cover: scheduling and hot reload; model capabilities and vendor adapters; session event logs and in-memory storage; the agent interface and the default main-loop driver; the tool registry and prompt assembly; subprocess and command-line execution; sandbox and approval policies; filesystem capabilities; user settings and credentials; subagents and workflows; and web search and fetching.
This leads to the first conclusion: the base package is not an API but a declaration of “which plugins I want to mount.” Reading it is equivalent to reading the capability boundaries of the entire system.
3. Clarifying the Role of tsconfig
Beginners often treat compile configuration as runtime configuration. In fact, compile configuration only affects type checking and artifact generation and does not participate in plugin assembly; plugin assembly is determined by the config tree and patches. Confusing the two creates the illusion that “I changed the config but nothing took effect.” It helps to view compile configuration as a “writing standard” and the config tree as the “runtime blueprint.”
4. The Build System: What the Build Command Does
The build command usually does three things: determine order by dependency topology, run type checking and transpilation, and produce artifacts that the runtime can load. It is not a simple file copy; it converts source semantics into a module structure the runtime can recognize. If the build fails, look at type errors and dependency order first, rather than rushing to change runtime configuration.
5. Two Startup Paths: Source Startup and Artifact Startup
Source startup suits development and debugging, where changes are visible immediately and hot reload helps quickly verify plugin behavior. Artifact startup is closer to real deployment and loads the built modules. The two paths have different module resolution rules, so “runs from source but errors from the artifact” is a typical symptom; when troubleshooting, first confirm which path you are on.
6. Workspace Mechanism and Dependency Linking
Multi-package collaboration relies on workspace capabilities: the link function references local packages to one another, and the package descriptor declares dependencies with the workspace protocol to avoid version mismatches. Once linking takes effect, local changes are picked up directly; if linking is missing, the runtime falls back to the installed version, causing “I changed it but nothing happened.”
7. Publishing: From a Local Plugin to an Installable Package
Before publishing, confirm that the composition marker and config patch in the package descriptor are complete, that all dependencies are resolvable, and that the artifact includes the files required at runtime. The published artifact should be a self-contained composition package that can be mounted through configuration after installation, rather than requiring users to patch the kernel manually.
8. The Config Profile Mechanism
The profile directory under the user directory stores config tree snapshots for different scenarios, such as a profile targeting the web scenario. Switching profiles switches the plugin composition, achieving “one codebase, multiple capability forms.” Understanding profiles explains why the same version behaves differently under different directories.
9. The Full Module Resolution Chain
The resolution order is usually: the plugin name declared by the current config tree, workspace links, installed dependencies, and built-in defaults. A missing link at any step throws an error. It is best to verify layer by layer along the chain: first confirm the plugin is declared, then confirm whether it is linked or installed.
10. Mental Model and Summary
Think of the harness as “config tree + plugin set + resolver.” When a problem arises, ask in order: Is the plugin declared? Is the build artifact updated? Which startup path am I on? Is the workspace link effective? Was the profile switched? Mastering this chain makes extension and troubleshooting predictable.
