Agent Architecture in Practice: How the Model and Harness Components Work Together
An AI agent needs both cognitive ability and the ability to act on the outside world. This article breaks an agent into two parts: the Model, which handles reasoning and understanding, and the Harness, which provides external capabilities such as web search, data access, and memory. It covers the configuration essentials of each module, with ready-to-adapt examples of prompts, routing logic, data schemas, and a launch checklist. All numeric values and thresholds are starting points and should be tuned against your own production data.
An agent needs both cognitive ability and external action capability. This article splits an agent into two parts: the Model, which handles reasoning and understanding, and the Harness, which provides external capabilities such as retrieval, data access, and memory. The following sections explain the configuration essentials of each module and provide examples you can adapt directly. All numeric values and thresholds in this article are starting points and should be tuned with your own business data.
1. The Model Layer: Integrating Multimodal Capabilities
An agent typically needs the following model capabilities:
- Text generation: understanding instructions, decomposing tasks, and generating responses.
- Vision understanding: reading images such as screenshots, charts, and receipts.
- Image or video generation: used on demand, only integrated when the business requires it.
- Embeddings: converting text into vectors for memory recall and semantic search. Embeddings belong to retrieval, not generation, so configure them as a separate item.
Each model provider requires its own API key. Recommended practices:
- Follow the principle of least privilege: only grant access to the models and endpoints the current module needs.
- Store keys in environment variables or a secrets management service. Never commit them to a code repository or print them to logs.
- Set rate limits for each model (such as requests per minute and tokens per minute) and configure cost alerts.
- Prepare a fallback route. When the primary model times out or is rate-limited, switch to a backup model and log the failover event for later analysis.
Regarding unified billing: if multiple vendors’ capabilities are accessed through a single platform, billing and budget management may be simpler. However, whether unified quotas are supported, how they are deducted, and how cross-vendor pricing works depend on the specific platform and contract terms. Before launch, verify the actual rules in the contract and console, and calculate unit price and usage for each modality separately.
2. Harness Component: Web Retrieval
A large model’s training data has a cutoff date. Questions about recent policies, prices, or news require real-time retrieval. A workable retrieval pipeline includes the following steps:
Step 1: Decide whether retrieval is needed. Trigger retrieval when time-sensitive words like “recently,” “this year,” or “latest” appear, or when the question involves specific dates, prices, or policies. Otherwise, let the model answer directly.
Step 2: Query rewriting. Use the model to rewrite the user’s question into 2 to 3 search queries, preserving entity names, time ranges, and metric names. A prompt template you can use:
Rewrite the user's question into search-engine-friendly queries.Requirements: keep entity names, time ranges, and metric names;each query must be no more than 15 words;output a JSON array only, with no other content.User question: {question}
Before and after example:
- Original question: “What has changed in the latest EV subsidy policy?”
- Rewritten:
["EV subsidy policy 2026 adjustment", "EV subsidy policy notice site:gov.example"]
Step 3: Domain and time restrictions. In scenarios such as finance or healthcare, restrict search domains to authoritative sources like regulators and official disclosure sites. Time filters should match the use case — for example, the past 7 days for news and the past year for policy documents. The exact parameter names depend on the search service you choose; refer to its documentation.
Step 4: Source verification. Every retrieval result must retain its URL, source name, and publication time. When the model generates an answer, every factual statement must correspond to a source. Content without a source should be labeled “unverified” rather than presented as fact.
Step 5: Timeout, retry, and degradation. Set a 3–5 second timeout per request, retry at most 2 times with exponential backoff. If all attempts fail, the answer should state “real-time information is temporarily unavailable” and provide only the confirmed parts — never fabricate results.
Retrieval quality can be measured with these metrics:
- Recall: whether the ground-truth source appears in the top results.
- Precision: manual sampling to check whether cited content matches the question.
- End-to-end latency: time from question to answer.
- Citation reachability: whether links in the answer open correctly.
Prepare at least 100 annotated test questions, establish a baseline first, then compare configurations.
3. Harness Component: Vertical Data Routing
General search works for common-knowledge questions, but financial reports, business registration records, legal risk data, and vehicle specifications require structured professional databases. The routing component’s job is to decide which data source a question should go to.
Intent classification. Start with rule-based coarse filtering (entity patterns such as ticker symbols, model names, or company registration codes), then use a small or large model to output a classification from a fixed label set. The label set should cover your business scope, for example: finance, business registration, legal, academic, automotive, macroeconomic, other.
Confidence threshold. When classification confidence falls below the threshold, do not force routing — fall back to general retrieval. Choose the threshold from a validation set; 0.7 is a reasonable starting value.
Pseudo-code for the routing logic:
def route(query: str) -> dict:intent, confidence = classify(query) # returns label and confidenceif intent in DATA_SOURCES and confidence >= ROUTE_THRESHOLD:try:result = DATA_SOURCES[intent].query(params=parse_params(query),timeout=5,)if result.is_empty():# the database has this category but no matching result; fall back to general retrievalreturn fallback_search(query)return result.to_standard_format()except (TimeoutError, RateLimitError):return fallback_search(query)return fallback_search(query)
Unified response schema. Field structures vary widely across data sources, so standardize the output format before integration. Recommended fields:
{"source": "data source name","entity": "company or vehicle name","metric": "metric name, e.g. ROE","period": "reporting period, e.g. 2023-12-31","value": 0.152,"unit": "ratio","retrieved_at": "2026-11-24T10:00:00+08:00","url": "original data page"}
Data licensing. Licensing terms differ across data sources. Before integration, confirm the following: whether commercial use is allowed, whether caching is permitted, how long cached data may be retained, and whether attribution is required in answers.
4. Harness Component: Cross-Session Long-Term Memory
An agent without memory starts every conversation from scratch. Long-term memory lets the agent remember user preferences and confirmed decisions, but it also introduces privacy, bloat, and conflict problems.
Write policy. After a session ends, the model extracts candidate facts from the conversation. Only write stable preferences (such as output format and preferred units) and explicit decision conclusions; small talk and one-off information should not be stored. Each record should contain at least: content, type, source session ID, write timestamp, and confidence.
Sanitization before writing. Phone numbers, ID numbers, and bank card numbers should be replaced or removed using regex rules. Sensitive fields that cannot be identified by rules should not be stored at all.
Expiration and deletion. Preference-type memories can have a default TTL, such as 180 days, after which they are automatically purged. When a user requests deletion, remove the record from both the vector store and any backups, and confirm deletion has completed.
Recall. Perform semantic search on the question and take the top-k results; k = 3 to 5 is a common starting value. Discard results below the similarity threshold (e.g., 0.6) to prevent irrelevant memories from contaminating the answer.
Context budget. Cap the share of context that memory occupies — for example, no more than 10% of the total window. When exceeded, truncate from least to most relevant.
Conflict handling. When a new fact contradicts an old memory, keep the new record and mark the old one as expired, rather than keeping both. If the content was explicitly stated by the user, the user’s latest statement takes precedence.
Memory write and recall can be rolled out in two phases: enable read-only recall first, observe that it works reliably, then enable automatic writes.
5. Orchestration
The goal of orchestration is to let the model invoke components on demand and integrate results into one verifiable answer. A typical flow:
- The model receives the task and outputs an execution plan describing which tools to call.
- Tools execute according to their dependencies; independent calls can run in parallel.
- Each step’s result is written into context along with its source information.
- Before generating the final answer, check that every factual statement has a corresponding source.
- Log the tool calls, latency, cost, and error codes for the task.
A curated component catalog can reduce selection time, but it cannot replace validation. Compatibility, latency, cost, and permissions all need to be tested in your own business scenario. The most common problem area is the interface contract: if components’ input and output fields are inconsistent, the orchestration layer will fail frequently. Write interface contract tests for each tool to confirm field names, types, and null-value handling.
6. FAQ and Troubleshooting
How to choose a web retrieval component? Focus on four aspects: whether domain restriction and time filtering are supported, whether results include URL and publication time, whether pricing and call quotas fit your budget, and whether data storage and cross-border transfer meet compliance requirements.
How to integrate the memory system? Connect read-only recall first, then writes. Before enabling writes, validate extraction quality in test sessions — confirm there are no incorrect or missing entries and no sensitive information leakage — before opening it to real users.
Common mistakes:
- The model restates retrieval results without checking publication time, citing outdated information.
- Routing sends almost every question to the database; the database returns empty results and users get blank answers. Fix: set a confidence threshold and configure fallback for empty results.
- The memory store only grows and never shrinks; recall slows down and outdated information leaks into answers. Fix: set expiration and conflict-handling rules.
- The model fabricates an answer after a tool call fails. Fix: explicitly require in the prompt that when information cannot be obtained, the reason must be stated.
7. Launch Checklist
- Model: least-privilege keys configured for each modality; rate limits and cost alerts active; fallback routes tested.
- Retrieval: domain whitelist, time filters, source fields, and timeout/retry policies verified.
- Routing: classification accuracy meets validation-set targets; empty-result fallback tested.
- Memory: sanitization rules, TTL, deletion flow, top-k, and context budget configured.
- Orchestration: tool interface contract tests passing; per-task cost and latency limits in place.
- Monitoring: input summary, output summary, latency, and error code logged for every tool call.
The key to agent engineering is clearly defining each component’s boundaries, failure modes, and validation methods. Choosing the right components is not enough — each one must be tested in real scenarios before it can ship reliably.
