โšก Join AI Agents Mastery 7-in-1 ยท Now 60% Off

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.

Build 9 AI Agents Projects

Nov 27, 2025

AI Agent Interpretability

Nov 27, 2025

How to Build Finance AI Agents

Nov 20, 2025