Modular Agent Framework Refactoring: The "Everything Is a Plugin" Approach in Practice
This article breaks down the shift from monolithic coding agents to modular agent frameworks built on the formula Agent = Model + Harness. It explains the layered architecture, plugin contracts, context budgeting, state management, extension workflow, observability, and security requirements, and offers a risk-based checklist for deciding whether such frameworks are ready for production use.
1. Introduction: Why Agents Need a Structural Breakdown
For a long time, most discussions about coding agents focused on a single dimension: whether the model is stronger, the context window is longer, or generation is faster. But once you put these systems into a real engineering workflow, the bottleneck is often not the model itself. It is the entire set of mechanisms outside the model that make the agent productive: how tools are registered and discovered, how tasks are decomposed and planned, how execution is scheduled, how side effects are isolated, how state is persisted, and when the loop terminates.
This has led to a new abstraction in the industry: writing an agent as a minimal formula.
Agent = Model + Harness
Here, Model is a replaceable reasoning component, while the Harness contains the tool layer, planning layer, scheduling layer, sandbox layer, storage layer, session layer, and main loop. Its core claim is a single sentence: everything is a plugin. This article uses that claim as the main thread to discuss the positioning, layered design, plugin contracts, and extension practices of modular agent frameworks, as well as how to rationally evaluate whether to adopt them for production amid the current hype.
The conclusion first: these frameworks are worth installing and studying, and their architecture is especially worth reading closely. However, while the ecosystem and stability have not yet converged, it is not advisable to put critical business paths directly on top of them.
2. Positioning: It Is Not “Another Coding Assistant”
A common first reaction is to see it as a clone of some intelligent programming tool. That understanding understates the problem. Coding is only one typical application form of the Harness. What the framework really addresses is a more fundamental question: which components make up an agent, and can those components be separated, replaced, and recombined?
Traditional all-in-one products tightly couple the model, tool chain, and interaction layer into a complete deliverable. The advantage is that they work out of the box with a consistent experience; the cost is high replacement overhead, because changing the implementation of any layer means accepting the constraints of the whole. Modular frameworks take the opposite path: they move the model down from the center and make it just another pluggable implementation, like tools, sessions, and sandboxes.
A useful comparison:
| Dimension | All-in-One Agent Product | Plugin-Based Harness |
|---|---|---|
| Model | Bound to the product | Replaceable component |
| Tools | Mostly built-in | Registered and discovered; third-party implementations allowed |
| Sandbox | Fixed policy | Pluggable isolation backends |
| Storage/Session | Internal format | Adapter interfaces |
| Main Loop | Hard to change | Replaceable strategies allowed |
| Extension | Depends on official capabilities | Write a plugin |
It is important to emphasize that replaceability does not mean no constraints. A truly mature plugin-based system always provides clear contracts and default implementations. Otherwise, “everything is a plugin” degrades into “everything is uncontrollable.”
3. Layered Architecture: What Is Inside the Harness
Breaking the Harness apart yields roughly six layers. Each layer should correspond to a stable interface and at least one default implementation.
Model adapter layer. It translates unified reasoning requests into the differences between vendor interfaces, and handles streaming output, tool-call protocols, error codes, and retry semantics. The key design point is to make “capability declarations” explicit, such as whether function calling or multimodal input is supported, so upper layers can degrade based on capability rather than name.
Tool layer. It covers tool registration, discovery, parameter validation, permission declaration, and result return. A tool description is essentially API documentation for the model, and its quality directly determines call accuracy.
Planning and task layer. It breaks vague goals into verifiable subtasks, maintains todos and dependencies, and supports failure fallback and retry boundaries.
Scheduling and execution layer. It decides concurrency, timeouts, priorities, and queue policies, and handles asynchronous execution and progress reporting for long-running tasks.
Sandbox and permission layer. The file system, network egress, and command execution all need boundaries. The default should be “least privilege plus rollback capability,” not “open first and patch later.”
Storage and session layer. It handles context compression, memory retrieval, artifact archiving, and audit logs. This layer determines whether a long workflow is recoverable and reviewable.
The main loop (Agent Loop) spans all of the above: fetch context, request the model, parse actions, execute tools, fill results back in, and decide whether to terminate. Making it a replaceable strategy allows switching between “cautious” and “aggressive” execution styles without changing other components.
4. Plugin Contracts: How “Everything Is a Plugin” Actually Works
Whether “everything is a plugin” holds depends on whether the contract design is restrained and complete enough. A usable plugin description usually contains four parts: identity and version, capability declaration, input/output schema, and permissions and resource declarations.
Illustrative description (pseudocode, structure only):
plugin:id: fs.readversion: 1.0.0capabilities: [filesystem.read]schema:in: { path: string, max_bytes?: number }out: { content: string, truncated: boolean }permissions:- fs.read(path.scope)limits:timeout_ms: 3000max_bytes: 1048576
Four engineering lessons around contracts are worth standardizing:
- Prefer declarative definitions. Permissions, timeouts, and resource limits should be statically checkable by the framework, not exposed only at runtime.
- Make failures classifiable. Classify errors into retryable, requiring human confirmation, and unrecoverable, so the main loop can make correct decisions.
- Make results trimmable. Overly long tool output quickly consumes the context budget, so truncation markers must be explicit.
- Allow versions to coexist. Once the plugin ecosystem opens up, multiple versions running in parallel is normal, and interfaces must remain backward compatible.
5. Context and State: The Underrated Core Engineering
After plugin modularization, the most likely source of problems is not an individual plugin but the context budget. It is recommended to split context into four parts with separate quotas: system constraints, task state, retrieval snippets, and tool output. Once the quotas are clear, compression strategies have a basis.
context_budget:system: 10%task_state: 20%retrieval: 30%tool_output: 40%
For state, a combination of “event stream plus snapshot” is recommended: the event stream is for auditing and replay, while the snapshot is for fast recovery. Being able to continue from a snapshot after a long task is interrupted, rather than rerunning from scratch, is the dividing line for whether it can be used in a real workflow.
6. Extension Practice: The Full Process of Writing a Plugin
Using a “structured log write” plugin as an example, a five-step approach is recommended:
- Define the schema. Clarify whether the input is structured fields or plain text, and whether the output includes a write identifier.
- Declare permissions. Request only permission to write to a specified prefix path, avoiding full write access.
- Implement and validate. Validate the schema at the entry point first, then perform business processing, and finally wrap errors with unified classification.
- Verify locally. Construct three types of cases: normal, boundary (overly long content), and exception (insufficient permissions).
- Roll out gradually. Run in read-only or shadow mode first, compare differences with the existing implementation, and then gradually increase traffic.
A minimal implementation skeleton:
def run(payload):if not isinstance(payload, dict):return err("INVALID_INPUT", retryable=False)text = payload.get("text", "")if len(text) > MAX_BYTES:text, truncated = text[:MAX_BYTES], Trueelse:truncated = Falsesink.append({"text": text, "truncated": truncated})return ok({"written": True, "truncated": truncated})
7. Observability and Security: Required Answers Before Production
Modularity does not automatically bring operability. At least three types of signals are needed: tracing (which step consumed time and tokens), metrics (success rate, retry rate, average rounds), and logs (structured and desensitizable). On the security side, default deny, least privilege, keeping sensitive information out of context, and traceable artifacts must be implemented.
For cloud deployment, general-purpose category capabilities can be used: container platforms host executors, object storage archives artifacts, message queues decouple long-running tasks, and logging services with monitoring and alerting handle observability. This keeps the approach neutral and avoids binding to a specific implementation.
8. Rational Evaluation: What It Is Suitable for Now
It is recommended to proceed in risk tiers:
- Suitable: internal R&D efficiency, architecture pre-research, refining plugin contracts and tool descriptions, and offline batch processing tasks.
- Caution: paths involving production write operations, strong consistency state, or strong compliance auditing.
- Not recommended for now: serving as the sole entry point for critical business, or deeply customizing private branches before the ecosystem converges.
The evaluation checklist can be simplified to six questions: Is the contract stable? Are the default implementations complete? Are failures classifiable? Is state recoverable? Are permissions minimized? Are upgrades backward compatible? Only when all six can be answered should production adoption be discussed.
9. Conclusion
The value of “everything is a plugin” is not making the framework look flexible, but turning every layer of the agent into a replaceable, testable, and governable engineering object. The model returns to being a component, capabilities settle into contracts, and workflows settle into state and events. Understanding and practicing this layered method can significantly improve the maintainability and evolution speed of a self-built agent system, even without adopting a specific framework.
