The Research Report
The Structured Prompts Movement Has a Reference Site
Most system prompts are written the way early web pages were built: a single blob of text, hand-edited, fragile, impossible to maintain at scale. AgentPatterns.ai is a new reference site that treats system prompt design as an engineering discipline, not a creative writing exercise. It documents the patterns that production teams at Anthropic, OpenAI, and others use to build agents that actually work.
The site covers four interconnected ideas that change how you think about system prompts: dynamic composition, cache-aware layering, heuristic effort scaling, and declarative multi-agent composition. Each one solves a specific problem that teams hit when they move from demo to production.
The Problem with Monolithic Prompts
A single static system prompt works fine for a chatbot. It breaks down fast when you build a real agent. The prompt accumulates sections for identity, code quality rules, safety constraints, interaction guidance, and context awareness. Every conversation pays the token cost for every section, whether it needs them or not.
A leaked 102K-character system prompt from a Claude.ai computer-use session shows what this looks like at production scale. That prompt uses roughly 25 top-level XML sections to separate concerns. It is not a paragraph of instructions. It is a structured document with named sections, explicit boundaries, and deliberate ordering.
AgentPatterns.ai documents the techniques visible in that prompt and backs them up with research from Anthropic's engineering publications and the OpenDev paper (Bui, 2026).
Dynamic System Prompt Composition
The core idea: build system prompts from modular, priority-ordered sections at runtime, not from a single static blob.
Each section carries a numeric priority that determines assembly order. The OpenDev paper identifies five functional tiers:
- 10-30: Core Identity — agent role, capabilities, boundaries
- 40-50: Tool Definitions — tool schemas, capability declarations
- 55-65: Safety and Rules — style rules, safety constraints
- 70-80: Provider-Specific Guidance — provider-optimized instructions
- 85-95: Dynamic Context — session state, memory injection
Only enabled sections make it into the final prompt. Planning mode omits code quality rules. Execution mode omits planning heuristics. A Claude-specific instruction block gets injected only when the active provider is Anthropic, not when it is OpenAI.
Here is what this looks like in practice:
SECTIONS = [
PromptSection(
priority=10,
content="You are an autonomous software engineering agent.",
),
PromptSection(
priority=60,
content="Follow PEP 8. Write type annotations.",
modes=["execution"],
),
PromptSection(
priority=80,
content="<claude_specific>Prefer tool use over free-form reasoning.</claude_specific>",
providers=["anthropic"],
),
PromptSection(
priority=90,
content="Current session state: {session_state}",
),
]
def compose_prompt(mode, provider, session_state):
active = [s for s in SECTIONS if mode in s.modes and provider in s.providers]
active.sort(key=lambda s: s.priority)
return "\n\n".join(s.content for s in active)
The mode-specific sections at priority 60 and 75 are mutually exclusive. The provider block at 80 exists only for Anthropic calls. Cross-provider bloat disappears without branching the calling code.
Why This Matters for Production Teams
Three practical wins:
Token efficiency. Irrelevant instructions no longer consume context. A planning-mode agent does not carry execution-mode rules. A GPT call does not carry Claude-specific guidance.
Testability. Each section can be tested in isolation. A section that works alone may break when combined with another that contradicts its framing. The combinatorial testing surface is smaller than testing a monolith.
Maintainability. Adding a new section requires one entry in the priority list. Reordering or removing sections is a config change, not a rewrite.
When Composition Backfires
AgentPatterns.ai is honest about the tradeoffs. Dynamic composition can defeat the caching goal it was meant to enable. Naive composition — dynamic content sprinkled through the prompt — can increase latency and cost. The site cites Lumer et al. (2026), who found that placing dynamic content at the end and excluding tool results from the cacheable region is essential for long-horizon agent tasks.
Other pitfalls: combination explosion in testing (N sections × M modes), prompt injection through dynamic sections, and cache invalidation from over-modulation. The site recommends reaching for dynamic composition only when the agent operates across genuinely distinct modes or providers, not as a default.
Cache-Aware Prompt Layering
This is where AgentPatterns.ai separates itself from generic prompt engineering advice. Prompt caching is not an optimization you toggle on after the fact. It is a structural constraint that shapes how you compose, extend, and compact agent context from day one.
The economics are stark. Cached reads cost 10% of the base input price on Anthropic's API. Cache writes cost 125-200%. A single cache-busting change wipes out savings across every subsequent call. Manus reports that KV-cache hit rate is "the single most important metric for a production-stage AI agent," noting a 10x price differential on Claude Sonnet.
The Immutable Prefix Pattern
Agent systems that achieve high cache efficiency share a common layout: a stable prefix followed by a growing tail.
[Cached Prefix — stable across turns]
System Prompt → Tool Definitions → Project Instructions
[Dynamic Tail — grows each turn]
Conversation History → Latest User Message
The Bui (2026) paper describes this as "modular prompt composition." Core identity and policies form the stable prefix. Conversation history occupies the dynamic suffix.
Three Cache-Busting Patterns
Prefix caching requires exact byte-level matches. Three patterns consistently bust the cache:
Adding or removing tools mid-session. Tool definitions sit in the prefix. Changing them invalidates everything after. Keep the tool list static across the session.
Switching models. Model-specific instructions sit in the prefix. A model change invalidates the cache for the entire session. Treat model switches as context boundaries.
Mutating the prefix to convey state. Timestamps, config, or metadata in early sections bust the cache on every call. Place variable state in the dynamic tail instead.
OpenAI found a bug in Codex where MCP tools were listed in non-deterministic order. The tool list prefix was never the same twice, causing a cache miss on every call. The fix was straightforward: sort tool definitions by name and keep the order consistent.
The Production Pattern
# Built once per session — stable cache prefix
TOOLS = sorted(load_tools_from_registry(), key=lambda t: t["name"])
SYSTEM = build_system_prompt() # no per-user injection
def call_model(conversation_history, user_message):
return client.messages.create(
model="claude-sonnet-4-20250514",
system=SYSTEM, # identical bytes every call → cache hit
tools=TOOLS, # deterministic order → cache hit
messages=conversation_history + [{"role": "user", "content": user_message}],
)
The system prompt and tool definitions are built once and reused across every turn. Only the conversation history grows. After the first turn, cached reads cover the system prompt and tool definitions.
Monitoring Cache Health
Anthropic's API returns three key metrics: cachecreationinputtokens (tokens written), cachereadinputtokens (tokens served from cache), and inputtokens (uncached). Track cachereadinputtokens / total as a session metric. A healthy session shows near-zero cachecreationinput_tokens after the first turn. A mid-session spike signals a prefix change.
Claude Code's SDK had a bug (fixed in v2.1.72) that caused cache invalidation on every call. When fixed, input token costs dropped by up to 12x. Cache misses are silent. The API charges the full rate without erroring. You have to monitor.
Heuristic Effort Scaling
Fixed instructions like "always use three subagents" waste tokens on simple tasks and under-invest on complex ones. "Be thorough" gives no actionable constraint. Anthropic's multi-agent research system spawned up to 50 subagents for queries that needed one, until they encoded explicit complexity tiers.
The Pattern
Define tiers in the system prompt with concrete resource ceilings:
- Tier 1 — Simple fact-finding — 1 agent, 3-10 tool calls. "What does function X return?"
- Tier 2 — Direct comparison — 2-4 agents, 10-15 calls each. "Compare approach A vs B."
- Tier 3 — Complex research — 10+ agents, parallelized. "Audit the entire auth surface."
The agent reads the query and classifies it before taking any action. A query like "What does validateSession return?" triggers Tier 1. The agent runs a single grep, finds the answer, and stops. A query like "Audit all places that bypass authentication" triggers Tier 3. The lead agent uses extended thinking to decompose the problem by subsystem, then fans out 10+ subagents across the codebase in parallel.
Breadth-First Before Narrowing
Specific query instructions cause agents to issue narrow searches. A breadth-first heuristic outperforms step-by-step specificity because the agent can adapt to what it discovers. Anthropic found that a broad pattern returning 50 filterable results beats a specific pattern returning zero.
Parallelization Gains Compound
Anthropic documented two independent parallelization dimensions: the lead agent spawning 3-5 subagents simultaneously, and each subagent executing 3+ tools in parallel. Combining both reduced complex query time by up to 90%.
The Refinement Loop
Anthropic found that ~20-query test sets were sufficient to detect regressions when refining effort-scaling prompts. Early iterations moved success rates from 30% to 80%. The loop: run the current prompt against a fixed test set, identify tiers where effort was misallocated, adjust thresholds, and re-run.
When Scaling Backfires
Multi-agent architectures use roughly 15x more tokens than single-agent chat. Three conditions make the tradeoff unfavorable:
- High inter-dependency tasks. Most coding tasks need shared state. Parallel subagents produce overlapping results and merge conflicts.
- Cost-sensitive workloads. Routine lookups routed to Tier 3 by a miscalibrated classifier overspend by an order of magnitude.
- Synchronous execution constraints. The lead agent cannot steer subagents after spawning.
Apply effort scaling selectively: research, synthesis, and audit workloads fit well. Implementation tasks with shared mutable state typically do not.
Declarative Multi-Agent Composition
Most multi-agent code tangles agent capabilities, coordination logic, and runtime behavior into a single imperative mess. When a workflow fails, you trace through code to distinguish a misconfigured agent from a wrong handoff or a runtime error.
Declarative composition separates the "what" from the "how." You define agents as structured data — model, tools, memory, prompt — then wire them into workflows through explicit coordination rules rather than imperative code.
The Define-and-Compose Pattern
Research from AutoGen Studio (EMNLP 2024), drawing on 200,000+ installations, identified define-and-compose as the dominant workflow authoring pattern:
agents:
code-reviewer:
model: claude-sonnet-4-20250514
tools: [read_file, git_diff]
prompt: "Review code changes for correctness and style."
max_tokens: 4096
security-scanner:
model: claude-sonnet-4-20250514
tools: [read_file, grep, semgrep_run]
prompt: "Scan changed files for security vulnerabilities."
workflow:
name: pr-review-pipeline
orchestration: sequential
stages:
- agent: code-reviewer
output: { verdict: string, issues: list }
- agent: security-scanner
output: { vulnerabilities: list, severity: string }
final_gate:
approve_if: "all(stage.verdict != 'reject' for stage in stages)"
Adding a fourth agent requires one new block under agents: and one new entry under stages:. No coordination code changes.
Built-In Profiling Changes Debugging
Multi-agent workflows fail in ways single-agent systems do not: coordination failures, context loss at handoffs, cascading errors. Declarative specs enable automatic instrumentation at every agent boundary because the runtime knows the full workflow structure. Imperative code requires manual instrumentation at each handoff point.
Effective multi-agent profiling surfaces token cost per agent, tool invocation frequency, message flow between agents, and per-agent timing. These map directly to the OpenTelemetry GenAI agent span conventions.
The Export-to-Code Path
Visual and declarative tools work for prototyping. Production deployments need code. The pattern that works:
- Prototype in declarative format — fast iteration, visual feedback
- Validate with built-in profiling — catch coordination issues early
- Export to code when the workflow is stable — full control, version-controlled, testable
This avoids the framework-first anti-pattern by starting with explicit specifications rather than opaque abstractions.
When Declarative Breaks Down
Declarative specs work for static workflows with known coordination patterns. They struggle with dynamic agent creation based on runtime conditions, complex conditional routing, and shared mutable state during execution. The practical boundary: use declarative composition for the workflow skeleton, imperative code for runtime adaptation.
Why This Site Matters
AgentPatterns.ai fills a gap. The prompt engineering space has plenty of tutorials telling you to "be specific" and "use examples." It has almost nothing on how production teams actually structure system prompts at scale.
The site's value comes from three things:
Sourced from production. Every pattern references either Anthropic's engineering publications, the leaked Claude system prompt, or peer-reviewed research (Bui 2026, Lumer et al. 2026, AutoGen Studio). No speculation.
Honest about tradeoffs. Each pattern includes a "when this backfires" section. Dynamic composition can bust caches. Effort scaling costs 15x more tokens. Declarative specs struggle with dynamic workflows. The site does not sell patterns as silver bullets.
Cross-referenced. Patterns link to each other. The cache-aware layering pattern connects to the composition pattern, which connects to the effort scaling pattern. You can follow the graph from any entry point.
The structured prompts movement — the idea that system prompts should be engineered documents, not freeform text — has been growing for the past year. AgentPatterns.ai gives it a proper reference. If you are building agents that run in production, this site will save you from learning hard lessons the expensive way.
Citations
- AgentPatterns.ai — Production System Prompt Architecture: https://agentpatterns.ai/instructions/production-system-prompt-architecture/
- AgentPatterns.ai — Dynamic System Prompt Composition: https://agentpatterns.ai/context-engineering/dynamic-system-prompt-composition/
- AgentPatterns.ai — Heuristic-Based Effort Scaling: https://agentpatterns.ai/agent-design/heuristic-effort-scaling/
- AgentPatterns.ai — Declarative Multi-Agent Composition: https://agentpatterns.ai/multi-agent/declarative-multi-agent-composition/
- AgentPatterns.ai — Prompt Caching: Architectural Discipline: https://agentpatterns.ai/context-engineering/prompt-caching-architectural-discipline/
- AgentPatterns.ai — Static Content First Caching: https://agentpatterns.ai/context-engineering/static-content-first-caching/
- Bui (2026) — OpenDev: https://arxiv.org/abs/2603.05344
- CL4R1T4S — Claude Opus 4.6 system prompt capture: https://github.com/elder-plinius/CL4R1T4S/blob/main/ANTHROPIC/ClaudeOpus4.6.txt
- Anthropic — Effective context engineering for AI agents: https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents
- Anthropic — Multi-agent research system: https://www.anthropic.com/engineering/multi-agent-research-system
- Anthropic — Prompt caching: https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
- Anthropic — Advanced tool use: https://www.anthropic.com/engineering/advanced-tool-use
- Lumer et al. (2026) — Don't Break the Cache: https://arxiv.org/abs/2601.06007
- AutoGen Studio research (EMNLP 2024): https://arxiv.org/abs/2408.15247
- OpenAI — Unrolling the Codex Harness: https://openai.com/index/unrolling-the-codex-agent-loop/
- Manus — Context Engineering: https://manus.im/blog/Context-Engineering-for-AI-Agents-Lessons-from-Building-Manus
- OpenTelemetry GenAI agent span conventions: https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-agent-spans/
Suggested Title
The Patterns Behind Production System Prompts (or: Structured Prompts Get a Reference Site)
Word Count
~2,100 words (body text)
Fact-Check Notes
- The leaked 102K-character Claude system prompt is documented by CL4R1T4S. I confirmed the URL and repository exist. The specific claim of ~25 XML sections comes from AgentPatterns.ai's analysis of that prompt.
- The Bui (2026) OpenDev paper is at arxiv.org/abs/2603.05344. I have not independently verified the arxiv ID but it is cited directly by AgentPatterns.ai.
- The Lumer et al. (2026) paper is at arxiv.org/abs/2601.06007. Same sourcing note.
- The AutoGen Studio research claiming EMNLP 2024 and 200K+ installations is at arxiv.org/abs/2408.15247. I have not independently verified the publication venue.
- The "up to 90% reduction" in complex query time and "15x more tokens" claims come from Anthropic's blog post on their multi-agent research system. I have not independently verified these numbers.
- The "10% of base input price" for cached reads and "125-200%" for cache writes come from Anthropic's API documentation.
- The Claude Code SDK bug (v2.1.72) and the "up to 12x" cost reduction claim come from AgentPatterns.ai. I have not independently verified the specific version number or the magnitude of the improvement.
- Manus's quote about KV-cache hit rate being "the single most important metric" comes from AgentPatterns.ai's citation of the Manus blog post. I have not verified the original source directly.