AI Agent Engineering: A Practical Guide to Building Agents with a Model and an Execution Harness
This guide explains how to build production-ready AI agents by separating the model from the execution harness. It covers using a multimodal model foundation, designing a slot and plugin mechanism, implementing five core component categories (retrieval, data parsing, memory, tools, and iteration), managing quotas through unified budgets, and following a step-by-step rollout with a practical acceptance checklist.
1. Why AI Agents Need a Two-Layer Structure: Model + Execution Harness
In real projects, many teams blame poor agent performance on limited model capabilities. However, the root cause is often on the engineering side: the model only handles “thinking,” while “seeing, searching, remembering, doing, and modifying” all require an external execution harness. The industry is converging on a consensus that an agent’s capabilities can be abstracted as “model + execution harness”: the model is the brain, responsible for understanding, reasoning, and generation; the execution harness acts as the hands, feet, and nervous system, responsible for connecting to the external world, maintaining state, invoking tools, and feeding results back to the model.
This layered approach provides a direct benefit: decoupling. Models can be swapped on demand or used in parallel across different tiers, while the harness’s stability, observability, and permission boundaries can evolve independently. For developers, this shifts the evaluation question from “switching to a stronger model” to “identifying which layer is missing.” If an agent cannot answer real-time questions, retrieval is missing. If it forgets context every time, memory is missing. If it cannot produce deliverables, the tools and artifact layer is missing.
2. The Capability Foundation: Covering Input and Output with a Multimodal Model
An agent’s “brain” should not support text alone. In real business scenarios, inputs may include screenshots, scanned documents, audio, and spreadsheets, while outputs may include images, short videos, structured data, or vector representations. Therefore, the foundation layer typically needs to cover general capability categories such as text generation, image generation, video generation, and vectorization.
For integration, the mainstream approach is to have the execution harness support “custom model providers”: add a provider in the settings interface, enter the service address and key, and then bind different models to different tasks. An illustrative configuration is shown below (this is a structural example only and does not represent any specific API):
providers:- name: primarybase_url: "<your service address>"api_key: "<your key>"models:chat: "<text model identifier>"vision: "<multimodal model identifier>"embedding: "<vector model identifier>"routing:planning: chatperception: visionmemory_index: embedding
From an engineering perspective, three practices are recommended. First, route tasks by type: use long-context models for planning, low-latency models for extraction, and models with stable dimensions for vectorization. Second, set timeouts and retries to prevent single-point jitter from bringing down the entire pipeline. Third, keep model identifiers in configuration rather than code to facilitate canary releases and rollbacks.
3. The Execution Harness Slot Mechanism: Turning Optional Capabilities into Pluggable Components
If all capabilities are hardcoded into the main workflow, the system will quickly degrade. A more mature design provides a slot and plugin mechanism: the main workflow only defines standard interfaces, such as “perform one retrieval,” “write one memory entry,” or “execute one action,” while specific implementations are provided by plugins. This allows teams to replace search sources, switch databases, and adjust memory strategies without modifying the main workflow.
The key to slot design lies in three points. First, minimize interfaces: keep parameter and return structures stable to prevent plugins from reverse-depending on the main workflow’s internal implementation. Second, allow graceful degradation on failure: when a retrieval plugin times out, it should be allowed to return empty results and let the model explicitly state uncertainty, rather than failing the entire request. Third, declare permissions: plugins should declare required permissions (network access, file writing, external actions) upon registration, and the runtime should validate them uniformly to reduce the risk of privilege escalation.
4. Five Categories of General Components: Enabling Agents to Work, Remember, and Grow
After abstracting common requirements, the execution harness components can be roughly categorized into five types. Each solves a specific class of problems, and only when combined do they form a complete loop.
- Retrieval and search: Responsible for acquiring external real-time information. When selecting a solution, focus on result traceability, support for time filtering and site constraints, and the ability to return source snippets for the model to cite. It is recommended to enforce “retrieve before answering” and require answers to include sources to reduce hallucination.
- Data acquisition and parsing: Responsible for converting web pages, documents, spreadsheets, and API responses into processable structures. The focus is on encoding detection, layout restoration, table structuring, and field mapping. Data sources with different levels of trustworthiness should be labeled, and authoritative sources should be prioritized in case of conflicts.
- Memory: Divided into three layers: short-term context, long-term facts, and vector index. Short-term memory stores key points of the current session; long-term memory stores facts in a “subject-attribute-value-time” structure; the vector layer is used for semantic recall. Writes require deduplication and conflict resolution, while reads require sorting by time and confidence.
- Tools and actions: Responsible for actually “doing things,” such as calculations, file read/write, message notifications, and workflow triggers. The principle is that write operations must be auditable and rollback-capable, and high-risk actions should introduce secondary confirmation and human approval.
- Iteration and optimization: Responsible for “growth,” including run trace logging, failure sample collection, and versioned evaluation of prompts and strategies. Without an evaluation loop, an agent will remain in the demo stage and cannot reliably enter production.
Illustrative memory write and recall logic:
def remember(agent_id, subject, attribute, value, confidence=0.9):# If the same subject attribute already exists with higher confidence, keep the old valueold = store.find(agent_id, subject, attribute)if old and old.confidence > confidence:return oldreturn store.upsert(agent_id, subject, attribute, value, confidence)def recall(agent_id, query, top_k=5):hits = vector_index.search(query, top_k=top_k)return sorted(hits, key=lambda h: (h.timestamp, h.confidence), reverse=True)
5. Subscriptions and Budgets: Moving Quota Governance Upstream
When multiple components run in parallel, quota and cost management are often overlooked. A pragmatic approach is to adopt unified subscriptions and a unified quota deduction pool: text, image, video, and vectorization share the same quota pool, avoiding accounting difficulties caused by multiple billing standards. On this basis, teams should establish a budget view, tag by application, environment, and task type, set daily/monthly thresholds and alerts, and add caching and idempotency controls for high-cost actions (such as video generation and large-scale vectorization) so that duplicate requests hit the cache directly.
6. Implementation Steps and Acceptance Checklist
It is recommended to proceed in five steps. Step one: define task boundaries and deliverable forms. Step two: integrate the model foundation and establish the minimal end-to-end pipeline. Step three: inject components one by one according to gaps, starting with retrieval and memory, then tools and iteration. Step four: build an evaluation set covering common questions, edge cases, and adversarial inputs. Step five: roll out gradually, observing success rate, latency, cost per task, and human takeover rate.
For acceptance, refer to the following checklist: Does the answer include verifiable sources? Can key facts be correctly remembered across sessions? Do write operations have audit logs and rollback paths? Can the system degrade gracefully when a model or plugin fails? Can quotas be attributed to specific applications? By following this path, developers do not need to blindly trial-and-error through a massive number of plugins. Using a general and practically tested combination, they can build a stable, scalable, and continuously optimizable agent system.
