fix(core): compact with the main session model, not the fast model (#11255)

This commit is contained in:
filip
2026-08-19 17:18:09 +00:00
committed by GitHub
parent b1de7a5e8a
commit 33fb29402e
2 changed files with 30 additions and 11 deletions
+5 -5
View File
@@ -276,20 +276,20 @@ pub async fn check_if_compaction_needed(
Ok(needs_compaction)
}
struct FastCompactionModel<'a> {
struct GooseCompactionModel<'a> {
provider: &'a dyn Provider,
model_config: &'a ModelConfig,
session_id: &'a str,
}
#[async_trait::async_trait]
impl goose_context_management::CompactionModel for FastCompactionModel<'_> {
impl goose_context_management::CompactionModel for GooseCompactionModel<'_> {
async fn complete(
&self,
system: &str,
messages: &[Message],
) -> Result<(Message, ProviderUsage), ProviderError> {
crate::model_config::complete_fast(
crate::model_config::complete_compaction(
self.provider,
self.model_config,
self.session_id,
@@ -348,7 +348,7 @@ async fn do_compact(
)
.agent_visible_messages();
let model = FastCompactionModel {
let model = GooseCompactionModel {
provider,
model_config,
session_id,
@@ -475,7 +475,7 @@ pub async fn summarize_tool_call(
if that is what it was.
"#};
let (mut response, _) = crate::model_config::complete_fast(
let (mut response, _) = crate::model_config::complete_compaction(
provider,
model_config,
session_id,
+25 -6
View File
@@ -87,7 +87,7 @@ fn configured_fast_model_name() -> Option<String> {
}
/// Resolve the model config to use for lightweight "fast" tasks (session
/// naming, compaction, summarization). Resolution order:
/// naming, tool-call labels, orchestrator routing). Resolution order:
/// 1. `GOOSE_FAST_MODEL` (user override)
/// 2. the provider's declared default fast model
/// 3. the supplied `model_config` (i.e. the main model)
@@ -112,8 +112,8 @@ pub async fn get_fast_model(
}
}
/// Fast tasks summarize a transcript or tool result that never recurs, so a prompt
/// cache entry written for one can never be read back and only costs the
/// A one-shot task summarizes a transcript or tool result that never recurs, so
/// a prompt cache entry written for it can never be read back and only costs the
/// cache-write premium.
fn one_shot_model_config(model_config: ModelConfig) -> ModelConfig {
model_config
@@ -121,9 +121,9 @@ fn one_shot_model_config(model_config: ModelConfig) -> ModelConfig {
.with_prompt_cache_disabled()
}
/// Run a completion for a lightweight "fast" task (session naming, compaction,
/// summarization) using the provider's fast model, falling back to the supplied
/// main `model_config` if the fast model errors.
/// Run a completion for a lightweight "fast" task (session naming, tool-call
/// labels, orchestrator routing) using the provider's fast model, falling back
/// to the supplied main `model_config` if the fast model errors.
pub async fn complete_fast(
provider: &dyn Provider,
model_config: &ModelConfig,
@@ -163,6 +163,25 @@ pub async fn complete_fast(
}
}
/// Run a completion for compaction or tool-result summarization on the main
/// session model with one-shot semantics (thinking off, no prompt-cache writes).
pub async fn complete_compaction(
provider: &dyn Provider,
model_config: &ModelConfig,
session_id: &str,
system: &str,
messages: &[Message],
tools: &[Tool],
) -> Result<(Message, ProviderUsage), ProviderError> {
let compaction_model_config = one_shot_model_config(model_config.clone());
crate::session_context::with_session_id(
Some(session_id.to_string()),
provider.complete(&compaction_model_config, system, messages, tools),
)
.await
}
async fn provider_default_fast_model(provider_name: &str) -> Option<String> {
if provider_name == goose_providers::openai::OPEN_AI_PROVIDER_NAME {
return crate::providers::openai_def::live_fast_model();