Three Engineering Layers of AI Agent System Design
This article breaks down AI agent design into three engineering layers: prompt engineering, context engineering, and runtime framework engineering. It explains why prompt tuning alone plateaus, how each layer answers a distinct question, and what practical practices belong to each one, along with a suggested three-step path for building more reliable agents in your own system.
Three Engineering Layers of AI Agent System Design
1. Why “Being Good at Prompts” Is Not Enough to Build a Useful Agent
When many teams start building an AI coding agent, their first instinct is to polish the prompt: make the role definition more detailed, tighten the output format constraints, and lengthen the list of prohibited behaviors. This works for short-range tasks such as single-turn question answering or text rewriting. But once the task chain grows longer, the number of dependent files and modules increases, and the work requires multiple rounds of tool calls with result verification, the marginal return on prompt tuning drops quickly.
The reason is that prompts only address one layer of the problem: how to express intent. They cannot determine what the model actually sees at a given moment, nor can they guarantee that the model stays on target during a task that may run for tens of minutes. An experience repeatedly confirmed in engineering practice is this: relying on prompt optimization alone, system capability can be pushed to roughly 70%; introducing context engineering raises it to around 80%; only by adding the constraints, verification, and recovery mechanisms of the runtime framework layer can the system reliably reach the 90% range.
These three layers are usually summarized as prompt engineering, context engineering, and runtime framework engineering. They answer three questions respectively: “how to say it,” “what to let the model see,” and “what kind of environment it runs in.” They are not substitutes for one another but a layered system of constraints. Each is discussed below.
2. Layer One: Prompt Engineering — Turning Intent into Executable Rules
The core of prompt engineering is not copywriting skill but translating vague requirements into rules the model can follow reliably. Four reusable practices stand out.
First, make the role and goal explicit. Define the agent’s identity, the boundaries of its available capabilities, and the form of the final deliverable, so the model does not waver between “answering a question” and “modifying code.”
Second, fix the workflow. Break a complex task into a fixed sequence of stages — for example, locate the relevant code first, then propose a plan, then apply the changes, and finally run verification. When the process is written down clearly, the model will not skip steps.
Third, formalize the output contract. Give explicit constraints on structure, fields, naming, and comment style, and use a sample structure when necessary:
Output format requirements:1) List of changed files: path + reason for the change2) Key code snippets: only the necessary context3) Verification method: executable check commands and expected results4) Open questions: information that needs user confirmation
Fourth, define failure paths in advance. Specify behaviors such as “ask first when information is insufficient” and “roll back and explain when verification fails,” reducing the model’s improvisation in abnormal states.
It is important to be clear-eyed about the ceiling of prompts. They cannot compensate for missing context, nor can they correct a conclusion that looks reasonable but is actually wrong when no external verification exists.
3. Layer Two: Context Engineering — Deciding What the Model Should See Right Now
Context engineering concerns the selection, organization, compression, and updating of information, and it is the key to the success or failure of long-range tasks.
Information selection. A large codebase far exceeds the capacity of the context window, so retrieval and dependency analysis are required to inject only the fragments strongly relevant to the current subtask. Selection signals can come from call relationships, reference relationships, change history, and test coverage.
Information compression. Turn retrieved raw material into structured summaries — for example, compress lengthy logs into “symptom — scope of impact — suspicious locations,” and compress long files into interface signatures and key constraints. This significantly reduces noise interference.
Information layering. Put stable project conventions in a high-priority region, dynamic task state in a separate region, and rolling summaries of the conversation history, so that they do not contaminate one another.
Information updating. In long tasks, early conclusions may already be invalid. Context needs to be versioned, clearly marking which items are current facts and which have been overturned, to prevent the model from reusing outdated assumptions.
A practical rule of thumb: whenever a task clearly goes off track, first check whether the context is missing information, contains noise, or is outdated, rather than continuing to lengthen the prompt.
4. Layer Three: Runtime Framework Engineering — Trading Environmental Constraints for Reliability
Runtime framework engineering refers to the scheduling, tools, verification, and recovery mechanisms on which the agent depends. It is the main source of pushing capability from 80% to above 90%.
Tools and permissions. Tool interfaces should be narrow and explicit, with reads separated from writes, and high-risk operations should require explicit confirmation, so that mistakes do not escalate into irreversible losses.
Verification loops. Modification tasks must have objective verification built in — compilation, static checks, unit tests, or rule validation — using external facts instead of the model’s self-assessment.
State and recovery. Persist task state, completed steps, and pending items so that after an interruption the work can resume from the breakpoint instead of rerunning from the beginning.
Observability. Record a summary of the input, the tool calls, and the verification results for each step, making it easier to locate the problematic stage and perform replay analysis.
A sketch of the main loop looks like this:
while not done:context = build_context(task, memory, retrieved)action = model.decide(context, tools)result = run_tool(action)if verify(result):memory.commit(action, result)else:memory.record_failure(result)context = rebuild_context(task, memory)
5. Implementation Recommendations
To reproduce this path in your own system, proceed in three steps: first, fix the workflow and output contract in the prompt; then build retrieval, summarization, and state management capabilities to control the signal-to-noise ratio of the context; finally, complete tool permissions, automatic verification, and breakpoint recovery. If deployment spans multiple environments, general cloud capabilities such as container platforms, object storage, log services, and monitoring and alerting can carry the state persistence and observability requirements.
The relationship among the three layers can be summarized as follows: prompts determine the starting point, context determines stability, and the runtime framework determines the ceiling. Understanding them separately and investing in each is the viable path to building a highly reliable agent system.
