Plugin-Based Agent Harness: Architecture and Implementation

    This article explains why an agent needs a harness, how to divide the runtime into six pluggable layers, and how to evaluate the replacement cost of each layer. It covers minimal setup, plugin selection, writing a tool plugin, cancellation and progress reporting for long-running tasks, security and data considerations, and a practical three-step adoption plan.

    1. Why Agents Need a Harness

    A harness originally means horse tack and reins. In the agent field, it refers to the runtime environment wrapped around a large model. The model itself only generates text or outputs invocation instructions in an agreed format. The harness is responsible for translating those outputs into real tool calls, file reads and writes, code execution, and environment management. The model is the engine, and the harness is the complete vehicle. Without a chassis, steering wheel, and wheels, even a powerful engine cannot drive.

    Traditional agent frameworks often bind model access, tool registration, session management, and UI integration together. When developers want to replace one part, they often need to change a large amount of code. The “everything as a plugin” approach targets this problem: make every runtime component a pluggable module so that replacing one layer does not affect the others.

    2. Responsibilities and Replacement Costs of the Six Plugin Layers

    Layer Main responsibility Interface boundary Replacement cost
    Model layer Connect to local inference or cloud APIs Unified request and response format Low; business code remains unchanged
    Tool layer File I/O, command execution, web scraping, etc. Tool name, parameter schema, return structure Low; replace tools one by one
    Skill layer Prompts, workflows, subtask orchestration Skill manifest and input/output declarations Medium; depends on tool layer capabilities
    Session layer History storage, compression, retrieval Read/write, compression, and retrieval methods Medium; involves data migration
    Sandbox layer Code execution environment Execution request and isolation level Medium; security must be revalidated
    UI layer CLI, web UI, editor integration Communication protocol with the core Low; interfaces do not affect each other

    The core only handles protocol and lifecycle management. Feature increments are delivered by plugins, so the community can develop in parallel without waiting for a core release.

    3. Get the Minimal Environment Running First

    The following commands use placeholders. Replace them with the real package name and commands in the project README.

    1. Confirm that the Node.js version meets the project requirements. This article uses Node.js 18 as an example.
    2. Install the CLI globally:
    1. npm install -g <harness-package-name>
    1. Start the service:
    1. <harness-cli> serve
    2. # Open http://localhost:3080 in a browser

    Port 3080 is only an example. Most frameworks allow the port to be changed through a configuration file or startup parameter. Follow the project documentation for the specific method.

    1. Enter the model service API key on the settings page, then send a test message.

    Common issues and troubleshooting methods are as follows.

    • Global installation reports a permission error: prefer changing npm’s global directory to a user directory instead of using sudo directly, which introduces additional security risks.
    • Port is occupied: use lsof -i :3080 (macOS or Linux) or netstat -ano (Windows) to find the process using the port, or switch to another port.
    • The page does not open: confirm that the service process is still running and check the error messages printed in the terminal.
    • The conversation returns an authentication failure: check whether the API key is correct, whether it has expired, and whether the account quota is sufficient.

    Note that many harnesses ship with limited features. Capabilities such as image recognition, file references, and context compression usually require additional plugins.

    4. Plugin Selection Checklist

    Community plugins broadly fall into four categories: basic experience (image recognition, file references, Markdown rendering), productivity tools (code review, test generation, log analysis, scheduled tasks), integration extensions (version control, project boards, messaging notifications), and security sandbox (container execution, sensitive information masking, permission auditing).

    Before selecting plugins, check each item in the following list.

    Check item What to look at Warning sign
    Core compatibility Declared range of supported core versions No version declaration, or it does not match the current core version
    Maintenance activity Recent commits, Issue response speed No updates for a long time, Issues unanswered
    Least privilege Whether declared network, file, and process permissions match the functionality A plugin that only converts formats requests all file permissions
    Sandbox isolation Whether arbitrary code runs in an isolated environment Executes user-input code directly on the host
    License Whether the license permits your intended use No license file

    5. Writing a Tool Plugin

    A tool plugin usually contains three parts: a manifest file, capability registration, and lifecycle hooks. The manifest must declare the name, version, compatible core version, and permissions required by the plugin.

    1. // weather-lookup/index.js
    2. export default {
    3. name: "weather-lookup",
    4. version: "1.0.0",
    5. harnessVersion: ">=1.0.0",
    6. permissions: ["network:weather-api.example.com"],
    7. tools: [
    8. {
    9. name: "get_weather",
    10. description: "Get the current weather for a specified city. The city name can be provided in Chinese or pinyin.",
    11. parameters: {
    12. type: "object",
    13. properties: {
    14. city: { type: "string", description: "City name" }
    15. },
    16. required: ["city"]
    17. },
    18. async run({ city }) {
    19. if (typeof city !== "string" || city.trim() === "") {
    20. return {
    21. ok: false,
    22. error: { code: "INVALID_ARGUMENT", message: "city must be a non-empty string" }
    23. };
    24. }
    25. try {
    26. const data = await fetchWeather(city.trim());
    27. return { ok: true, data };
    28. } catch (err) {
    29. return {
    30. ok: false,
    31. error: { code: "UPSTREAM_ERROR", message: "The weather data source is temporarily unavailable" }
    32. };
    33. }
    34. }
    35. }
    36. ]
    37. };

    There are three key points in this code.

    First, parameter validation is performed inside the plugin. Even if the core has already performed schema validation, the plugin should still check types and empty values because the plugin may be used directly by other callers.

    Second, errors are returned using a consistent ok plus error structure. The model can use this to decide whether to retry, and logs can count problems by error code. Exception information should not contain secrets or internal paths.

    Third, the tool description should clearly state the purpose and meaning of the parameters. The model relies on the description to decide when to call the tool, and a vague description directly reduces call accuracy.

    fetchWeather is an assumed helper function. The actual implementation needs to call the data source you choose.

    6. Cancellation and Progress for Long-Running Tasks

    Tools that take a long time should support cancellation and progress reporting; otherwise they block the entire session. The following example assumes that the core provides a cancellation signal and progress callback in the execution context. The specific interface names depend on the documentation of the framework you use.

    1. async run({ city }, ctx) {
    2. ctx.progress?.(0.1, "Starting data source request");
    3. const res = await fetch(buildUrl(city), { signal: ctx.signal });
    4. if (!res.ok) {
    5. return { ok: false, error: { code: "UPSTREAM_HTTP", message: `Status code ${res.status}` } };
    6. }
    7. ctx.progress?.(0.9, "Parsing result");
    8. return { ok: true, data: await res.json() };
    9. }

    Long-running tasks should also have a timeout. After a timeout, return a clear error code and release any resources already occupied.

    7. Security and Data Considerations

    • API keys, tokens, and other secrets should only be placed in environment variables or a secret management service. Do not write them into code or output them to logs.
    • User input and model output in logs should be masked, especially phone numbers, ID numbers, and email addresses.
    • Session data needs a clear retention period. Conversation records stored for a long time may contain sensitive content and should be cleaned up regularly.
    • Plugins that execute arbitrary code must run in a sandbox and limit network and file access scope.
    • After each upgrade of the core or a plugin, validate the behavior of key tools in a test environment before using them in production.

    8. Summary and Action Plan

    Agent development is shifting from competing on models to competing on ecosystems. “Everything as a plugin” makes models, tools, and sandboxes replaceable, while the core only handles protocol and scheduling.

    A three-step approach is recommended. First, complete the minimal installation described in Section 3 and confirm that the model can hold a normal conversation. Second, use the checklist in Section 4 to select basic plugins and verify compatibility and permissions one by one. Third, package workflows you use repeatedly as tool plugins, and add validation, error returns, and cancellation mechanisms according to Sections 5 and 6.

    If your system is deployed in production, you can also consider supporting services such as object storage for session artifacts, a container platform for hosting sandbox execution, and monitoring and alerting for observing agent status. Before adopting these services, clarify their permission scope, data retention policy, and cost, then decide whether to use them.