With the fast-paced, evolving nature of AI, new terms and techniques appear all the time. One of the latest discussions is around context engineering. If you are not sure what context engineering is, why it's important, or what techniques you can use to optimize the context your agentic systems use, read on to find out.
What is context engineering?
Context engineering refers to a collection of practices that can be combined to provide the right information to Large Language Models (or LLMs) to help them accomplish the desired task. It comprises of 5 key elements:
- System prompt: also known as Instructions, these are the main instructions outlining the type of tasks to perform along with guardrails and expected results.
- User prompt: the instructions provided by the user outlining their desired result.
- Retrieval Augmented Generation (RAG): a known pattern to add relevant documents to the LLM context to ground the model.
- Memory: messages captured from the current and prior sessions that are persisted to storage, known as short and long-term memory respectively.
- Tools: defined functions that the LLM can invoke to perform relevant actions such as retrieve data and perform key operations.
- Structured Outputs: the use of defined data schemes to inform the LLM of the structured of generated outputs.
Why do LLMs need context engineering?
It's important to ensure that the LLMs we use in agents and MCP tools have the right information sources to ensure they provide accurate results, and don't hallucinate or fail to give the desired answer. My high school maths teacher always talked about the notion of "rubbish in, rubbish out" in terms of the inputs we provided to our calculations and proofs.