Context engineering, clearly explained:
Everybody is talking about context engineering, but no one tells you what it actually means. Today, I'll explain everything you need to know about context engineering in a step-by-step manner. Let's go! 🚀
So, what is context engineering? It’s the art and science of delivering the right information, in the right format, at the right time, to your LLM. Here's a quote by Andrej Karpathy on context engineering...👇
To understand context engineering, it's essential to first understand the meaning of context. Agents today have evolved into much more than just chatbots. The graphic below summarizes the 6 types of contexts an agent needs to function properly. Check this out 👇
By now, you should know that it's not enough to simply "prompt" the agents. You must engineer the input (context). Think of it this way: 🧠 LLM = CPU 💾 Context Window = RAM You're essentially programming the "RAM" with the perfect instructions for your AI. continued...👇
So how do we do it? Context engineering can be broken down into 4 fundamental stages: - Writing Context - Selecting Context - Compressing Context - Isolating Context Let's understand each, one-by-one...👇
1️⃣ Writing context: Writing context means saving it outside the context window to help an agent perform a task. You can do so by writing it to: - Long-term memory (persists across sessions) - Short-term memory (persists within session) - A state object Check this👇
2️⃣ Read context: Reading context means pulling it into the context window to help an agent perform a task. Now this context can be pulled from: - A tool - Memory - Knowledge base (docs, vector DB) Check this👇
3️⃣ Compressing context Compressing context means keeping only the tokens needed for a task. The retrieved context may contain duplicate or redundant information (multi-turn tool calls), leading to extra tokens & increased cost. Context summarization helps here. Check this👇
4️⃣ Isolating context Isolating context involves splitting it up to help an agent perform a task. Some popular ways to do so are: - Using multiple agents (or sub-agents), each with its own context - Using a sandbox environment for code storage and execution - And using a state object Check this👇
119