Pluggable AI Coding Agent Architecture: Context, Tools, and Verification
This article breaks down a pluggable architecture for AI coding agents, where context construction, model access, tool registration, permission checks, and result validation are all replaceable units. It explains three measurable layers—context management, tool permission boundaries, and a verification loop—along with configuration examples, trade-offs of building a custom agent, and a four-step adoption path with common pitfalls.
1. The Real Technical Question: From Skin Deep to Replaceable Architecture
Several command-line coding assistants maintained by individual developers have appeared in the community recently. They feel close to mainstream AI coding tools in terms of interaction and iterate quickly. But treating these projects as interface-level imitation misses the real technical dividing line: a new generation of harness-style designs treats “everything is a plugin” as the first principle. Context construction, model access, tool registration, permission checks, and result validation all become replaceable units.
The significance of this shift is that the system’s capability boundary is no longer fixed by a particular product; it is determined by how the user assembles the pieces. The cost is equally clear: the more configurable options there are, the higher the variance in system behavior. Closed, integrated solutions are stable precisely because they hard-code most decisions internally. A highly pluggable design hands decision-making back to the user, and hands the engineering responsibility back along with it.
So evaluating this kind of architecture should not stop at comparing feature lists. It should come back to three measurable questions: Is context controllable? Do tool permissions have boundaries? Are execution results verifiable?
2. Layer One: Context Management Decides Whether an Agent Drifts and Makes Unwanted Edits
Context is the scarcest resource for a coding agent. The window is limited, while a codebase often far exceeds its capacity, so the selection strategy directly determines output quality.
The policies that need to be defined explicitly include:
- Admission rules: which files enter the prompt. The recommendation is “symbols relevant to the current task and their direct dependencies,” rather than bulk-loading whole directories.
- History compression: intermediate results from multiple tool-call rounds must be trimmed, keeping only conclusions and failure reasons.
- Summary timing: when a task spans multiple phases, phase-level summaries save more tokens than linear accumulation.
- Re-reading source: read the actual file content again before editing, to avoid relying on an outdated version from memory.
An illustrative policy can be written as configuration rather than hard-coded:
context_policy:include: ["src/**/*.py", "tests/**"]exclude: ["dist/**", "*.lock"]max_files: 12compress_after_turns: 6summary_on_phase_change: truereread_before_edit: true
Without this layer, the most common failure is an agent editing code based on a stale impression and then introducing regressions in unrelated modules.
3. Layer Two: The Key to Tool Orchestration Is Boundaries, Not Count
Reading files, writing files, running commands, calling external capabilities, and requesting human approval carry very different risk levels. More tools does not mean more capable; blurred boundaries are the main source of risk. An agent with out-of-control permissions is far more dangerous than one that cannot use tools at all.
A practical approach is to classify tools by side effect and force high-risk actions through confirmation:
TOOLS = {"read_file": {"side_effect": "none", "confirm": False},"write_file": {"side_effect": "local", "confirm": True},"run_cmd": {"side_effect": "host", "confirm": True,"allow": ["pytest", "ruff", "mypy"]},"call_mcp": {"side_effect": "external", "confirm": True},}
Supporting engineering constraints include: use an allowlist rather than a denylist for command execution; restrict write operations to the workspace directory; route external calls through a controlled gateway for easier auditing and rate limiting; and keep structured logs of all tool calls for traceability. If stronger isolation is needed, the execution environment can be placed in a container platform, with logging services and monitoring alerts forming an observable closed loop.
4. Layer Three: A Verification Loop Turns “Done Once Written” into “Deliverable”
A genuinely useful coding agent does not stop after generating code. It runs tests, static checks, and type checks on its own, feeds the errors back to the model, and then decides whether to keep fixing or stop and ask.
A minimal loop can be abstracted as:
while attempt < max_attempts:result = run_checks()if result.passed:return resultif not result.recoverable:ask_human(result.summary)returnfeed_back(result.errors)attempt += 1
Two parameters here are the most easily overlooked: the maximum retry count sets the cost ceiling, and the recoverability check decides when to cut losses. An agent without a stop condition tends to burn budget repeatedly on the same error.
5. Combining Capabilities and the Trade-off of Building Your Own Domain Agent
A pluggable architecture lets you assemble an agent from different models: a strong reasoning model handles planning, a lightweight model handles retrieval and formatting, and a specialized small model handles classification. This combination is most valuable in vertical scenarios, such as internal framework migration, remediation against a specific language style guide, or adapting to a company’s own components.
Conversely, if the task is just everyday general coding, a general-purpose assistant is already enough, and building your own only adds maintenance burden. The criteria are simple: is the domain knowledge stable and reusable, and can the workflow be described clearly? Only when both hold is the investment worthwhile.
6. Adoption Path and Common Pitfalls
The recommended path is four steps: first solidify the context policy, then tighten tool permissions, then add the verification loop, and only then freely swap models and plugins. Reversing the order leads to many hard-to-diagnose problems.
There are three common pitfalls: treating configurable as mandatory to configure; measuring capability by the number of tools; and lacking cost and safety limits. Pluggability brings freedom, and freedom only turns into productivity when paired with boundaries and verification.
