From Token to Harness: A Deep Dive into AI Agent Core Architecture

    Building a functional AI Agent goes far beyond making a single LLM API call. It requires a comprehensive engineering pipeline spanning context management, capability encapsulation, knowledge retrieval, tool protocols, development methodologies, and runtime frameworks. This article breaks down six core elements—Token, Skill, RAG, MCP, SDD, and Harness—detailing the problems they solve, how they collaborate, and common pitfalls and countermeasures in practice.

    From Token to Harness: A Deep Dive into AI Agent Core Architecture

    Building a truly capable AI Agent is much more than calling a Large Language Model (LLM) API. It is a comprehensive engineering chain spanning context management, capability encapsulation, knowledge retrieval, tool protocols, development methodologies, and runtime frameworks. This article connects these six key elements into a single main thread, breaking down what problems they solve, how they collaborate, and common pitfalls and countermeasures in practice.

    1. Token: The Agent’s Workbench, Not a Warehouse

    When discussing Agents, Token is often oversimplified as a billing unit. While not incorrect, this perspective offers little help for engineering practice. A more fundamental view is: Token is the “workbench” for the model’s current inference.

    Everything the model can reference when generating a response must be laid out on this workbench: system instructions, conversation history, tool call results, code snippets, error logs, and retrieved documents. The model knows nothing about information not placed there—it cannot simply “browse the hard drive.” This leads to several direct engineering conclusions:

    1. Context is a scarce resource. No matter how large the window, the usable capacity is always limited. Long contexts often bring increased latency and cost, and can even suffer from attention decay where “middle content is ignored.”
    2. What to put in matters more than how much. Injecting relevant paragraphs is better than dumping an entire document; keeping task goals and key decisions is better than stuffing in months-old chit-chat.
    3. The workbench needs regular cleaning. Historical messages should be compressed, summarized, and evicted. Overly long tool returns should be truncated or summarized before entering the context.

    A basic discipline in practice is to plan the format and budget for each type of content entering the context, for example:

    1. Context Budget Schematic (Conceptual)
    2. - System instructions and safety rules: Fixed, ~5%
    3. - Task specs and current goals: Persistent, ~10%
    4. - Tool definitions: Injected on demand, ~10%
    5. - Retrieved materials: Sourced, truncated, deduplicated, ~40%
    6. - Recent dialogue and tool results: Rolling window + summary, ~35%

    Designing Tokens as a workbench gives RAG, Skill, and MCP a unified assembly goal: they are essentially answering “what to put on this workbench and how.”

    2. Skill: Encapsulating Capabilities into Callable Units

    Skills are the Agent’s “hands.” The model itself only generates text; to make it query databases, write files, or call internal systems, specific capabilities must be encapsulated into units the model can understand and trigger.

    A well-designed Skill typically includes:

    • Name and Description: The only basis for the model to judge “when to use it.” The description must clearly state applicable scenarios, boundaries, and prerequisites.
    • Input/Output Schema: Structured parameter definitions. The clearer they are, the lower the chance of the model filling in wrong parameters.
    • Execution Body: The code, function, or flow that actually executes the logic.
    • Error Semantics: Returns information that the model can understand and recover from upon failure, rather than a meaningless stack trace.

    A common pitfall in Skill design is improper granularity. Too coarse (one Skill doing ten things) makes it difficult for the model to pass parameters correctly; too fine (dozens of highly similar Skills) turns selection into a disaster. A rule of thumb is: use a “verb + object” unit that the model can understand at a glance, such as “Query order status,” “Create ticket,” or “Search knowledge base entry.”

    Another key point is that Skill descriptions themselves consume Tokens. Instead of listing 50 Skills, it is better to dynamically inject the 5 relevant ones based on the task phase—bringing us back to the workbench scheduling problem.

    3. RAG: Grounding Agent Knowledge in Facts

    Knowledge within LLM parameters has a cutoff date and lacks enterprise private domain information. RAG (Retrieval-Augmented Generation) retrieves from an external knowledge base before inference, placing relevant materials into the context so answers are evidence-based.

    A complete RAG pipeline includes:

    1. Knowledge Ingestion: Document parsing, chunking, and metadata tagging.
    2. Vectorization and Indexing: Converting text chunks into vectors and storing them, usually combined with keyword indexing for hybrid retrieval.
    3. Retrieval and Reranking: First recalling candidates, then reranking by relevance to take the Top-K.
    4. Injection and Generation: Splicing sourced materials into the context, requiring the model to cite sources and explicitly state when it cannot confirm an answer.

    In an Agent scenario, RAG operates in two modes: as a fixed pre-step (retrieving before every query), or as a model-initiated Skill (retrieving only when the model decides it’s necessary). The latter aligns better with the Agent’s autonomy but requires the retrieval Skill’s description to be clear enough; otherwise, the model might fail to query when it should.

    The core challenge of RAG implementation is often not “whether it can recall,” but knowledge chunk boundaries, metadata filtering, multi-recall fusion, and answer traceability. It is recommended to retain source identifiers for retrieval results and specifically measure “whether the answer is supported by retrieved materials” in the evaluation set.

    4. MCP: Connecting Tool Ecosystems via Unified Protocols

    When the number of Skills increases and sources diversify, writing integration logic separately for each tool quickly spirals out of control. The value of open protocols like MCP (Model Context Protocol) lies in: defining a standardized description, discovery, and invocation specification between “model” and “tool.”

    MCP can be understood as a “universal socket” for the tool layer:

    • Server: Exposes capabilities like database queries, file operations, and internal APIs according to the protocol, declaring a capability list.
    • Client: The Agent runtime discovers these capabilities and translates them into model-understandable tool definitions.
    • Invocation Specification: Unified request/response formats, error structures, and session management.

    This brings a direct benefit of decoupling: tool developers don’t need to care about the specific model, and Agent developers don’t need to customize integration for each tool. Enterprise internal system capabilities, once encapsulated according to the protocol, can be reused by different Agents.

    Engineering-wise, note three points: First, capability lists also consume context and should support on-demand loading. Second, permissions and auditing should be unified at the protocol layer to avoid each tool doing its own thing. Third, tool execution results should be uniformly structured to facilitate model consumption and log tracing.

    5. SDD: Taming Uncertainty with Spec-Driven Development

    Agent systems behave probabilistically; “tweaking a prompt and running a successful demo” does not equal controllability. SDD (Spec-Driven Development) advocates: first write requirements into machine-readable specs, then let the Agent implement and verify against the spec.

    Its workflow usually involves:

    1. Writing Specs: Using structured text to describe goals, functional boundaries, interface contracts, and acceptance criteria.
    2. Agent Planning: The model decomposes tasks based on the spec and generates an implementation plan.
    3. Implementation and Self-Check: The Agent writes code and tests, with test cases directly corresponding to acceptance criteria.
    4. Review and Iteration: Humans review discrepancies; if specs change, acceptance criteria are updated synchronously.

    The essence of SDD is to extract “intent” from conversation and solidify it into a version-controllable, reviewable, and regression-testable asset. It brings three benefits: requirements and implementation alignment is verifiable; the Agent’s degrees of freedom are constrained by acceptance criteria; changes can explicitly track “whether the spec or the implementation was modified.” For Agent-assisted development, clearer specs mean less chance of the model going off track.

    6. Harness: The Agent’s Runtime Framework

    If Token is the workbench, Skill is the hands, RAG is the reference library, MCP is the socket, and SDD is the methodology, then Harness is the machine chassis that makes everything run collaboratively. It is responsible for orchestrating and governing the entire inference loop, with typical duties including:

    • Loop Control: Managing the multi-step loop of “think -> call tool -> observe result -> continue thinking,” setting max steps and timeouts.
    • Context Management: Executing history compression, tool result truncation, and information assembly to keep the workbench clean.
    • Tool Scheduling: Loading Skill/MCP tool definitions, routing calls, and handling concurrency and retries.
    • Security and Permissions: Confirming high-risk operations, sandbox isolation, and least privilege control.
    • Observability: Logging inputs/outputs, Token consumption, and tool latency for each step to form a replayable trace.
    • Evaluation and Regression: Accumulating evaluation sets for regression testing on prompts, retrieval strategies, and tool changes.

    A conceptual run loop looks like this:

    1. def agent_loop(task, max_steps=20):
    2. context = build_context(system_prompt(), task)
    3. for step in range(max_steps):
    4. action = model.decide(context, available_tools())
    5. if action.is_final_answer:
    6. return action.answer
    7. result = harness.execute(action) # Sandbox, audit, rate limiting
    8. context = compress(context, action, result)
    9. return fallback_response(context)

    The quality of the Harness determines whether an Agent can move from “demo” to “production.” Without loop limits and budget controls, a single derailed inference could burn vast amounts of Tokens; without structured traces, troubleshooting “why it called this tool” becomes impossible.

    7. Integrating the Six Elements into a Unified Architecture

    These six concepts are not parallel nouns but a layered, collaborative whole:

    • Token Layer: Defines information boundaries—what the model can see.
    • Skill Layer: Defines capability boundaries—what the model can do.
    • RAG Layer: Defines knowledge boundaries—what the model bases its answers on.
    • MCP Layer: Defines connection methods—how capabilities are standardized and integrated.
    • SDD Layer: Defines development methods—how the system is reliably built.
    • Harness Layer: Defines runtime methods—how everything lands in a controlled loop.

    The recommended order for designing an Agent is: first clarify task goals and acceptance criteria (SDD thinking), then sort out required knowledge and tools (RAG and Skill), integrate via unified protocols (MCP), and finally let the runtime (Harness) assemble and schedule on the limited Token workbench. A weakness in any layer will amplify problems in others: no matter how many tools exist, improper context assembly leads to incorrect selection; no matter how good retrieval is, a lack of runtime governance leads to loss of control.

    Conclusion

    The best way to understand an Agent is to view it as a combination of context engineering and capability engineering: Token determines the model’s vision, Skill determines its hands, RAG supplements its memory, MCP unifies tool interfaces, SDD constrains development uncertainty, and Harness makes everything run in a safe, observable loop. Grasping this main thread allows for targeted action, whether evaluating technical solutions or building your own Agent systems.