mirror of
https://github.com/openai/codex.git
synced 2026-11-15 22:53:30 +00:00
Support model-owned token budget defaults (#35608)
## What changed - Add token-budget settings to model catalog messages and apply them when the feature is enabled without explicit token-budget configuration. - Keep explicit user settings authoritative, reject invalid catalog defaults, and preserve resolved defaults in exported config locks. - Manage context-window guidance through world state so it updates once when the active model changes while retaining prior conversation history. ## Testing - Cover catalog defaults, explicit overrides, disabled features, invalid values, config-lock replay, and model switching. GitOrigin-RevId: 54544fefaa14b09f5ef5bad9967a13c52b87b0fe
This commit is contained in:
1 parent
16d7daad7c
commit
fbe65995bb
17 files changed
+742
-72
No files matched your search
@@ -1,7 +1,59 @@
|
||||
use super::session::Session;
|
||||
use super::turn_context::TurnContext;
|
||||
use crate::config::Config;
|
||||
use crate::config::TokenBudgetConfig;
|
||||
use crate::context::ContextualUserFragment;
|
||||
use codex_features::Feature;
|
||||
use codex_protocol::openai_models::ModelInfo;
|
||||
|
||||
pub(super) fn has_explicit_settings(config: &Config) -> bool {
|
||||
config
|
||||
.config_layer_stack
|
||||
.effective_config()
|
||||
.get("features")
|
||||
.and_then(|features| features.get("token_budget"))
|
||||
.and_then(|token_budget| token_budget.as_table())
|
||||
.is_some_and(|settings| settings.keys().any(|key| key != "enabled"))
|
||||
|| config
|
||||
.token_budget
|
||||
.as_ref()
|
||||
.is_some_and(|token_budget| token_budget != &TokenBudgetConfig::default())
|
||||
}
|
||||
|
||||
pub(super) fn apply_model_defaults(config: &mut Config, model_info: &ModelInfo) {
|
||||
if !config.features.enabled(Feature::TokenBudget) || has_explicit_settings(config) {
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(model_defaults) = model_info
|
||||
.model_messages
|
||||
.as_ref()
|
||||
.and_then(|messages| messages.token_budget.as_ref())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
let token_budget = TokenBudgetConfig {
|
||||
reminder_threshold_tokens: Some(model_defaults.reminder_threshold_tokens),
|
||||
reminder_message_template: model_defaults.reminder_message_template.clone(),
|
||||
guidance_message: Some(model_defaults.guidance_message.clone()),
|
||||
auto_compact_fallback_prompt: Some(model_defaults.auto_compact_fallback_prompt.clone()),
|
||||
auto_compact_fallback_buffer_tokens: Some(
|
||||
model_defaults.auto_compact_fallback_buffer_tokens,
|
||||
),
|
||||
};
|
||||
|
||||
if let Err(error) = token_budget.validate() {
|
||||
tracing::warn!(
|
||||
model = %model_info.slug,
|
||||
%error,
|
||||
"ignoring invalid model-owned token-budget defaults"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
config.token_budget = Some(token_budget);
|
||||
}
|
||||
|
||||
pub(super) async fn maybe_record(
|
||||
sess: &Session,
|
||||
|
||||
Reference in new issue
Block a user