Chapter 2.3 — Prompt engineering and context engineering¶
🎯 Objective¶
Distinguish prompt engineering (formulating instructions) from context engineering (assembling the correct set of information the model will see).
🧠 Mindset shift¶
Prompt engineering: how to ask better?
Context engineering: what deserves to enter the context, in what order,
in what format, with what confidence and with what budget?
🏗️ Context layers¶
- Normative: system instructions, policies, scope.
- Identity and tenant: user, organization, roles, permissions.
- Situational: task, parameters, recent history.
- Operational: available tools, tool results, checkpoints.
- Cognitive: plan, working memory, transient hypotheses.
- Grounding: documents, citations, retrieved facts.
- Output contract: schema, format, success criteria.
🚨 Context anti-patterns¶
- Dumping whole documents into the prompt.
- Mixing instructions with user data.
- Huge tool descriptions.
- Infinite history.
- Memory without consent.
- Context without source IDs.
- Structured output only in the prompt (without a native schema).
🛡️ Prompt caching¶
- Reduces cost and latency when there are stable prefixes.
- Works best with instructions, policies and tool schemas at the start.
- Caution: poorly designed caching can mask a policy or version change. Include the version in the execution metadata.
📚 References¶
- Anthropic — Effective context engineering for AI agents: https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents
- OpenAI — Prompt caching: https://developers.openai.com/api/docs/guides/prompt-caching