* feat(combo): add context requirements config for target filtering
Add contextRequirements config field to combo runtime config:
- minContextWindow: filter models below threshold (0-10M tokens)
- preferLargeContext: sort targets by context size descending
- contextFilterMode: 'strict' excludes unknown limits, 'lenient' includes them
Implementation:
- Added Zod schema validation in combo.ts
- Created contextRequirements.ts module with applyContextRequirements()
- Integrated filtering after filterTargetsByRequestCompatibility()
- Full test coverage with unit + integration tests
Tests: 17/17 pass (combo-context-requirements.test.ts + integration)
* feat(combo): add ContextRequirementsEditor UI component
Add standalone React component for editing context requirements config:
- Slider for minContextWindow (0 to 1M tokens) with presets
- Toggle for preferLargeContext sorting
- Radio group for contextFilterMode (strict/lenient)
- Tooltips explaining each option
- Active filters summary display
Component features:
- Shadcn UI components (Card, Slider, Switch, RadioGroup)
- Preset buttons for common context sizes (8K, 32K, 128K, 1M)
- Conditional display of filter mode when minContextWindow > 0
- Clear visual feedback of active filters
Integration:
Import and use in combo config form where other config fields
like fusionTuning and judgeModel are edited. Pass combo.config.contextRequirements
as value prop and update on onChange.
Example usage:
<ContextRequirementsEditor
value={config.contextRequirements}
onChange={(val) => updateConfig({ contextRequirements: val })}
/>
UI matches existing combo config editor patterns.
* feat(combo): wire ContextRequirementsEditor into combo config form
Adds context requirements section to combo edit page (strategy section),
matching existing ResponseValidation pattern. Placed after response
validation block, before agent features.
* docs(combo): add context requirements feature documentation
Covers: config schema, behavior, use cases, UI integration,
troubleshooting, and test instructions.
* fix(combo): pass provider+modelStr to getModelContextLimit for accurate context resolution
Per gemini-code-assist review feedback: model names are not globally
unique across providers. Passing both provider and modelStr ensures
correct context limit resolution in applyContextRequirements().
* fix(combo): repair broken doc links and restore test:unit:fast flag
- Point docs/combo-context-requirements.md 'Related' links at real docs
(routing/AUTO-COMBO.md, architecture/RESILIENCE_GUIDE.md) — the three
placeholder links (strategies.md/model-capabilities.md/fusion-tuning.md)
did not exist and failed check:doc-links (Docs Gates fast-path).
- Revert an out-of-scope package.json change to test:unit:fast that dropped
--test-isolation=none; restore to match release/v3.8.47.
Co-authored-by: oyi77 <oyi77@users.noreply.github.com>
* test(combo): validate context requirements against the real Zod schema
Point tests/unit/combo-context-requirements.test.ts at the real
comboRuntimeConfigSchema export (src/shared/validation/schemas/combo.ts)
instead of hand-duplicating the Zod schema inline, so the test catches
schema drift.
Also declare contextRequirements on DEFAULT_COMBO_CONFIG so
resolveComboSetupConfig's inferred return type includes the key —
combo.ts reads config.contextRequirements but the property was missing
from the object typecheck:core infers types from, causing a build error.
Co-authored-by: oyi77 <oyi77@users.noreply.github.com>
* fix(combos): remove dead ContextRequirementsEditor scaffolding (broken ui/card+label imports)
The editor imported @/components/ui/card and @/components/ui/label which do not
exist in the repo, breaking the Turbopack build. Removed the editor + its page.tsx
usage + doc mention; the real fix (comboConfig contextRequirements default + test)
is preserved.
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
---------
Co-authored-by: oyi77 <oyi77@users.noreply.github.com>
Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouza.pw@gmail.com>
Co-authored-by: Diego Rodrigues de Sa e Souza <8016841+diegosouzapw@users.noreply.github.com>
6.5 KiB
Combo Context Requirements Feature
Overview
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
Configuration
Schema
Add contextRequirements to your combo's runtime config:
{
"contextRequirements": {
"minContextWindow": 128000,
"preferLargeContext": true,
"contextFilterMode": "strict"
}
}
Fields
minContextWindow (optional)
- 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 context128000- Require 128K+ context (GPT-4 Turbo, Claude 3)200000- Require 200K+ context (Claude 3 Opus)1000000- Require 1M+ context (Gemini 1.5 Pro)
preferLargeContext (optional)
- Type:
boolean - Default:
false - Description: When
true, sorts remaining targets by context size (descending). Large context models are tried first.
contextFilterMode (optional)
- 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
Behavior
Filtering Pipeline
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
Filter Mode Logic
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
Sorting Logic
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
Use Cases
Example 1: Long Document Processing
{
"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
Example 2: Large Codebase Analysis
{
"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)
Example 3: Prefer Large Context Without Strict Requirements
{
"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
API Response
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)
Implementation Details
Backend Module
open-sse/services/combo/contextRequirements.ts:
applyContextRequirements()- Main filtering functiongetTargetContextWindow()- Context lookup helper- Uses
getModelContextLimit()frommodelCapabilities.ts
Integration Point
open-sse/services/combo.ts line 1187:
orderedTargets = filterTargetsByRequestCompatibility(orderedTargets, body, log);
orderedTargets = applyContextRequirements(orderedTargets, config.contextRequirements, log);
Schema Definition
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(),
Testing
Run Tests
# 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
Test Coverage
- Schema validation: 6 tests
- Filtering logic: 6 tests
- Integration: 5 tests
- Total: 17/17 passing ✅
Troubleshooting
All targets filtered out
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
Unknown context models excluded
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
Sorting not applied
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
Related
Version History
- v3.8.47: Initial implementation
- Added
contextRequirementsconfig - Created backend filtering module
- Full test coverage (no dedicated dashboard UI yet — configure via combo JSON)
- Added