Context windows and prompts

A model sees only what's in its context window, rebuilt by your app on every call. Watch a prompt get assembled, counted and trimmed, and see a key fact fall out.

9 min Free

A model has no memory between calls. Each request starts from nothing. What it can use is the context window: all the tokens you send in one request. Google’s docs compare it to short-term memory.

In a chat app, the prompt the model really sees is usually several parts joined together:

  • System instruction: your fixed rules (“You are a trip planner. Keep answers short.”).
  • Conversation history: earlier messages, sent again every time.
  • Extra context: documents, search results or tool results you add.
  • The new message from the user.

Many Gemini models have context windows of 1 million tokens or more. Google’s docs give examples of what that holds: about 50,000 lines of code, 8 average-length English novels, or transcripts of over 200 podcast episodes. That’s a lot, but it isn’t free: you pay for every token on every call, and bigger prompts take longer.

Press Play to watch a short chat. Then switch Try it to Long chat: oldest turns dropped, and finally to keep a summary of key facts.

  1. Build prompt
  2. Count tokens
  3. Trim
  4. Generate
  5. Save
Travellerchat userYour appbuilds the promptInstructionssystem instructionChat historyevery past turnToken budgetcount_tokensGeminisees only the prompt

Press Play to watch it run, or step through with ← →.

00/09

What the model sees

Nothing sent yet. Press Play.

What to notice

  1. The model only knows what’s in the window. No hidden memory, no other chats. If a fact isn’t in the prompt (and wasn’t in its training data), the model can’t use it.
  2. “Memory” is your app re-sending history. The bot seems to remember because your code stores each turn and sends it again. See Training an LLM: chatting never changes the model itself.
  3. What falls out is your choice. Dropping the oldest turns is simple but loses important facts. Summarising old turns, or storing key facts separately, keeps them in far fewer tokens.
  4. Output counts too. The reply is generated into the same request. On Gemini 4 models, the 1M-token window is shared by input, thinking and output tokens. Earlier Gemini 3 and 2.5 models have separate input and output limits.
  5. A big window isn’t perfect recall. Google’s docs report that models find a single fact in a long context very well, but accuracy drops when you need many separate facts from it at once.

Reusing a long context
If many requests share the same large context, such as one long manual, look at context caching. Google’s docs call it the main optimisation for long-context work: you pay less for cached input tokens than for sending them fresh each time.

Check your understanding

1. A user said “I'm vegetarian” at the start of a long chat. Your app keeps only the last 20 turns. What happens?
2. Your model supports 1 million tokens. Why might you still keep prompts much smaller?
3. Which is the best way to keep important facts from a very long conversation?