-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Combo Context Requirements
The Context Requirements feature allows combo configurations to filter and sort targets based on their context window size. This is useful for use cases requiring large context windows like:
- Long document processing (100k+ tokens)
- Large codebase analysis
- Extensive conversation histories
- Multi-file code reviews
Add contextRequirements to your combo's runtime config:
{
"contextRequirements": {
"minContextWindow": 128000,
"preferLargeContext": true,
"contextFilterMode": "strict"
}
}-
Type:
number(0 to 10,000,000) -
Default:
undefined(no filtering) - Description: Filters out models with context windows below this threshold
Examples:
-
32000- Filter out models with <32K context -
128000- Require 128K+ context (GPT-4 Turbo, Claude 3) -
200000- Require 200K+ context (Claude 3 Opus) -
1000000- Require 1M+ context (Gemini 1.5 Pro)
-
Type:
boolean -
Default:
false -
Description: When
true, sorts remaining targets by context size (descending). Large context models are tried first.
-
Type:
"strict"|"lenient" -
Default:
"lenient" -
Description: How to handle models with unknown context window limits
-
"strict": Excludes models with unknown context limits -
"lenient": Includes models with unknown context limits
-
Context requirements are applied after filterTargetsByRequestCompatibility():
- Request compatibility filtering - Removes models incompatible with request (tools, vision, structured output)
-
Context requirements filtering - Applies
minContextWindowandcontextFilterMode -
Context-based sorting - If
preferLargeContextis true, sorts by context size descending
When minContextWindow is set:
Lenient mode (default):
- ✅ Includes models with context >= minContextWindow
- ✅ Includes models with unknown context limits
- ❌ Excludes models with context < minContextWindow
Strict mode:
- ✅ Includes models with context >= minContextWindow
- ❌ Excludes models with unknown context limits
- ❌ Excludes models with context < minContextWindow
When preferLargeContext is true:
- Models are sorted by context window size (descending)
- Unknown context models sort to the end
- Original strategy order is used as a tiebreaker
{
"name": "Document Analysis",
"strategy": "fusion",
"config": {
"contextRequirements": {
"minContextWindow": 128000,
"preferLargeContext": true,
"contextFilterMode": "strict"
}
}
}This configuration:
- Requires 128K+ context window
- Prefers larger context models (Gemini 1.5 Pro > Claude 3 Opus > GPT-4 Turbo)
- Excludes models with unknown context limits
{
"name": "Code Review",
"strategy": "auto",
"config": {
"contextRequirements": {
"minContextWindow": 200000,
"preferLargeContext": true,
"contextFilterMode": "lenient"
}
}
}This configuration:
- Requires 200K+ context window
- Prefers larger context models
- Includes models with unknown limits (lenient)
{
"name": "Flexible Chat",
"strategy": "weighted",
"config": {
"contextRequirements": {
"preferLargeContext": true
}
}
}This configuration:
- No minimum requirement (all models eligible)
- Sorts by context size (largest first)
- Useful when large context is preferred but not required
When context requirements filter targets, the combo logger outputs:
[COMBO] Context requirements: filtered 10 → 3 targets (minContextWindow: 128000, mode: strict)
[COMBO] Context requirements: kept models gemini-1.5-pro, claude-3-opus-20240229, gpt-4-turbo
[COMBO] Context requirements: sorted by context size (descending): gemini-1.5-pro(1000000), claude-3-opus-20240229(200000), gpt-4-turbo(128000)
open-sse/services/combo/contextRequirements.ts:
-
applyContextRequirements()- Main filtering function -
getTargetContextWindow()- Context lookup helper - Uses
getModelContextLimit()frommodelCapabilities.ts
open-sse/services/combo.ts line 1187:
orderedTargets = filterTargetsByRequestCompatibility(orderedTargets, body, log);
orderedTargets = applyContextRequirements(orderedTargets, config.contextRequirements, log);src/shared/validation/schemas/combo.ts:
contextRequirements: z
.object({
minContextWindow: z.coerce.number().int().min(0).max(10_000_000).optional(),
preferLargeContext: z.boolean().optional(),
contextFilterMode: z.enum(["strict", "lenient"]).optional(),
})
.strict()
.optional(),# Unit tests (schema + logic)
npm test tests/unit/combo-context-requirements.test.ts
# Integration tests (end-to-end)
npm test tests/unit/combo/context-requirements-integration.test.ts- Schema validation: 6 tests
- Filtering logic: 6 tests
- Integration: 5 tests
- Total: 17/17 passing ✅
Problem: All targets removed, combo returns "no compatible models"
Solutions:
- Lower
minContextWindowthreshold - Switch to
"lenient"mode to include unknown context models - Remove
minContextWindowand use onlypreferLargeContext
Problem: Custom/new models excluded even though they have large context
Solutions:
- Switch to
"lenient"mode (default) - Add model context limit to
modelCapabilities.ts - Remove context filtering and rely on strategy order
Problem: preferLargeContext doesn't change order
Check:
- Verify
preferLargeContext: truein config - Check if all targets have unknown context (all sort equal)
- Verify multiple targets remain after filtering
-
v3.8.47: Initial implementation
- Added
contextRequirementsconfig - Created backend filtering module
- Full test coverage (no dedicated dashboard UI yet — configure via combo JSON)
- Added
OmniRoute · Website · npm · Docker Hub
- Setup Guide
- User Guide
- Features
- Quick Start (Docker)
- Electron Desktop App
- Termux (Android)
- PWA Guide
- MCP Server
- A2A Server
- Agent Protocols
- OpenCode Plugin
- Webhooks
- Cloud Agents
- Skills
- Memory
- Evals
- Gamification
- Guardrails
- Compliance
- Error Sanitization
- Public Credentials
- Route Guard Tiers
- Stealth Guide
- CLI Token Auth