How Provider Overrides and Model-Specific Context Budgets Function in Reasonix
Reasonix employs a hierarchical fallback system where provider-wide context_window defaults are applied unless explicitly overridden by model_overrides entries, enabling precise per-model token budgets without modifying source code.
The Reasonix inference engine from esengine/DeepSeek-Reasonix treats every LLM endpoint as a configurable provider with customizable token limits. Understanding how provider overrides and model-specific context budgets function allows you to fine-tune memory allocation across different models while maintaining sensible global defaults in your TOML configuration.
Provider-Wide Defaults and the Fallback Chain
At the foundation of Reasonix's budget system lies the provider-wide context_window, defined in internal/provider/config.go within the Config struct. This field establishes the default token limit for every model served by that provider.
When the engine processes a request, the Config.ResolveModel method implements the resolution logic:
- It first identifies the provider responsible for the requested model.
- It checks whether the model name exists as a key in the
ModelOverridesmap. - If an override exists and specifies a
ContextWindowgreater than zero, that value replaces the provider default. - Otherwise, the system falls back to the provider's global
ContextWindowsetting.
This design ensures that new models automatically inherit the provider's default budget while allowing surgical adjustments for specific model variants.
Model-Specific Budget Overrides in Practice
The model_overrides mechanism enables granular control through the TOML configuration structure. Under the [provider.<name>.model_overrides."<model-name>"] section, you can define a custom context_window that applies exclusively to that model.
Setting context_window = 0 for a specific model disables automatic context compaction entirely, which is useful for debugging or when handling extremely long contexts manually. Positive values specify custom token budgets—for example, allocating 1,000,000 tokens for a long-context variant while keeping the provider default at 4,000 for standard models.
The same override system supports max_output_tokens, allowing you to set generation limits independently of the input context budget. This separation ensures that reasoning-step budgets remain distinct from final output constraints.
Configuration Example
Here is a complete TOML configuration demonstrating provider defaults and per-model overrides:
# reasonix.toml
[provider.deepseek]
name = "deepseek"
base_url = "https://api.deepseek.com"
api_key_env = "DEEPSEEK_API_KEY"
# Provider-wide token budget (fallback)
context_window = 4000
# Model-specific overrides
[provider.deepseek.model_overrides."deepseek-v4-flash"]
context_window = 1_000_000 # enable long-context mode
max_output_tokens = 32_768
In this example, all DeepSeek models default to 4,000 tokens, but deepseek-v4-flash receives a one-million-token context window and a 32,768-token output limit.
Go Implementation Details
The resolution logic lives in internal/provider/config.go. The ResolveModel method performs the override check before falling back to defaults:
func (c Config) ResolveModel(model string) (int, error) {
// Find provider for the model (omitted for brevity)
prov := c.Provider // the resolved Provider config
// Check for a model-specific override
if ov, ok := prov.ModelOverrides[model]; ok && ov.ContextWindow > 0 {
return ov.ContextWindow, nil
}
// Fallback to the provider default
return prov.ContextWindow, nil
}
When building requests, the session retrieves the effective budget and passes it to the provider's compaction logic:
func (s *Session) buildRequest(model string, msgs []Message) Request {
ctxWin, _ := s.cfg.ResolveModel(model)
return Request{
Model: model,
Messages: msgs,
ContextWindow: ctxWin, // passed to the provider for compaction logic
}
}
Summary
- Provider defaults are stored in the
ContextWindowfield withininternal/provider/config.goand apply to all models unless superseded. - Model overrides use the
model_overridesmap structure in TOML configuration to specify custom budgets per model name. - Zero value behavior—setting
context_window = 0—disables automatic context compaction for that specific model. - Resolution logic is implemented in
Config.ResolveModel, which checks overrides before falling back to provider defaults. - Output limits can be configured separately via
max_output_tokensoverrides, independent of input context budgets. - Configuration-driven changes require no code modification; adjusting
reasonix.tomlsuffices for updating token limits.
Frequently Asked Questions
How does Reasonix determine the effective context window for a specific model?
Reasonix calls Config.ResolveModel in internal/provider/config.go, which first checks if the requested model exists in the provider's ModelOverrides map. If a valid override exists, that value is returned; otherwise, the method falls back to the provider's global ContextWindow setting.
Can I disable automatic context compaction for individual models?
Yes. Set context_window = 0 within the [provider.<name>.model_overrides."<model>"] section of your TOML configuration. This zero value signals the engine to bypass automatic compaction for that specific model while leaving other models unaffected.
Where are the provider default and model override specifications defined?
The authoritative specification resides in docs/SPEC.md, which defines the behavior for provider-wide fallbacks and per-model overrides. The Go implementation that enforces these rules is located in internal/provider/config.go, specifically within the Config struct and its ResolveModel method.
Is it possible to set different output token limits for specific models?
Yes. The model_overrides mechanism supports an independent max_output_tokens field. This allows you to configure generation budgets separately from input context windows, providing fine-grained control over both reasoning-step limits and final output length on a per-model basis.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →