Managing Context in Long Conversations
Every LLM on PolarGrid enforces a hard context limit covering the system prompt, the full message history, and the requested completion. Forqwen-3.8-27b it is 262,144 tokens (256K). There is no server-side truncation: when a request exceeds the limit, the API returns:
Why this matters for voice agents
Voice sessions accumulate context fast: every user turn and assistant reply joins the history. A 256K window is unlikely to be exhausted by a single call, so the pressure here is latency and cost, not the hard cap — time-to-first-token grows with prompt length, and you pay for every input token on every turn. Compact history because it keeps the agent responsive and cheap, not because the session is about to die. If you pin a lowermax_model_len on a node, or move to a model with a smaller window, the hard cap becomes the binding constraint again — the patterns below cover both cases.
Rule of thumb for budgeting
English text averages roughly 4 characters (≈0.75 words) per token.qwen-3.8-27b’s 256K window is far larger than a voice conversation needs, so budget for responsiveness rather than to the ceiling:
These are latency targets, not limits. Track an estimate as you go (
len(text) / 4 is adequate) and compact when history crosses your budget. If you are running against a genuinely small window, compact at ~80% of the hard limit rather than reacting to the 400.
Pattern 1: Sliding window (simplest, fits most voice agents)
Keep the system prompt plus the most recent N turns; drop the oldest user/assistant pairs first.Pattern 2: Running summary (when early context must survive)
When facts from early in the call matter at the end (caller name, account details, the original problem statement), fold older turns into a compact summary instead of dropping them:- When history crosses your threshold, send the oldest turns to the LLM with a “summarize the key facts in under 100 words” instruction.
- Replace those turns with a single system-adjacent message:
{"role": "system", "content": "Summary of earlier conversation: ..."}. - Keep the most recent turns verbatim.
Pattern 3: Structured state instead of raw history
Voice agents that collect fields (name, phone, address, intent) often don’t need the transcript at all — extract entities into a structured object as you go and prompt with the state object plus only the last 2-3 turns. Smallest possible context, immune to call length.Handling the overflow error defensively
Even with budgeting, guard the call:Per-model limits
Check the model card for each model’s context window (Models); the limit also applies to/v1/completions prompts. For workloads that genuinely need very long context, contact us about enterprise configurations.