An LLM generates responses using the information available in its context window and what it learned during training. It doesn't automatically remember previous requests, access your database, or know who the user is. Your application has to provide that information with each request.
This makes the context window the main interface between your application and the model. Every request requires a decision about what to include: system instructions, tool definitions, conversation history, retrieved documents, and relevant memories from earlier sessions. Too little context can leave the model without the information it needs. Too much increases cost and latency, and can make useful information harder to find.
Context engineering is the work of selecting, organizing, and managing this information so the model can produce useful responses, even as conversations grow longer and agents run for hours.
In this chapter, we'll look at how to budget the context window, structure prompts for caching, manage long conversations, build long-term memory, and keep agents within their context limits.