Agent = Model + Harness: An Engineering Practice Guide

    An agent’s ceiling is set largely by the model, but reliable production work depends on the harness around it. This guide covers design principles, a unified model layer, and harness components for search, domain datasets, memory, tool execution, evaluation, and staged rollout with governance.

    Agent = Model + Harness: An Engineering Practice Guide

    1. Design principles: treat the agent as systems engineering of “model + runtime”

    An agent’s capability ceiling is determined largely by the model, but whether it can do work reliably often depends on the harness outside the model. Here, the harness is not a single tool. It is the full set of runtime capabilities built around the model: context management, tool calling, web retrieval, access to specialized data, memory, permission control, sandboxed execution, logging and observability, evaluation and regression, and budget governance.

    Connecting a large model alone can produce a demo quickly, but it rarely goes straight into production. The reasons are straightforward. Model knowledge has a cutoff and cannot actively verify the latest facts. The model does not inherently know internal enterprise data. It cannot reliably remember user preferences across sessions. Write operations need permissions, audit trails, and idempotency protection. Output quality needs continuous calibration through offline evaluation and online feedback. These problems are not solved by “switching to a larger model” alone. They are the harness’s job.

    A more reasonable engineering principle is to split the agent into a replaceable model layer and a composable harness layer. The model layer connects text, image, video, embedding, and similar capabilities through a unified gateway. The harness layer connects search, datasets, memory, tools, evaluation, and other components through standard interfaces. Component selection should not chase quantity. It should consider whether a component has been validated in real projects, whether its interface is stable, whether it is observable, whether it can degrade, whether permissions are controllable, and whether cost can be metered.

    A practical admission checklist includes:

    • Coverage: it solves a clear problem rather than duplicating an existing capability.
    • Interface stability: it has a clear input/output contract and a versioning policy.
    • Observability: it emits traces, latency, error codes, hit rates, and similar metrics.
    • Replaceability: it is connected through an adapter so business code is not bound to one implementation.
    • Security and permissions: it supports tenant isolation, least privilege, and redaction of sensitive data.
    • Cost control: calls can be tagged by project, session, and task and charged against a shared quota pool.
    • Evaluation readiness: it can enter a regression set and support failure attribution.

    2. Model layer: multimodal access and unified routing

    The model layer should be accessed through a unified model gateway rather than scattered calls in business code. The gateway handles key custody, capability declarations, routing, fallback, quotas, and audit. At runtime, custom providers can be added through a general configuration such as Settings → Models, using a dedicated API key, and capabilities such as text generation, image generation, video generation, and embeddings can be registered as routable capabilities.

    An illustrative configuration:

    1. model_gateway:
    2. providers:
    3. - id: primary
    4. auth: ${MODEL_KEY}
    5. capabilities: [text, image, video, embedding]
    6. routes:
    7. default_text: primary/text-large
    8. fallback_text: primary/text-small
    9. embedding: primary/embed-v1
    10. budget:
    11. tags: [tenant_id, project_id, session_id]
    12. quota_pool: agent_shared_pool

    Routing should consider at least task type, cost, latency, and availability. For example, complex planning can use a stronger text model, while simple classification uses a smaller model. Embedding tasks stay on the embedding route. If the primary model times out or is rate-limited, traffic falls back to a backup model. Every routing decision should be written into the trace so later analysis can explain why a task was costly, slow, or lower quality.

    Budget management should not stop at per-call billing. It should support a shared quota pool and quota policy: tag by tenant, project, and session, and set alert thresholds and hard caps so the agent does not run away in a call loop. Keys must be hosted. They must not be written into prompts or front-end configuration, and logs must not record full keys.

    3. Harness component 1: web search so the agent can verify facts

    Model knowledge has a cutoff date; tasks do not. A web search component should provide four basic capabilities: actively retrieve the latest facts, verify sources, filter by source authority, and filter by time range. For complex queries, it should also support automatic rewriting that turns a colloquial question into searchable keyword combinations.

    Define a stable search interface:

    1. search(query, options) -> results
    2. options:
    3. time_range: last 7 days / 30 days / 1 year / unlimited
    4. source_filter: authoritative / industry / all
    5. top_k: 5~10
    6. results:
    7. title, snippet, published_at, source_id, score

    Search is not finished once full web pages are stuffed into context. Three engineering points matter. First, retrieve before generation, and require the model to cite source_id in the answer so users can verify. Second, treat retrieved content as untrusted data so prompt injection in a page cannot contaminate system instructions. Third, set cache and TTL: hot questions can reuse results, while time-sensitive questions must refresh. Metrics include retrieval hit rate, empty-result rate, citation accuracy, average latency, and source distribution.

    4. Harness component 2: specialized datasets so the agent gets hard data

    General search is good at discovering information, but many tasks need structured, computable vertical data—financial metrics, business registration information, legal risk, academic papers, vehicle configurations, macro indicators, and similar records. These needs should go through a specialized dataset component, not “answer from memory.”

    The key is routing. Maintain a dataset registry and use rules, semantic classification, and a confidence threshold to decide whether a query goes to general search or a vertical store. Illustrative pseudocode:

    1. def route(query):
    2. scores = classify(query)
    3. best = argmax(scores)
    4. if scores[best] < 0.55:
    5. return web_search(query)
    6. return dataset_registry[best].query(query)

    For example, if the agent asks how ROE in an industry changed over the last three years, routing should hit a financial database and return structured ROE data. If it asks for the chassis configuration of a specific vehicle model, it should route to a vehicle-configuration store. Results should include field schema, data time, source version, and confidence so the model does not invent missing fields as facts. Vertical data often involves permissions and compliance, so access control must be enforced by tenant, role, and dataset, and queries must be audited.

    5. Harness component 3: a memory system so the agent remembers across sessions

    A memory system should not be a simple concatenation of chat history. A more reasonable implementation is a context database of “virtual file system + semantic retrieval”: treat memories, resources, and skills uniformly as files, load them in layers, recall them on demand, and automatically consolidate long-term memory after a session ends.

    Memory can be split into three layers. Working memory holds the current task state. Short-term session memory holds the context of the current conversation. Long-term memory holds stable facts, user preferences, project experience, and reusable skills. The write policy should be restrained: write only stable information, deduplicate before writing, and attach confidence, source, TTL, and a permission tag. An illustrative record:

    1. {
    2. "namespace": "tenant/project",
    3. "type": "preference",
    4. "content": "User prefers structured table output",
    5. "confidence": 0.92,
    6. "ttl_days": 180,
    7. "source": "session:xxx",
    8. "permission": "team_read"
    9. }

    For recall, use hybrid retrieval: keyword match, vector recall, time decay, and permission filtering. That finds semantically related content while keeping expired or unauthorized memories out of context. The memory system must also support deletion and audit to meet privacy requirements. In multi-tenant settings, isolation must be strict so projects do not contaminate each other.

    6. Harness component 4: a tool execution environment so the agent can act safely

    Tools are the agent’s “hands and feet,” and they are also a risk entry point. The tool layer should provide registration, schema descriptions, permission checks, sandboxed execution, timeouts, retries, idempotency, and audit. All tools should return structured results. Error messages should be readable and classifiable. Write operations must require a second confirmation or enter an approval flow.

    A typical agent loop:

    1. while not done:
    2. decision = model.decide(context, tools)
    3. if decision.action == "tool":
    4. result = tool_registry.call(
    5. decision.tool,
    6. decision.args,
    7. trace_id=trace_id
    8. )
    9. context.append(observation=result)
    10. else:
    11. return decision.answer

    Generate a trace_id for every tool call and record an argument summary, latency, result status, and retry count. High-risk tools need allowlists, least privilege, and rate limits. Write operations need an idempotency key so network retries do not write twice. Tool descriptions should be maintained like API documentation, because the quality of the model’s tool choice depends heavily on how clear those descriptions are.

    7. Harness component 5: evaluation and evolution so the system keeps improving

    An agent’s “growth” should not be understood as the model automatically getting stronger. It is continuous optimization of the harness through an evaluation loop. Offline evaluation sets should cover tasks, tools, retrieval, and memory. Core metrics include task success rate, citation accuracy, tool-call success rate, average steps, average cost, latency, and hallucination rate. Online, collect user corrections, failure attribution, and human feedback, and periodically feed them back as regression cases.

    What you iterate includes prompts, tool descriptions, routing thresholds, memory write policy, retrieval top_k, and fallback policy. Every change should pass a regression gate and a small-traffic A/B test so a local improvement does not degrade the system overall. Evaluation is not a one-off project. It is infrastructure for agent engineering.

    8. Rollout path and governance

    Build in stages. Stage one: model gateway, web search, and citation verification, forming a minimal loop. Stage two: specialized datasets and tool execution. Stage three: memory and evaluation regression. Stage four: permissions, audit, budget, and cost governance.

    The combination can be summarized as follows. The model gateway handles keys, routing, fallback, and quotas. Search handles source filtering, time filtering, cache, and citations. Datasets handle the registry, routing, schema, and permissions. Memory handles layering, writes, recall, and deletion. The tool layer handles registration, sandboxing, idempotency, and audit. Observability handles traces, metrics, and alerts. Evaluation handles offline sets, regression, and A/B tests. Isolate concrete implementations behind adapters. Version pinning, admission review, replaceability, and graceful degradation prevent a pile of plugins.

    For cost governance, use a shared quota pool, budget alerts, tenant isolation, log redaction, and content-safety policy. On Baidu AI Cloud, object storage can hold evaluation sets and snapshots, a logging service can collect traces, monitoring and alerting can track anomalies, and vector retrieval can support semantic recall and similar general capabilities. The goal is not to connect the most components. It is to form an agent runtime that has been validated, is observable, can evolve, and can do work safely.