Managing Context in Long Conversations
Every LLM on PolarGrid enforces a hard context limit — forqwen-3.5-27b it is 8,192 tokens covering the system prompt, the full message history, and the requested completion. 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, and a long support call can cross 8,192 tokens mid-conversation. If your orchestration layer doesn’t manage the window, the session dies at its longest — and most engaged — moment. Build context management in from the first prototype.Rule of thumb for budgeting
English text averages roughly 4 characters (≈0.75 words) per token. A practical budget forqwen-3.5-27b:
| Slice | Budget |
|---|---|
| System prompt | ≤ 1,000 tokens |
Reserved for the reply (max_tokens) | 512–1,024 tokens |
| Conversation history | whatever remains (~6,000 tokens ≈ 45 average voice turns) |
len(text) / 4 is adequate) and compact before you hit the wall — at ~80% of the 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.