Agent Engineering Playbook: The Six-Layer Constraint Chain

    This article explains why AI agents that perform well in demos often fail in production, and introduces a six-layer constraint chain for building reliable agent systems: Token, Skill, RAG, MCP, SDD, and Harness. It covers how to manage context budgets, turn repeated tasks into reusable rules, provide traceable evidence for knowledge gaps, standardize external system access, define specifications before code generation, and close the loop with orchestration and evaluation. Developers can use these layers to move from capability stacking to end-to-end governance and dependable delivery.

    Introduction: Why Demos Look Smart but Delivery Turns Dumb

    The core difficulty in agent engineering is often not switching to a larger model, but building a complete constraint chain on a solid foundation. Many systems look impressive during demos, yet once they enter real business scenarios, they suffer from context loss, unstable repeated tasks, incorrect knowledge citations, uncontrolled external calls, code changes that drift from requirements, and results that cannot be reproduced. These problems are not isolated model capability gaps; they indicate that the system lacks layered constraints.

    Token, Skill, RAG, MCP, SDD, and Harness can be understood as six layers of constraints that move the same system from “able to answer” to “able to deliver.” They are not six parallel terms, but a bottom-up engineering chain: Token determines how much information the agent can currently see; Skill determines the rules for executing repeated tasks; RAG determines where to obtain evidence when knowledge is missing; MCP determines how to access external systems safely and in a standardized way; SDD determines whether there is a clear specification before writing code; Harness determines whether these capabilities can form a stable closed loop.

    1. Token: The Boundary of the Agent’s Vision and Attention Budget

    A token is the unit of information a model can process in a single inference, and it also defines the boundary of the agent’s vision. In engineering, it is not enough to focus only on “how large the context window is”; you must also pay attention to the allocation efficiency of effective tokens. System prompts, tool descriptions, conversation history, retrieved snippets, task state, and output format constraints all compete for the token budget. If all information is stuffed into the context without discrimination, the model will be distracted by noise and key instructions will be diluted.

    A more reasonable approach is to manage tokens as a budget: set separate quotas for the task goal, current state, evidence snippets, tool results, and output format; summarize and compress conversation history; rerank and truncate retrieval results; and use segmented execution with externalized state for long tasks. The logic can be illustrated as follows:

    1. Effective context = task goal + current state + necessary evidence + available tool summary + output constraints

    The goal of the token layer is not to “fill it up,” but to let the model see, within a limited field of vision, the information most relevant to the current decision first.

    2. Skill: Turning Repeated Tasks into Reusable Rules

    Skill addresses the stability of repeated tasks. When an agent faces similar tasks, relying on ad hoc reasoning each time causes output quality to fluctuate. The essence of a Skill is to solidify task steps, decision conditions, tool usage order, exception handling, and acceptance criteria into a reusable capability unit.

    A qualified Skill contains at least four parts: applicable scenarios, execution steps, input and output constraints, and failure fallback strategies. It should not be just a prompt template, but should be close to an “executable work instruction.” For example, a code review Skill can specify: first read the change scope, then check interface compatibility, then verify test coverage, and finally output a risk level and modification suggestions. This changes the agent’s behavior from “improvising” to “working according to a procedure.”

    Skills also need version management. Changes in rules, tools, or business definitions all affect execution results, so Skills should have change records, regression samples, and an owner mechanism to avoid rule drift.

    3. RAG: An Evidence Completion Mechanism for Knowledge Gaps

    RAG determines where the agent obtains evidence when internal knowledge is missing. Its value is not simply “doing a search,” but turning external knowledge into citable and verifiable context. High-quality RAG needs to cover document chunking, index construction, retrieval, reranking, citation annotation, and stale content governance.

    In engineering, evidence traceability should be prioritized. Key conclusions in the model’s answers should map to specific snippets; conflicting evidence should be explicitly flagged; and for low-confidence retrieval, the agent should be allowed to express uncertainty or request additional materials. Retrieval should not rely only on a single similarity measure; it can combine keywords, structured filtering, permission filtering, and business tags.

    The process can be illustrated as follows:

    1. Question rewriting -> multi-route retrieval -> permission filtering -> reranking -> evidence trimming -> generation with citations

    The goal of the RAG layer is to let the agent be “backed by evidence,” rather than letting the model fill gaps based on impression.

    4. MCP: A Standardized Boundary for External System Access

    MCP can be understood as a standardized connection layer between the agent and external systems. It determines how the agent safely and properly calls databases, object storage, message queues, logging services, monitoring and alerting, intelligent coding tools, or business APIs. Without this layer, an agent can easily access production systems through temporary scripts or hard-coded methods, leading to excessive permissions, missing audits, and uncontrolled calls.

    A robust access layer should have least-privilege authorization, a call allowlist, parameter validation, timeout and retry strategies, idempotency control, audit logs, and sensitive information masking. Tool descriptions must also be readable by the model, clearly stating the purpose, input structure, output structure, and failure semantics to avoid misuse by the model.

    1. Agent -> tool gateway -> permission check -> parameter validation -> external system
    2. |-> audit and masking

    The key to MCP is not “how many systems it can connect to,” but “whether each connection is manageable, controllable, and traceable.”

    5. SDD: Specification-Driven Development Before Writing Code

    SDD, or specification-driven development, determines whether the agent has a clear specification before generating or modifying code. Many coding agents fail not because they cannot write code, but because they misunderstand requirements. Without a specification, the model fills in assumptions on its own, causing the scope of changes to get out of control.

    A specification should include the goal, scope, non-goals, interface agreements, data structures, exception handling, acceptance criteria, and rollback plan. For complex tasks, the agent can first output a draft specification, then have a person or an upper-level process confirm it, and finally proceed to implementation. An example structure is as follows:

    1. Goal: fix failures under a certain type of input
    2. Scope: adjust only the parsing layer
    3. Non-goal: do not change the external protocol
    4. Acceptance: all new samples pass and old samples show no regression

    SDD shifts code generation from “guess-based implementation” to “constraint-based delivery,” and also makes subsequent testing, review, and auditing easier.

    6. Harness: Making the Six Layers Form a Stable Closed Loop

    Harness is the runtime and evaluation shell that determines whether the above capabilities can run as a stable closed loop. It includes task scheduling, state management, execution sandboxes, evaluation sets, log tracing, failure retries, human takeover, and continuous regression. Without Harness, Token, Skill, RAG, MCP, and SDD are isolated components; with Harness, they can be orchestrated, measured, and improved in a unified way.

    Harness must answer at least four questions: whether tasks are reproducible; whether failures can be located; whether results can be quantified; and whether risks can be intercepted. In practice, layered evaluation should be established: unit-level checks verify whether tool calls are correct, task-level checks verify whether deliverables meet the specification, and regression-level checks verify whether historical samples degrade. Confirmation points or human approval should be set for high-risk actions.

    Conclusion: From Capability Stacking to Chain Governance

    Agent engineering is not the stacking of isolated capabilities, but chain governance. Token manages vision, Skill solidifies processes, RAG completes evidence, MCP constrains external interactions, SDD clarifies delivery specifications, and Harness ensures closed-loop operation. If any of the six layers is missing, the system will expose weaknesses in real scenarios. For developers, the feasible path from demo to reliable delivery is to first stabilize the chain’s layering, boundaries, and evaluation mechanisms, and then gradually enhance model and tool capabilities.