M/Visual Library
  1. Visual Library
  2. Gen AI
  3. Context Engineering: Everything the Model Sees

Gen AI

Context Engineering: Everything the Model Sees

Context engineering is designing all a model sees before it answers: instructions, examples, references, memory, tool results. Why it beats clever prompts.

Also known as: context engineering, what is context engineering, context engineering vs prompt engineering, context window, context management, system prompts, context engineering for images, common ground

From the prompt to the whole window

A prompt is the message you write. Context is everything the model receives with it: the system instructions, the earlier turns of the conversation, attached files and images, retrieved documents, examples, the results of tools it has called, and any memory carried over from before. In mid-2025 developers began calling the work of designing all of that 'context engineering'. Andrej Karpathy described it as the art and science of filling the context window with just the right information for the next step.

The shift came with agents and long conversations. A single clever sentence matters less when the model also reads forty pages of material and twenty earlier messages. Research showed that models use long contexts unevenly: information in the middle of a long input is recalled less reliably than information at the start or end, and performance can drop as more is added. So the job becomes curation: what goes in, in what order, in what form, and what is left out.

Linguists would recognise the problem. Robert Stalnaker and Herbert Clark described conversation as building 'common ground', the shared knowledge that lets a short sentence mean a lot. Context engineering is building common ground with a machine on purpose, because it has none of its own.

What goes into the context

System instructions

The standing brief: role, tone, rules, what to do when unsure. Read before everything else.

Conversation history

Earlier turns. Useful continuity, but also drift: an early mistake keeps getting repeated.

Examples

Worked samples of the output you want. The strongest signal in the window, for better or worse.

Retrieved material

Documents, notes or data pulled in for this task, often by search (retrieval-augmented generation).

Tool results

What a search, a calculation or a file read returned. Raw results can crowd out everything else.

Memory

Facts carried between sessions: preferences, past decisions, a project's state.

Principles

Relevant over complete

More context is not better context. Every extra paragraph competes for attention.

Position matters

Put the brief and the key material where they are read most reliably: near the start and the end.

Structure it

Label sections, separate instructions from material, keep formats consistent.

Compress

Summarise long histories and keep decisions, not every step that led to them.

Isolate

Split big jobs so each step sees only what it needs.

Write down the implicit

Whatever you and your team 'just know' must be written, or the model will fill it with the average.

Context for images

Reference images

A reference carries palette, light and texture more precisely than words; pair it with words that say what to take from it.

Style sheets

A short fixed block of style words reused across every prompt keeps a series consistent.

Character sheets

Describe a recurring character once in exact terms and reuse that block verbatim.

Chat-based image editing

In multi-turn image tools every earlier image and request is context; start a fresh thread when the drift sets in.

Brand kits

Colours, type, do's and don'ts and approved examples, packed once and reused.

What linguistics already knew

Common ground

Meaning depends on what both sides already share (Stalnaker, Clark). A model's common ground is only its window.

Deixis

'This', 'here' and 'the one before' point into context. Name things instead when the context is long.

The words to describe it

Precise words for the qualities above. Combine a few of them instead of naming the style or artist alone.

  • context engineering
  • context window
  • system prompt
  • common ground
  • retrieval-augmented generation
  • few-shot examples
  • memory
  • context rot
  • lost in the middle
  • style sheet
  • character sheet
  • reference image
A description to start from

'Style sheet: soft overcast light, muted sage and clay palette, 50mm lens at eye level, fine film grain. Character: a woman in her sixties with short silver hair, round tortoiseshell glasses and a mustard cardigan. Scene: she is repotting a fern on a cluttered kitchen windowsill.'

How to put it into words

  • Write a short brief: goal, audience, constraints, what to do when unsure.
  • Add only the material this task needs, labelled.
  • Include one or two examples of the output you want.
  • Reuse fixed blocks for style and characters; refresh long threads with a summary.

Where we usually get it wrong

Treating the context window as a bin. Pasting every document, every earlier draft and every reference 'just in case' makes results worse, not safer: the model weighs noise alongside signal and the important line gets lost in the middle. Curate the context the way you would brief a new collaborator: what they need, in the order they need it.

Try this

Pick a series you want to make, four images of one character or one product. Write three fixed blocks: a style sheet (palette, light, lens, texture), a character or product sheet (exact physical description) and a brief (purpose, audience, what to avoid). Generate the four images by changing only the scene line and reusing the blocks word for word. Then try once without the blocks and compare consistency.

Sources and further reading

  • Robert Stalnaker, 'Common Ground', Linguistics and Philosophy (2002).
  • Herbert H. Clark, Using Language (1996).
  • Nelson F. Liu et al., 'Lost in the Middle: How Language Models Use Long Contexts', TACL (2024).
  • Patrick Lewis et al., 'Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks' (2020).
  • Anthropic, 'Effective context engineering for AI agents' (2025).

Keep looking