Context engineering: what reaches the model?
Context engineering selects what the model sees.
What you will learn
- Explain: context is the workbench
- Apply the idea in an example: Context engineering: what reaches the model?
- Recognize limitations and verify the exercise outcome
Context engineering selects what the model sees. The goal is relevance, not filling the context window.
You can follow this course without an account or programming. Examples use synthetic data and AI outcomes need checking.
How it works, step by step
Context is the workbench
Context includes instructions, the current request, relevant history, retrieved documents and tool results. The context window has limited capacity; reserve room for the response too. More text does not automatically improve accuracy. Irrelevant information and contradictions can hide important evidence. Summarize history carefully and preserve the origin of facts. State describes the current run, a checkpoint saves a resumable point, and persistent memory retains information across runs. These are different mechanisms managed by the application.
RAG accesses evidence, it does not retrain
RAG means retrieval-augmented generation: retrieval supplies relevant passages before the model answers. Ingestion prepares documents, while query execution searches the index and builds context. An embedding model represents text numerically; the response model writes the answer. Rerankers, vision, graph and router models have different roles when needed. RAG helps with private or changing information but does not guarantee truth. Use an authorized API for balances, exact inventory or permissions; an old document is not a reliable source for current state.
Check access before use
Permissions must be enforced by servers and the data layer. Do not let the model decide whether a user may see a document. Filter sources before they enter context, not after generating the answer. Use minimal-access credentials, keep them out of prompts, screenshots and browser code, and rotate exposed keys. A widget domain allowlist does not replace API authentication. Authentication identifies you; authorization determines the operations and data you can use. Test denied access too.
The visual map
Follow the solid arrows for the main flow. Dashed blue arrows supply data or context; dashed pink arrows show feedback or returning results. Colors and shapes distinguish models, stores, decisions and outputs. On smaller screens, scroll horizontally to follow the entire diagram.
A complete example
For a return question, keep the current policy and product, not ten pages of color discussion. If two policies conflict, mark versions rather than mixing them.
Try it yourself
- Reduce ten paragraphs of context to what the question requires.
- Record the input, source and expected outcome before running the experiment. Use only the fictional data in the example.
- Follow the diagram stages. At every step record what information is received and produced; do not confuse intermediate output with the final outcome.
- Repeat after removing necessary information or making the input ambiguous. Check whether the system clarifies, stops or invents an answer.
- Compare with the explained solution. Keep the configuration, date, result and an explanation for differences. Change one thing and retest.
An explained solution
The model receives instruction, question and relevant evidence with source and version retained. A successful exercise lets you show the connection between input, stages and outcome. When information is missing, a cautious answer is more useful than invented details. Compare more than style: check conditions, sources and operations too.
When it helps and what can go wrong
Summarization can lose conditions; check what was removed. Choose this approach when it improves a measured need. Keep a simple baseline and compare outcomes using identical inputs. One successful example does not establish reliability in every situation.
Check your understanding
Is a checkpoint permanent user memory?
No. Saving a run does not imply retaining preferences across conversations.
Does RAG change LLM parameters?
No. It supplies request-time context; parameter changes belong to training.
What outcome should this exercise produce?
The model receives instruction, question and relevant evidence with source and version retained.
Words to remember
- Checkpoint: Saved state used to resume an execution.
- Retrieval: Finding relevant information in accessible sources.
- Autorizare / Authorization: Checking the right to access an operation or resource.
Sources and your next step
- LangGraph — Workflows and agents
- Lewis et al. — Retrieval-Augmented Generation
- OWASP — Prompt injection
To prepare: P01 — Prompt engineering without magic formulas