Agent Execution Framework Principles and a Practical Guide to Plugin Architecture
This article explains what an agent execution framework (agent harness) is and why large language models need one, then breaks down a typical five-layer architecture, the key constraints of a plugin system, and the full workflow for building a plugin from scratch. It also clarifies common configuration concepts around module resolution, sessions, execution capabilities, and memory management, and ends with practical rollout advice and a reference deployment approach on Baidu AI Cloud.
1. Why an Execution Framework Is Necessary
A large language model is essentially a function that takes text in and returns text out. It excels at reasoning, summarization, and generation, but it cannot directly read or write files, execute commands, or guarantee that intermediate state is preserved across a multi-step task. To turn a model from an advisor in a chat window into an executor that delivers results, you need an engineering layer outside the model. The industry commonly calls this an agent execution framework, or agent harness.
This layer takes on at least four responsibilities:
- Tool integration: Abstracting capabilities such as the file system, terminal, network requests, and databases into interfaces the model can call.
- Loop control: Maintaining the observe-decide-act-observe loop and terminating at the right moment.
- State management: Persisting sessions, context, variables, and intermediate artifacts, with support for interruption and recovery.
- Extension mechanism: Allowing third parties to add tools, commands, interfaces, and policies as plugins without modifying the core.
Once you understand these four points, it becomes clear why such frameworks often look less like an application and more like a runtime.
2. Layered Architecture: From Core to Capability Families
A mature execution framework can usually be abstracted into five layers:
- Core layer: Handles the event loop, scheduling, error propagation, and lifecycle.
- Dependency injection and plugin layer: Assembles capabilities in an “everything is a plugin” fashion, leaving the core with minimal semantics.
- Capability family layer: Session management, execution capabilities, orchestration and collaboration, memory management, protocols, and interfaces.
- Model adaptation layer: Hides differences between models in context length and function-calling formats.
- Integration layer: Command line, desktop, or browser interfaces.
The value of this layering is replaceability: swapping models does not require changing plugins, and swapping interfaces does not require changing the core. A practical test for whether a framework is healthy is whether adding a new capability requires modifying core code. If it does, the extension points are not well designed.
3. Key Constraints of Plugin Design
For a plugin system to be genuinely usable, four things must be clearly defined:
- Declaration: How a plugin describes its name, version, dependencies, and exported capabilities.
- Resolution: How the runtime locates and loads plugins from disk or a repository.
- Isolation: A crash in one plugin should not take down the entire session.
- Version compatibility: How semantic versioning constrains the relationship between core and plugins.
A sample plugin descriptor can be written as:
{"name": "file-guard","version": "0.1.0","exports": ["tool:read_file", "tool:write_file"],"requires": { "core": ">=1.0 <2.0" }}
In engineering practice, it is advisable to define a capability allowlist for each plugin, specifying the path scope it can access and the set of commands it may execute, to avoid the risk of default full permissions.
4. Building a Plugin From Scratch: The Complete Path
Using “write your own plugin” as the thread lets you connect scattered knowledge into a single main line.
1. Troubleshooting Editor Errors
When you hit type or module resolution errors, troubleshoot from the outside in:
- Whether dependencies are installed in the correct workspace;
- Whether the module resolution mode matches the package declaration;
- Whether type declaration files can be resolved;
- Whether multiple copies of the same dependency are causing type conflicts.
2. Package Management and Workspaces
In a multi-package repository, standardize on one package manager and lockfile to avoid different tools generating lockfiles that overwrite each other. It is recommended to place plugins in separate subpackages and reference each other through the workspace protocol, so local debugging requires no publishing.
3. Build Artifacts and Release
- Define the main entry, type entry, and runtime entry clearly;
- Keep the build target consistent with the runtime environment;
- Before release, run a clean install, build, and smoke test.
4. Runtime Module Resolution
Runtime resolution and editor resolution follow two different sets of rules. The editor infers from configuration files, while the runtime searches based on the actual directory structure and export fields. A mismatch between the two is the most common cause of “works in the editor but fails at runtime.”
5. Clarifying Configuration Semantics: Concepts That Cause Pitfalls
- Module mode: Determines whether import paths need extensions, and must stay consistent with the package declaration.
- Type references and inclusion scope: Affect which declarations the editor can see, which is not the same as what is visible at runtime.
- Path aliases: Valid only at build time and in the editor; the runtime needs additional mapping.
- Dependency hoisting: Can turn “it runs” into a coincidence, so locking versions is more reliable.
6. Sessions, Execution, and Memory
- Sessions: Store messages, tool calls, and artifact references, with support for recovery and branching.
- Execution capability family: Atomic capabilities such as files, commands, and retrieval, which need unified timeout and rollback semantics.
- Memory management: Distinguish short-term context from long-term knowledge; long-term memory should be searchable, expirable, and auditable.
- Orchestration and collaboration: Multi-agent collaboration must define task boundaries and conflict handling to avoid duplicated work.
7. Rollout Advice and a Baidu AI Cloud Practice
To deploy such a framework in a Baidu AI Cloud environment, you can combine general cloud product categories: use a container platform to host the runtime, object storage to hold build artifacts and session snapshots, a message queue to decouple tasks, and logging and monitoring with alerting for observability. On the model side, you can use the model services offered by the Qianfan large model platform and switch between models of different sizes through a unified adaptation layer to control cost and context strategy.
A suggested pace is to start with read-only tools and a minimal closed loop, then gradually open write permissions; start with a single agent, then move to multi-agent orchestration; and pair every step with a permission allowlist, timeouts, and auditing. Only then does the execution framework truly become maintainable, extensible, and governable engineering infrastructure rather than a demo that is hard to reproduce.
