Мақала Kazakh тілінде әлі жарияланбаған. English нұсқасы көрсетілуде.
Context Window Management: Sliding Windows, Rolling Summaries, and Long Conversations
Жарияланды
2 мин оқу
Even when a model advertises a 200K+ token context window, feeding an entire 6-month customer chat history into every turn is a bad idea: latency climbs, costs multiply, and outdated facts from three months ago ("I want the blue one") pollute today's order ("ship the green one"). Good context engineering keeps memory compact, fresh, and structured.
Comparing Context Compression Patterns
| Pattern | How It Works | Strengths | Pitfalls |
|---|---|---|---|
| Sliding Window (Last N Turns) | Keep only the most recent 10-20 messages | Simple, exact wording preserved | Forgets customer constraints stated earlier |
| Rolling Summary + Recent Turns | Periodically compress older turns into structured state | Constant token footprint across long threads | Poor summary prompts drop exact IDs or prices |
| Structured Working Memory | Maintain explicit JSON facts (city, selectedSku, budget) | High precision, auditable, easy to overwrite | Requires careful update rules when user changes mind |
Keeping Rolling Summaries Lossless on Key Facts
When summarizing older turns, instruct the summarizer to output structured bullet facts rather than vague narrative prose, and explicitly handle state overrides (latest user statement wins):
ts
export interface ConversationMemory {
rollingSummary: string;
verifiedFacts: {
preferredLanguage?: string;
activeOrderId?: string;
deliveryCity?: string;
openQuestions: string[];
};
summarizedThroughMessageId: string;
}
Token Budget Allocation Recipe
Reserve explicit slices of your per-turn prompt budget so no single section crowds out instructions or tool results:
- System + Policy + Tools: fixed budget (~1,000 to 2,000 tokens, prefix-cached).
- Rolling Summary + Verified Facts: capped at ~400 to 600 tokens.
- Recent Verbatim Turns: last 8 to 12 messages (newest first, truncating very long individual messages safely).
- Retrieved RAG Evidence: capped at ~2,000 to 3,500 tokens.
Next: ship prompt and model improvements without breaking live customers in Safe AI Rollouts.
Бұл пайдалы болды ма?