Skip to content

Context Windows

opencode edited this page Oct 3, 2026 · 1 revision

Context Windows and Capability Fallback

Source: docs/CONTEXT-WINDOWS.md in the main repo (condensed — see that file for the full policy). Code is the source of truth; the research-only model catalog (docs/Nexora-AI-Model-Catalog-*) may claim larger windows, but no per-model bump is applied without live verification.

Enforced context windows

context_limit_for(provider, model) resolves in this order: per-model map → provider fallback → gemini-substring rule → default.

Models Enforced window
OpenAI: gpt-5.6-terra, gpt-5.6-luna, gpt-5.6-sol 128,000 tokens
Anthropic: claude-sonnet-5, claude-haiku-4-5-20251001, claude-opus-4-8 200,000 tokens
Gemini (verified): gemini-3.6-flash, gemini-3.1-pro-preview, gemini-pro-latest 1,048,576 tokens
Gemini lite (live-verified 2026-10-03): gemini-3.1-flash-lite, gemini-flash-lite-latest, gemini-3.5-flash, gemini-3.5-flash-lite 1,048,576 tokens
Any other provider (openai, anthropic, gemini fallback) Provider window above
Unknown provider / unknown model 128,000 tokens (default)

A smaller (earlier-compacting) window is the safe direction: unverified windows are clamped down, never up. An explicit per-request override wins when set (Some(0) = unbounded passthrough).

Proactive compaction

  • Trigger: estimated input exceeds 0.8 of the usable window (strict->, exactly 0.8 stays quiet).
  • Usable window = context limit minus 20,000 reserved output tokens. A 0 limit means unbounded/dormant: no compaction.
  • A still-overflowing second crossing surfaces terminal AgentError::ContextExhausted — distinct from retryable provider-side ExecutorError::ContextLengthExceeded (one in-place compaction + resend).

Section budgets

The assembled input window is partitioned as fixed shares of the usable window (integer floor; shares sum to 100%):

Section Share
System identity (pinned, never omitted) 10%
Task + role (droppable) 15%
Stage context (pinned while attached) 15%
Tool outputs (newest-N, oldest-first drop) 35%
History summary (lowest priority) 25%

Overflow trims lowest-priority first and oldest-first within a section; system identity and the current stage truncate only as a last resort.

Capability gating

  • Listed models (hardcoded SUPPORTED_MODELS) are tool/vision/JSON capable; unlisted IDs get conservative false flags.
  • recommended_models(provider, require_tools): when tools are required, non-tool models are filtered out. Unknown providers yield an empty list.
  • No cross-provider fallback: a terminal failure or skipped model for one provider never tries another provider's models.

Compat endpoints (openai_compat)

  • No hardcoded model list by design (empty list): the model ID comes from the endpoint configuration.
  • supports_tools is a user toggle (default true); endpoints without function-calling support never receive the tools member. Misconfigured endpoints fail closed before any network activity.
  • Custom (unlisted) model IDs pass through for chat but are skipped fail-closed for agent runs (require_tools == true).

Pricing disclaimer

All cost figures are hardcoded estimates, never fetched over the network: known-free IDs bill $0, listed native IDs bill their table estimate, everything else bills a conservative policy default. Treat displayed costs as spend-guard approximations, not bills.

Clone this wiki locally