System Prompt Engineering for Production Coding Agents
Organize system prompts in five layers to keep coding agents coherent across sessions.

A coding agent hits a function that could be refactored two defensible ways, or a test fails for a reason that admits more than one explanation. If the system prompt that governs the agent describes tasks rather than defining a role, the agent has no footing from which to choose. It either invents a preference on the spot or stalls entirely. That failure has nothing to do with the underlying model's capability. It traces back to a design choice: whether the system prompt tells the agent what to do, or tells it who it is, what constraints bound its behavior, and how to resolve ambiguity when the task description runs out. Everything that follows in this piece treats the system prompt as that kind of artifact rather than as a paragraph of instructions to be polished.
The five-layer anatomy of a production system prompt
Every major production coding agent, whatever its branding, converges on the same five-layer structure inside its system prompt: identity framing, behavioral rules, tool descriptions, context management, and multi-turn coherence. Each layer does work the others cannot substitute for, and collapsing them into a single undifferentiated block of instructions is where most prompt failures originate. Identity framing establishes who the agent is within the project, the scope of authority it holds, and the stance it takes when it meets ambiguity. That layer is what turns a general-purpose model into a role-scoped agent rather than a text completer following loose suggestions. Behavioral rules add deterministic constraints on output format, safety boundaries, escalation triggers, and refusal conditions, which together make the agent's behavior auditable rather than improvised. Tool descriptions function as structured signals about when a tool should be invoked, in what sequence, and under what conditions, not simply as documentation of an API surface. Agents built on weak tool descriptions overuse capabilities they should reserve or misroute requests to the wrong tool entirely. Context management governs what the agent loads, summarizes, or discards as a task runs long, and it connects directly to the deeper constraint the next section takes up: that every session begins with no memory of the ones before it. Multi-turn coherence closes the structure, holding the agent's goal steady across many tool calls and model turns so that accumulating context doesn't pull it away from the task it was given. The Galster et al. study that audited these systems identified eight distinct configuration mechanisms, ranging from static context files to executable integrations and external services, bound together by two mechanisms that cut across the rest: an interface layer and a session substrate shared by several subsystems.
Session statelessness is the root constraint that system prompt architecture must solve
A single structural fact forces the entire discipline into existence: the agent carries no memory of any session before the current one, so every piece of persistent knowledge it needs has to be injected deliberately, every time, at runtime. It is a constraint to design around continuously, not a configuration task completed once and left alone. One documented engineering response to this problem built a three-component context infrastructure during construction of a 108,000-line C# distributed system: a hot-memory constitution encoding conventions, retrieval hooks, and orchestration protocols; 19 specialized domain-expert agents; and a cold-memory knowledge base of 34 on-demand specification documents. The hot and cold distinction matters because context window space is a shared, finite resource. Content loaded by default at every session start competes with everything else the agent needs to reason about, while content held in reserve and retrieved only on demand costs nothing until the moment it's actually relevant. The skill this architecture depends on has its own name in the literature: context fluency, the capacity to externalize domain expertise and tacit project knowledge into structured documents before an agent starts working, rather than correcting its misunderstandings after the fact. The payoff is not cosmetic. Agents that operate without sufficient upfront context produce code that then requires extensive debugging and rework; the actual bottleneck in agentic coding sits in the alignment between developer intent and agent output rather than in the raw mechanics of code generation.
Manifest files are the entry point, but they do not scale beyond a modest codebase on their own
Galster et al. found AGENTS.md emerging as an interoperable standard across tools: GitHub Copilot, Cursor, and Codex all recognize it natively, Claude Code reads it as a fallback when no CLAUDE.md file is present, and Gemini CLI requires explicit configuration before it will read one at all. The same study found measurable value in using one well: among projects that adopted manifests, the presence of AGENTS.md files correlated with a meaningful reduction in median runtime and in output token consumption, a signal that well-formed context files cut down on wasted computation rather than merely organizing instructions more neatly. A recent product change reinforces the convergence around the format: Claude Code 2.1.277, released September 18, 2026, added AGENTS.md as a fallback when no CLAUDE.md exists in a folder, which reduces the burden of maintaining duplicate configuration files across different agent harnesses. None of that changes the format's honest ceiling. Vasilopoulos's study of the 108,000-line system notes that single-file manifests do not scale beyond a modest codebase: a small prototype can be served adequately by one manifest, but a large distributed system cannot. The gap between what teams could be using and what they actually use compounds the problem. Galster et al. found that few repositories adopt advanced mechanisms such as Skills and Subagents beyond basic context files, and that Skills, where they do appear, rely predominantly on static instructions rather than executable scripts: most teams are operating with only a fraction of the configuration surface available to them.
The three-layer context architecture that extends manifests into a durable harness
The answer to a manifest's ceiling is a tiered architecture, not a longer manifest. It is a tiered architecture that separates what the agent must always carry from what it can retrieve only when a task calls for it, and that delegates domain-specific judgment to agents scoped narrowly enough to carry it well. The documented production case built exactly this pattern in three tiers. At the top sits a hot-memory constitution, loaded at the start of every session, encoding conventions, retrieval hooks, and orchestration protocols, functioning as the agent's standing identity and its behavioral rules in one place. Below that sit 19 specialized domain-expert subagents, each carrying project-specific knowledge scoped to a bounded domain rather than asking a single general agent to hold the entire system in its head at once. That decomposition is a knowledge-management decision as much as it is a division of labor: an agent that carries only the context relevant to its domain makes fewer mistakes outside that domain and spends fewer tokens on context it will never use. The third tier is a cold-memory knowledge base of 34 on-demand specification documents, available for retrieval the moment a task needs them but never loaded by default, which preserves context window capacity for whatever the current task actually requires. All three tiers rest on an architectural principle: documentation is infrastructure that agents depend on structurally, not reference material written for human readers who happen to skim it occasionally. The mise en place methodology operationalizes the preparation side of that principle through three stages: contextual grounding, where domain expertise gets externalized into structured documents; collaborative specification, where human and agent dialogue produces concrete design artifacts; and task decomposition, where those specifications convert into dependency-aware work records agents can act on directly. A hackathon case study puts a number on what that preparation buys: roughly two hours of this kind of upfront work enabled rapid, parallel implementation of a full-stack educational platform by concurrent AI agents, a demonstration that time spent on context before coding starts reduces the correction work that would otherwise happen in the middle of the task.
Tool descriptions inside the system prompt require the same architectural discipline as context management
Tool descriptions embedded in a system prompt function as behavioral contracts, not documentation, and treating them as documentation is a primary source of agent error in production. Every tool's name, description, and schema gets stamped into the prompt on every single request. The failure mode is concrete: tool definitions consume context window space outright, the results tools return can run long and crowd out project context the agent actually needs, and an overpowered tool can turn what should have been a small, contained request into a large incident. The direction mature MCP usage is moving in reflects that governance concern: away from connecting every available tool to the model, and toward loading tools only on demand, enforcing least privilege on what each tool can touch, auditing every call, and making rollback possible when something goes wrong. The real infrastructure value sits in that governance layer rather than in how many servers a team manages to connect. The protocol landscape itself is consolidating in a way that will shape how tool descriptions get written going forward: MCP, introduced by Anthropic in 2024, is converging as the standard for agent-to-tool communication, while A2A, introduced by Google in 2025, is converging as the standard for agent-to-agent communication, with both now under the Agentic AI Foundation at the Linux Foundation. Tool description conventions inside system prompts will need to track that convergence rather than develop in isolation. Practically, this means tool descriptions belong in the system prompt with the same rigor as the context management layer: they should specify the conditions under which a tool gets invoked, any constraints on the order calls happen in, and how failures get handled, not just the function signature the agent could pattern-match from prior examples. Because tool descriptions, the content tools return, and any third-party data flowing through them can all become channels for injection, writing them well is a security discipline as much as a usability one.
Prompt caching restructures the system prompt as a cost engineering artifact
The order in which layers appear inside a system prompt is a cost and latency decision. It is a cost and latency decision, because prompt caching depends on static content appearing before variable content in the request. The caching principle itself is simple to state: system instructions, few-shot examples, and tool definitions, all static across calls, need to appear first, while user messages and query-specific data, which vary every time, need to appear last, so that the static prefix can be cached and reused rather than reprocessed from scratch. The 2026 roadmap source puts a number on what that reordering buys: structuring prompts to take advantage of caching can cut costs substantially and reduce latency by as much as 85 percent, which reframes system prompt architecture as a cost-engineering problem and not merely a quality one. The three-tier context architecture from the production case maps onto this cleanly: the hot-memory constitution, static and loaded at every session, belongs at the top of the prompt where the cacheable prefix lives, while task-specific context, which varies by request, belongs at the bottom. Teams whose prompts grew organically rather than by design tend to mix static and variable content throughout the prompt rather than separating them cleanly, and that mixing forfeits the caching benefit entirely, regardless of how well-written the individual instructions are. A system prompt that is already well-layered turns out to be cache-friendly by construction; one that was never layered with this discipline in mind reveals its architectural debt directly in its cost bill. That same fact motivates treating the prompt as something versioned rather than something edited freely: every change to the static prefix invalidates the cache built around it, so uncontrolled edits carry measurable cost consequences in addition to whatever behavioral consequences they carry.
Treating the system prompt as a versioned artifact changes how teams detect and fix harness degradation
Once caching makes the cost of uncontrolled edits visible, the natural next step is to manage the system prompt the way engineering teams manage any other piece of infrastructure that other systems depend on: as a versioned artifact with a known history, maintained deliberately rather than edited in place whenever someone notices a problem. A change to the hot-memory constitution, a revision to a tool description, or an added behavioral rule is a change to the runtime the agent operates inside, and it needs to be tracked with the same discipline applied to a change in application code, because it can degrade agent performance in ways that are easy to miss until cost or output quality already shows the damage. A system prompt built on the five-layer anatomy, grounded in a tiered context architecture, disciplined about tool descriptions, and structured for caching remains a living artifact after it's deployed. It is infrastructure that needs the same version history, the same audit trail, and the same ongoing attention that the rest of a production system already receives.


