Agent Development Framework Architecture: A Practical Guide to Building Pluggable AI Agents

    This article breaks down the architecture of agent development frameworks and explains how to build a pluggable agent from scratch. It covers why AI applications are shifting from single-turn chat to persistent, software-engineered tasks, what "everything is a plugin" means in practice, how dependency injection and lifecycle management work, and how spacetime composability enables branching execution maps. It also addresses cost control for large-scale runs, a six-step implementation path with code examples, and common pitfalls to avoid. Readers will gain a clear view of the extension points, security guardrails, and metrics needed to move from prompt engineering to production-grade agent engineering.

    Agent Development Framework Architecture: A Practical Guide to Building Pluggable AI Agents

    1. From Single-Turn Chat to Persistent Tasks: Why a New Development Paradigm Is Needed

    Over the past two years, the dominant form of large language model (LLM) applications has been “one question, one answer”: the user submits a prompt, the model returns a result, and the task ends when the session closes. This works well for content generation and knowledge Q&A, but its weaknesses surface quickly in real engineering environments: tasks cannot be paused and resumed, intermediate artifacts cannot be reused, external systems cannot be integrated reliably, and the execution process is not observable.

    The industry is converging on a basic consensus: LLM applications are moving from single-turn conversations to persistent tasks, and from prompt engineering to software engineering. Software engineering here implies at least four things:

    1. Persistable state: task progress, context, and intermediate results must be written to storage rather than living only in an in-memory session object.
    2. Pluggable capabilities: the model is only the inference engine; the actual work is done by external capabilities such as file I/O, command execution, retrieval, testing, and deployment, and these must be replaceable.
    3. Orchestratable workflows: complex tasks must be decomposed into steps that support conditional branching, retries, rollbacks, and human confirmation.
    4. Observable execution: the input, output, latency, and failure reason of every step must be traceable; otherwise debugging is impossible and cost governance is out of reach.

    Against this backdrop, a class of infrastructure known as an “agent runtime framework” (often called a harness in the industry, meaning a runtime that carries and constrains) is drawing attention. Its job is not to provide a stronger model, but to give the model a controlled, extensible, and reproducible execution environment.

    It is worth noting that high visibility in the open-source community does not equal deep understanding. Documentation, however thorough, usually only explains “what capabilities exist” and “how to start,” while what developers really need to grasp is why the architecture is designed this way, where the extension points are, and how to adopt it safely in their own business. This article addresses exactly those questions.

    2. Core Architecture: What “Everything Is a Plugin” Actually Means

    The most distinctive design trait of these frameworks is that “everything is a plugin.” Underneath, this is typically driven by a kernel framework that emphasizes spacetime composability—a design philosophy traceable to an academic paper on a spacetime-composable programming paradigm. To appreciate its value, you need to free “plugin” from the narrow notion of a “feature extension pack.”

    2.1 Plugins Are Not Just Features, They Are Every Building Block

    In an “everything is a plugin” architecture, the objects that get pluginized include but are not limited to:

    • the model access layer (adapters for different inference services);
    • tool capabilities (filesystem, terminal, browser, database, retrieval services);
    • interaction interfaces (CLI, GUI, conversational UI);
    • session and context management policies;
    • permission and approval policies;
    • logging, metrics, and trace reporting.

    This means the framework kernel stays minimal, responsible only for plugin loading, dependency resolution, lifecycle management, and event passing; all concrete behavior is contributed by plugins. The direct benefit: replacing one layer’s implementation requires no kernel changes and no touching of other plugins.

    2.2 Dependency Injection and Lifecycle Management

    Whether a plugin architecture can be realized hinges on dependency governance. Mature implementations usually provide three mechanisms:

    1. Plugin = metadata(name/version/dependency declaration)
    2. + setup function(receives ctx and config, produces capability object)
    3. + lifecycle hooks(init / ready / shutdown)

    At startup, the kernel reads the configuration, builds a dependency graph, and assembles plugins in topological order; at shutdown, it releases resources in reverse order. This turns “adding a capability” into “adding a declaration plus a setup function” instead of modifying the main trunk code.

    2.3 Spacetime Composability: A Draggable Branch Map

    “Spacetime composability” sounds abstract, but in product terms it is very concrete: the execution of a task can be represented as a map of nodes and branches, and the user can drag out a segment of conversation or an execution state to form an independent branch and continue from there, without rerunning from the beginning. It delivers three practical benefits:

    • Lower exploration cost: the same prior context can spawn multiple solution branches for side-by-side comparison;
    • Error isolation: a failure in one branch does not pollute the main trunk state;
    • Natural human-AI collaboration: human confirmation or edits can be inserted at any node before automated execution resumes.

    2.4 Comparison With a Monolithic Agent

    Dimension Monolithic implementation Plugin-based framework
    Adding a capability Modify the trunk, high regression risk Add a plugin, clear boundaries
    Swapping the model Often requires rewriting call logic Swap the adapter plugin
    Test granularity End-to-end only Per-plugin unit tests plus integration tests
    Team collaboration Frequent conflicts Parallel development along plugin boundaries
    Governance and audit Scattered logs Unified reporting plugin as a single funnel

    3. The Cost Perspective: Why “Running at Scale” Becomes a Key Metric

    Coding agents have a notable trait: a single task often involves dozens of model calls and many tool calls, consuming far more tokens than ordinary Q&A. If the framework cannot optimize scheduling, caching, and context management, the agent will remain stuck at the demo stage.

    Common cost-control techniques in the industry include:

    • Hybrid model routing: split the task into stages such as planning, coding, and verification; use a more capable model for planning and a lightweight model for repetitive rewriting and formatting;
    • Context compression and summarization: apply layered summarization to long histories, keeping only fragments strongly relevant to the current step;
    • Result caching and reuse: cache retrieval results, build artifacts, and test reports by content fingerprint;
    • Parallelism and batching: run mutually independent subtasks concurrently to shorten wall-clock time;
    • Early stopping and budget caps: set call-count and consumption limits per task, degrading or handing off to a human when exceeded.

    In engineering practice, a common combination is to use a container platform to host the runtime, object storage to hold intermediate artifacts, a message queue to decouple tasks, and logging and monitoring services for observability. When running on a cloud platform such as Baidu AI Cloud, you can compose these general categories as needed, avoiding coupling to specific business logic.

    4. Practical Guide: Building a Pluggable Agent From Zero

    Step 1: Define Boundaries and a Capability Inventory

    Before writing code, list the atomic capabilities the task requires and tag each with a risk level:

    1. Capability inventory example
    2. - Read files (low risk)
    3. - Write to workspace (medium risk)
    4. - Run build/tests (medium risk)
    5. - Execute any command (high risk, requires approval)
    6. - Access external net (high risk, requires allowlist)

    Risk classification is the input for designing the permission plugin later. Skipping this step makes unauthorized operations almost inevitable once the agent goes live.

    Step 2: Build a Minimal Kernel and the First Plugins

    Keep the kernel lean and first land four essential plugins: model adapter, tool execution, session state, and log reporting. Verify the pipeline works end to end before expanding.

    1. # Illustrative code: plugin assembly and dependency declaration
    2. from dataclasses import dataclass, field
    3. @dataclass
    4. class Plugin:
    5. name: str
    6. depends_on: list[str] = field(default_factory=list)
    7. setup: object = None # receives ctx and config, returns capability object
    8. on_ready: object = None # ready callback
    9. on_shutdown: object = None # release resources
    10. class Kernel:
    11. def __init__(self):
    12. self._plugins: dict[str, Plugin] = {}
    13. self._instances: dict[str, object] = {}
    14. def register(self, plugin: Plugin):
    15. self._plugins[plugin.name] = plugin
    16. def start(self, ctx, config):
    17. order = self._topo_sort() # topological sort of dependencies
    18. for name in order:
    19. p = self._plugins[name]
    20. cfg = config.get(name, {})
    21. self._instances[name] = p.setup(ctx, cfg) if p.setup else None
    22. if p.on_ready:
    23. p.on_ready(self._instances[name])
    24. return self
    25. def get(self, name):
    26. return self._instances.get(name)
    27. def shutdown(self):
    28. for name in reversed(list(self._instances)):
    29. p = self._plugins[name]
    30. if p.on_shutdown:
    31. p.on_shutdown(self._instances[name])
    32. def _topo_sort(self):
    33. # Implementation omitted: detect cyclic dependencies and raise a clear error
    34. ...

    Step 3: Give Tool Plugins a Unified Contract

    The tool layer is where “arbitrary parameters and unreadable error messages” most often appear. It is advisable to define a consistent input/output structure for all tools:

    1. {
    2. "tool": "run_tests",
    3. "arguments": { "path": "tests/", "timeout": 120 },
    4. "result": { "status": "ok|error", "summary": "...", "artifacts": ["oss://bucket/key"] }
    5. }

    The value of a unified contract: the model calls tools more correctly, the framework can validate, rate-limit, and audit uniformly, and storing artifacts externally makes branch reuse easier.

    Step 4: Orchestration and Branch Management

    Model the task as a directed graph where nodes are steps and edges are state-transition conditions. Three practices matter: first, define a clear completion criterion for each node to avoid “looks done”; second, give failed nodes a limited number of retries and a fallback path; third, allow forking at any node to form comparable candidate solutions.

    Step 5: Permissions, Approval, and Safety Guardrails

    High-risk tools are disabled by default and enabled via configuration with required human confirmation; external access is subject to a domain allowlist; write scope is limited to the working directory; and all high-risk calls are logged with the caller, a parameter summary, and the approval result.

    Step 6: Testing and Launch

    Testing should have three layers: plugin unit tests (contracts and boundaries), orchestration integration tests (branching and rollback), and end-to-end task tests (completion rate and consumption on real tasks). For launch, it is recommended to first run in “suggestion mode,” where the agent only produces plans without performing write operations, observe for several rounds, and then gradually open up permissions.

    5. Common Pitfalls and How to Avoid Them

    1. Treating plugins as piled-up scripts: without contracts and lifecycle management, the plugin count will inevitably spiral out of control. The fix is to define contracts first, then write implementations.
    2. Chasing plugin count instead of task completion rate: the value of a plugin ecosystem depends on end-to-end success rate, so build a metrics system centered on task completion rate, average number of calls, and human intervention rate.
    3. Neglecting context governance: unbounded context growth drives up both cost and error rate, so summarization and trimming strategies must be designed.
    4. Deferring safety guardrails: permissions and approval should be in place before the first high-risk tool is integrated, not patched on before launch.
    5. Doing demos but no regression testing: build a fixed regression set for typical tasks and run it on every plugin change to prevent silent capability degradation.

    6. Conclusion

    The “everything is a plugin” architecture matters not because the concept is novel, but because it turns the agent from a hard-to-maintain giant script into an engineering system that is testable, replaceable, and governable. Combined with a branching execution map and strict cost and permission controls, developers can finally put coding agents into production workflows. For teams looking to enter this space, the recommended sequence is: first define the capability inventory and risk classification, then build a minimal kernel, then fill in contracts, orchestration, guardrails, and metrics, and finally open up the plugin ecosystem gradually. Hosting the runtime on general cloud capabilities such as containers, storage, messaging, and observability lets you focus more on the business plugins themselves—a key step in moving from prompt engineering to software engineering.