Context Management
Working, STM, and LTM all compete for the same tokens. Someone has to allocate.
A flight bag with weight limits — you choose what boards.
Visual Workflows
Start here — scroll inside each diagram frame to explore, then use + / − to zoom up to 200% if needed.
Overview
Scroll inside the frame to explore · use + / − to zoom up to 200%
Scroll inside the frame to explore · use + / − to zoom up to 200%
Pack order
Scroll inside the frame to explore · use + / − to zoom up to 200%
Reserve the user turn first. Fill the rest from the budget.
Key Takeaways
- 1.Context management is the packing plan for one model call. Budget: system, memories, history, tools, user message.
- 2.If the budget breaks, drop in order — never the live user turn. Treat the window as a product constraint, not an accident.
- 3.Assign token budgets per section. Pack user message and system prompt first.
- 4.Fill memories from the ranked list. Trim history last.
- 5.Fail closed if you still overflow.
Learn elsewhere
- →Working Memory
- →Memory Ranking
Real Example
Scenario
8k window: 800 system, 1200 memories, 5000 history, 1000 user. History over? Summarize, do not clip the user.
What you would do
In Agent Memory, apply Context Management to this scenario: 8k window: 800 system, 1200 memories, 5000 history, 1000 user. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.
Commands
Commands to Remember
Budget per sectionUser turn is sacredTrim history before memories that ranked highOverflow is a bug you can test
Cheat Sheet
Quick recap
quick ref- •Packing plan
- •Section budgets
- •Never drop the user
- •Test overflow
Common Mistakes
- ✕Appending until the API 400s
- ✕Dropping the current user message to fit a memory
- ✕No per-section budget
