Context Engineering Cheat Sheet
Nov 20, 2025
Context Engineering In One ๐๐ต๐ฒ๐ฎ๐๐๐ต๐ฒ๐ฒ๐.
Your agent starts strong → performs a few tool calls → suddenly gets confused → outputs garbage.
Sound familiar?
Here's what's really happening: Context poisoning.
As your agent runs longer tasks, its context window fills up with tool feedback, memories, and instructions. Eventually, it drowns in its own data.
Enter: Context Engineering
Andrej Karpathy nailed the definition:
"The delicate art and science of filling the context window with just the right information for the next step."
Think of it like this:
ใ LLM = CPU
ใ Context Window = RAM (limited capacity)
ใ Context Engineering = Managing what fits in that RAM
The 4 Pillars of Context Engineering:
1๏ธโฃ WRITING Context Save information OUTSIDE the context window.
โธ Scratch Pads: Take notes during task execution (like Anthropic's multi-agent researcher saving its plan to memory)
โธ Long-term Memory: Persist learnings across multiple sessions (like ChatGPT's memory feature)
2๏ธโฃ SELECTING Context Pull only relevant information INTO the context window.
โธ Smart Tool Selection: Research shows agents fail after ~100 tools. Solution? Use RAG over tool descriptions to fetch only relevant tools
โธ Memory Types: Facts (semantic), past experiences (episodic), instructions (procedural)
โธ Knowledge Retrieval: Code agents like Cursor use parsing + embeddings + knowledge graphs + LLM-based ranking
3๏ธโฃ COMPRESSING Context Retain only essential tokens.
โธ Summarization: Claude Code auto-compacts at 95% of 200K token limit
โธ Trimming: Remove irrelevant messages using heuristics or learned approaches
4๏ธโฃ ISOLATING Context Split context across multiple spaces.
โธ Multi-Agent Systems: Each sub-agent gets its own context window (Anthropic's researcher processes more total tokens this way)
โธ Sandboxing: Execute code in isolated environments - keep heavy objects (images, audio) away from LLM context
โธ State Objects: Use Pydantic models with separate fields for different context types
Why This Matters:
According to Cognition: "Context engineering is effectively the #1 job of engineers building AI agents."
Without it, you hit:
ใ Context poisoning (conflicting information)
ใ Distraction (too much noise)
ใ Clash (hallucinations influencing outputs)
Real-World Impact:
ใ Semantic code chunking (not random blocks)
ใ Multiple retrieval techniques combined
ใ LLM-based ranking on top
Try to Get this:
what goes IN,
what stays OUT,
and what gets COMPRESSED in your agent's context window.
Master context engineering = Master AI agents.
๐Watch this video from langchain for more Context Engineering.
----------------------------
๐ New to AI Agents? Start with my free training and learn the fundamentals of building production-ready agents with LangGraph, CrewAI, and modern frameworks. ๐ Get Free Training
๐ Ready to Master AI Agents? Join AI Agents Mastery and learn to build enterprise-grade multi-agent systems with 20+ years of real-world AI experience. ๐ Join 5-in-1 AI Agents Mastery
โญโญโญโญโญ (5/5) 1500+ enrolled
๐ฉ๐ป Written by Dr. Maryam Miradi
CEO & Chief AI Scientist
I train STEM professionals to master real-world AI Agents.
