Three-Dimensional Design Philosophy for AI Agent Systems: Prompt, Context, and Harness Engineering
This article breaks down agent system design into three engineering dimensions: prompt engineering, context engineering, and harness engineering. It explains how dynamic prompt assembly, layered context budgeting, memory management, modular skills, hooks, sandboxes, and guardrails work together to move large language models from single-turn chat to autonomous, tool-using assistants. Each section includes practical structures, pseudocode examples, and governance recommendations, followed by an end-to-end task walkthrough, deployment advice, and common anti-patterns to avoid.
1. Introduction: The Shift from “Chatting” to “Getting Work Done”
By 2026, a class of systems often described as general-purpose autonomous agents had moved quickly out of research labs and into public view. Communities were flooded with guides on installing, configuring, and tuning them, along with jokes about paying to install a system and then paying again to remove it. Behind the noise sits a question that engineering teams should answer calmly: what did these systems actually get right, and how did they carry large language models from single-turn question answering to assistants that stay resident over long periods, plan on their own, call tools, and operate personal devices?
From an evolution standpoint, this is not a brand-new species. It is a systematic integration and refinement of several capabilities that matured across the agent field in recent years: dynamic prompt assembly, context compression and retrieval, layered memory management, modular skill reuse with progressive disclosure, extensible hook mechanisms, guardrails designed around high-risk actions, and the extension of permission boundaries from cloud APIs to local devices. As with most inflection points in technology, quantitative accumulation eventually produces a qualitative leap. Once these capabilities are integrated coherently, the system’s apparent intelligence and task coverage far exceed the linear sum of the individual techniques.
This article abstracts a product-agnostic methodology along three dimensions: prompt engineering → context engineering → harness engineering, and offers concrete engineering recommendations. The relationship can be summarized as follows: prompts decide how to say it, context decides what the model gets to see, and the harness decides the runtime environment in which the model is driven. Each layer builds on the previous one, and together they determine reliability and controllability on complex tasks.
2. Dimension One: Prompt Engineering — From Static Templates to Dynamic Assembly
2.1 The Core Tension: Stable Instructions vs. Diverse Scenarios
Early prompt engineering centered on writing one good system prompt, with precise wording, a clear role, and an explicit output format. In real business settings, however, a single static template cannot simultaneously cover shifting user intent, varying tool sets, and changing permission states. The emerging engineering consensus is that a prompt should not be a fixed block of text but an assembled result driven by runtime state.
2.2 The Basic Structure of Dynamic Assembly
A reusable prompt skeleton typically contains the following layers, ordered from highest to lowest priority and stability:
- Identity and boundary layer: defines the agent’s role, capability scope, and refusal policy; stable and short.
- Task and planning layer: injects the current goal, subtask decomposition, and completion criteria.
- Tool contract layer: injects only the signatures, parameter constraints, and failure semantics of tools available for this step.
- Skill index layer: provides skill names with a one-line description each, rather than the full text of every skill.
- Output specification layer: structured output format, examples, and validation rules.
A schematic structure (pseudocode):
system_prompt = render(identity = POLICY.identity, # stable layergoal = state.current_goal, # dynamic layerplan = planner.partial_plan(), # dynamic layertools = tool_registry.signatures(), # filtered by permissionskills = skill_index.one_liners(), # index onlyoutput = schema.contract() # validation contract)
2.3 Key Practices
- Minimal necessary injection: expose only the tools and skills needed for the current step, which lowers misselection rates and prevents prompt bloat.
- Explicit failure semantics: state in the prompt whether a failed tool call should be retried, routed around, or escalated, instead of leaving the model to improvise.
- Observability: record the version and diff of every assembly so that behavior drift caused by prompt changes can be traced in regression.
- Contract validation: validate output against a schema before it reaches downstream consumers; on failure, retry with the error message attached rather than executing it directly.
3. Dimension Two: Context Engineering — Showing the Model the Right Things Within a Limited Window
3.1 From “Filling the Window” to “Budget Management”
The context window is a scarce resource. Packing in the entire conversation history, every document, and all tool descriptions at once creates three problems: rising cost, diluted attention, and key information being drowned out. The essence of context engineering is making information trade-offs under a budget constraint.
3.2 Context Layers and Compression
In practice, context is usually divided into four layers, each with a different strategy:
| Layer | Content | Typical Strategy |
|---|---|---|
| Working | Inputs and outputs of the current step | Retain in full |
| Session | Recent multi-turn interaction | Sliding window plus summarization |
| Knowledge | Documents, code, retrieval results | Retrieve on demand, chunked |
| Memory | Long-term preferences and facts | Structured storage, selective recall |
Compression techniques include recursive summarization (rolling summaries of older conversation), structured extraction (turning process information into key-value facts), and keeping verbatim citations alongside summaries (retaining traceable IDs of original snippets).
3.3 Engineering Essentials of Memory Management
Memory should distinguish factual items (user preferences, environment configuration) from procedural items (intermediate task conclusions). Factual memory should be stored in structured form with confidence and recency metadata; procedural memory should be archived when the task ends. Recall should rank by a combined score of relevance, recency, and confidence, so that stale information does not contaminate decisions.
recall(query):candidates = vector_search(query) ∪ keyword_search(query)ranked = sort(candidates, key = w1*relevance + w2*recency + w3*confidence)return top_k(ranked) # with source and last-updated time
4. Dimension Three: Harness Engineering — Confining Capabilities Within Controllable Fences
4.1 Why a Harness Is Needed
When an agent moves from generating text to executing actions, and especially once it gains permission to operate local devices, the risk model changes fundamentally: a single misjudgment can delete files, send messages, or modify configuration. Harness engineering concerns the runtime environment itself: lifecycle, hooks, sandboxes, permissions, and auditing.
4.2 Key Components
- Skill modularization and progressive disclosure: skills register as independent units; the index is provided first, and the body plus dependencies load only after a match, balancing extensibility against context cost.
- Hook mechanism: insert validation, rewriting, and logging logic before an action, after an action, and on error, achieving cross-cutting control decoupled from business logic.
- Sandboxing and least privilege: file, network, and device access are granted at task granularity and revoked when the task ends.
- Guardrails and circuit breakers: high-risk actions require confirmation, rate limiting, rollback, and a path to human takeover.
- End-to-end auditing: record prompt versions, context snapshots, tool calls, and results to support replay and accountability.
Schematic hook and guardrail logic:
@before_actiondef guard(action, ctx):if action.risk_level == "high" and not ctx.approved:raise RequireConfirmation(action.summary())if action.tool not in ctx.granted_tools:raise PermissionDenied(action.tool)audit.log(ctx.trace_id, action) # log first, then execute@after_actiondef verify(result, ctx):if not schema.validate(result):raise RetryWithFeedback(result.error)
4.3 Governing Expanded Permission Boundaries
Once capabilities extend to personal devices, the governance question shifts from “did the model answer correctly” to “should this action be taken at all”. A recommended authorization model is deny by default, request on demand, valid for a single use, with mandatory second confirmation and rollback design for irreversible actions.
5. How the Three Dimensions Work Together: Lifecycle of an End-to-End Task
Take “organize a local project and produce a weekly report” as an example:
- The harness starts a task sandbox, grants read-only scanning plus restricted write permission, and registers hooks.
- The prompt dynamically assembles identity, goal, available tool contracts, and the output schema.
- The context loads the project structure and a summary of recent commits, while historical preferences are recalled from the memory layer.
- The agent decomposes subtasks and calls tools step by step; hooks validate paths and risk before every write.
- Process information is compressed into structured facts, and long output is written to disk in sections.
- When the task ends, permissions are revoked, the audit trail is retained, and factual memory is updated with user preferences.
6. Deployment Recommendations and Common Anti-Patterns
Recommendations
- Make output contracts and validation solid before pursuing autonomy.
- Manage the context budget explicitly, with per-layer quotas and eviction policies.
- Keep skills and tools small and clear, using an index to control the exposed surface.
- Route all high-risk actions through confirmation and rollback paths.
- Establish versioned regression mechanisms for prompts and context.
Anti-patterns
- Dumping every document into the context at once, which dilutes attention.
- Letting the number of tools grow without restraint, which degrades selection accuracy.
- Recording only the final answer without process snapshots, making problems impossible to replay.
- Leaving permissions resident instead of revoking them, which keeps expanding the risk surface.
7. Conclusion
Prompts, context, and the harness are not three isolated tricks but a complete chain that runs from expressing intent, to managing information, to constraining execution. Understanding the layering logic of this chain and how the layers cooperate has more long-term value than chasing any single trend. In engineering practice on cloud platforms such as Baidu AI Cloud, combining this methodology with general-purpose capabilities like container platforms, logging services, and monitoring and alerting can produce agent systems that are both intelligent and controllable, allowing capabilities to land safely in real business environments.
