Context window anatomy

system prompttool schemasmessage historylatest turnheadroom
Context windowTokens used88%full1 turntruncated
  1. One finite token budget; no hidden state outside it.
  2. System prompt and tool schemas form a fixed prefix.
  3. Each turn appends reasoning and tool_result tokens.
  4. At saturation, the oldest turns are truncated: context rot.
Notes & references

Use when

Budgeting tokens across prefix, history and output.

Avoid

Eager schema loading and raw log dumps: context rot precedes the hard limit.

context = [
    system_prompt,      # always there
    *tool_schemas,      # always there
    *conversation,      # grows every turn
]

if count_tokens(context) > LIMIT:
    # drop, shorten or summarise the oldest turns