Three-Dimensional Design Philosophy for AI Agents: Prompt, Context, and Harness Engineering Explained
This article breaks down agent system design into three layered engineering dimensions: prompt engineering, context engineering, and runtime harness engineering. It explains how to turn prompts into versioned behavioral contracts, how to manage layered memory and compression within a limited context window, and how to enforce lifecycle, tool governance, least privilege, and observability at the framework level. Readers will find practical patterns, code examples, common anti-patterns, and a review checklist for building reliable and controllable agents in production.
1. The Engineering Problem Behind the Hype: From Chatting to Acting
Over the past year, autonomous agents have moved quickly from demos into production. After the competition at the model layer, the industry has moved on to competition at the agent framework layer. Behind the noisy product launches and community discussions, the durable takeaway for developers is a reusable engineering methodology: how to keep a large language model reliable and controllable in real tasks that involve long workflows, multiple tools, and strict constraints.
These capabilities did not appear out of nowhere. They are a systematic integration of key components from several years of agent research: dynamic assembly of prompts, context compression, layered memory, modular and progressively disclosed skills, hook-based extensibility, guardrails with least privilege, tool-call orchestration, and “computer use” capabilities that push permission boundaries down to personal devices and local environments. When these components are combined in a single runtime, the change is qualitative rather than merely quantitative, and the system begins to exhibit autonomy closer to that of a personal assistant.
From an engineering perspective, the problem splits into three progressive dimensions:
- Prompt engineering: how to say it, meaning the expression, constraints, and structure of instructions.
- Context engineering: what the model gets to see, meaning the selection, compression, and retrieval of information.
- Harness engineering: what environment it runs in, meaning lifecycle, tools, permissions, state, and observability.
These three do not replace one another; they stack. Optimizing prompts alone leads quickly to context bloat and tool misuse in long tasks. Piling on context alone introduces noise and uncontrolled cost. A framework without prompt and context design produces unpredictable behavior.
2. Dimension One: Turning Prompt Engineering into an Engineering Discipline
Prompt engineering is often misunderstood as writing a longer incantation. In a production-grade agent, it is closer to a versionable behavioral contract.
Layered structure. Split the prompt into four layers: identity and goals (a stable role and success criteria), operating rules (when to plan, when to ask, when to stop), tool contracts (each tool’s applicable scenarios, preconditions, and failure handling), and output specifications (structured fields, citations, and how to express uncertainty). The benefit is that each layer changes at a different rate and can evolve and be rolled out independently.
Dynamic assembly. The system prompt should not be a static long document; the runtime should assemble it based on task type, available tools, and permission level. Example:
def build_system_prompt(task, tools, policy):base = load_template("agent_base")tool_spec = render_tools(tools) # expose only currently available toolsguard = render_policy(policy) # permissions and prohibitionsreturn f"{base}\n{tool_spec}\n{guard}\nTask type: {task.type}"
Decidable constraints. Replace “try to” and “be careful” with verifiable conditions, for example “confirm the path is inside the workspace before writing a file” or “retry no more than twice and state the reason for each failure.” Only decidable constraints can be enforced by the framework instead of relying on the model’s self-discipline.
Versioning and evaluation. Put prompts under version control and run regression against a fixed evaluation set. Every change should answer three questions: did task success rate improve, did the average number of steps drop, and did privilege violations and hallucinations increase?
3. Dimension Two: Context Engineering, or Spending a Limited Window Where It Counts
Context is a scarce resource. The core tension is between information completeness and window size, cost, and attention dilution.
Layered memory. Four layers are recommended: working memory (the current task and the last few steps), episodic memory (summaries of past trajectories), semantic memory (user preferences and domain knowledge), and external memory (vector retrieval or a structured database). Writes need a policy; reads need relevance ranking and time decay.
Compression and summarization. For long trajectories, use “segmented summarization plus retention of key fragments”: keep decision points, tool arguments, and the key points of returns, and drop verbose intermediate output. Example:
def compress(trace, keep_last=3, max_tokens=2000):head = summarize(trace[:-keep_last], max_tokens=max_tokens)tail = trace[-keep_last:]return head + tail
Retrieve instead of stuffing. Large objects returned by tools should not enter the window in full. Write them to external storage first, put only a summary and an addressable reference into the context, and fetch the full object on demand.
Prefer structure. Logs, tables, and code should be carried in structured formats, which are cheaper and less prone to misreading than natural-language descriptions. Also define explicitly how uncertain information is marked, to limit the spread of hallucinations.
4. Dimension Three: Harness Engineering, Making Agents Act Controllably
The framework layer decides whether an agent can move from demo to production. The focus areas are lifecycle, tool governance, permissions, and observability.
Lifecycle and state machine. Model the run as “plan, act, observe, revise, terminate,” persist state at every step, and support pause, resume, rollback, and human takeover.
Modular skills with progressive disclosure. Package capabilities as independent skill modules. Expose only the name and purpose first, and load detailed instructions and parameter schemas when the model decides they are needed. This avoids context bloat and choice paralysis caused by injecting everything at once.
Tool-call governance. Provide unified registration, authentication, timeouts, idempotency, and quotas. For high-risk tools such as deletion, transfers, and external publishing, enforce a second confirmation and keep an audit trail.
Guardrails and least privilege. On the input side, detect prompt injection and attempts to induce privilege escalation. On the output side, validate sensitive information and formatting. On the execution side, narrow permissions to the workspace and whitelisted resources, and run in a sandbox or isolated container when necessary.
Observability and evaluation. Collect trajectories, tool calls, token consumption, and failure reasons in one place, and connect them to logging services and monitoring alerts. Use an offline evaluation set plus online sampling for continuous regression.
5. How the Three Dimensions Work Together, and Notes on Cloud Deployment
The three dimensions share one feedback loop: prompts define behavior, context supplies information, and the framework enforces and observes. Failed samples from production flow back into the evaluation set and drive iteration of prompts and retrieval strategies.
For cloud deployment, a closed loop can be built from general-purpose service categories: object storage for trajectories and artifacts, a message queue to decouple long-running tasks, a container platform to host sandboxed execution, logging and monitoring with alerting for observability, and key and permission management to consolidate credentials. Baidu AI Cloud offers standardized cloud infrastructure across these general categories, which lets teams focus on the agent logic itself.
6. Common Anti-Patterns and a Checklist
- Anti-patterns: an overly long static system prompt, full history stuffed into the window, tools exposed without discrimination, no termination condition on failure, and missing logs.
- Checklist: are constraints decidable; does the context have compression and recall strategies; do high-risk tools require a second confirmation; are permissions minimized; does every change come with an evaluation regression.
To turn autonomy into deliverable, operable, and governable productivity, treat an agent as a system constrained by engineering rather than a chattier model, and invest in all three layers at once: prompts, context, and harness.
