How it works
Context engineering goes beyond the prompt: it involves choosing which documents to include, in what order, with which examples (few-shot) and what constraints. The goal is to maximize response quality within the context window.
It includes techniques like document chunking, result reranking, conversation history compression and dynamic tool selection. Context engineering also decides what to exclude to avoid noise and save tokens.
Practical example
A code agent receives: (1) system prompt with rules, (2) relevant files from the repository, (3) recent conversation history, (4) the current question. Context engineering decides what goes in and what stays out so it does not exceed the token limit.
{
"system": "Você é um assistente de código. Responda em português.",
"context": ["src/main.py", "tests/test_main.py"],
"question": "Corrija o bug de login"
}In RAG systems, context engineering includes: splitting documents into chunks, generating embeddings, retrieving the most similar ones and reranking them before sending to the model.
What it's for
Improve responses without changing the model. With good context, smaller models can outperform larger models with poor context. It is the core skill for anyone building LLM applications.