Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e501e3b
my hints for goose
katzdave Aug 20, 2025
060bbdd
base impl
katzdave Aug 20, 2025
8b34e02
update new providers with api
katzdave Aug 20, 2025
966e391
add provider defaults
katzdave Aug 20, 2025
f95b13d
cleanup
katzdave Aug 20, 2025
32256b0
clean comments
katzdave Aug 20, 2025
e8cd8fc
Fmt
katzdave Aug 20, 2025
3c3c376
parse context limit
katzdave Aug 20, 2025
bdb5583
more model config
katzdave Aug 20, 2025
352e0c5
rm groq model
katzdave Aug 20, 2025
ee5f40b
Reset python files
katzdave Aug 20, 2025
0c85d4d
should build now
katzdave Aug 20, 2025
3637a1a
with fast abstraction + env set
katzdave Aug 21, 2025
5528a29
no fast model on custom config
katzdave Aug 21, 2025
0447587
fn comments
katzdave Aug 21, 2025
51bfa48
Swap model to modelconfig
katzdave Aug 21, 2025
d3a5307
rm extra scripts
katzdave Aug 21, 2025
55aeedf
openai output model
katzdave Aug 21, 2025
b666551
fix warnings
katzdave Aug 21, 2025
f6c2550
fmt
katzdave Aug 21, 2025
8cc66f1
support databricks
katzdave Aug 21, 2025
4ec0d9b
bring back output
katzdave Aug 21, 2025
bdbfcf4
fix databricks
katzdave Aug 21, 2025
7a5f390
databricks to 3.7sonnet
katzdave Aug 21, 2025
1e6f164
fix clippy
katzdave Aug 21, 2025
395f434
summary model -> 1.5flash
katzdave Aug 21, 2025
a60b0fd
Merge branch 'main' of github.com:block/goose into dkatz/fast-summarize2
katzdave Aug 21, 2025
f996262
fix titrate
katzdave Aug 21, 2025
9e43de9
one more test fix
katzdave Aug 21, 2025
2f232f8
fix agent tests
katzdave Aug 21, 2025
0cd4189
add fast model exists check
katzdave Aug 21, 2025
74a8359
bump sonnet model
katzdave Aug 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/goose/src/context_mgmt/summarize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub async fn summarize_messages(

// Send the request to the provider and fetch the response
let (mut response, mut provider_usage) = provider
.complete(&system_prompt, &summarization_request, &[])
.complete_fast(&system_prompt, &summarization_request, &[])
.await?;

// Set role to user as it will be used in following conversation as user content
Expand Down
2 changes: 2 additions & 0 deletions crates/goose/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub struct ModelConfig {
pub max_tokens: Option<i32>,
pub toolshim: bool,
pub toolshim_model: Option<String>,
pub fast_model: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -101,6 +102,7 @@ impl ModelConfig {
max_tokens: None,
toolshim,
toolshim_model,
fast_model: None,
})
}

Expand Down
28 changes: 27 additions & 1 deletion crates/goose/src/providers/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,32 @@ pub trait Provider: Send + Sync {
tools: &[Tool],
) -> Result<(Message, ProviderUsage), ProviderError>;

/// Generate the next message using a fast/cheaper model when available
Comment thread
katzdave marked this conversation as resolved.
Outdated
///
/// Default implementation just calls regular complete() for providers that don't support fast models
///
/// # Arguments
/// * `system` - The system prompt that guides the model's behavior
/// * `messages` - The conversation history as a sequence of messages
/// * `tools` - Optional list of tools the model can use
///
/// # Returns
/// A tuple containing the model's response message and provider usage statistics
///
/// # Errors
/// ProviderError
/// - It's important to raise ContextLengthExceeded correctly since agent handles it
async fn complete_fast(
&self,
system: &str,
messages: &[Message],
tools: &[Tool],
) -> Result<(Message, ProviderUsage), ProviderError> {
// Default implementation: just call regular complete
// Providers that support fast models should override this
self.complete(system, messages, tools).await
}

/// Get the model config from the provider
fn get_model_config(&self) -> ModelConfig;

Expand Down Expand Up @@ -418,7 +444,7 @@ pub trait Provider: Send + Sync {
let prompt = self.create_session_name_prompt(&context);
let message = Message::user().with_text(&prompt);
let result = self
.complete(
.complete_fast(
"Reply with only a description in four words or less",
&[message],
&[],
Expand Down
3 changes: 3 additions & 0 deletions crates/goose/src/providers/formats/databricks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ mod tests {
max_tokens: Some(1024),
toolshim: false,
toolshim_model: None,
fast_model: None,
};
let request = create_request(&model_config, "system", &[], &[], &ImageFormat::OpenAi)?;
let obj = request.as_object().unwrap();
Expand Down Expand Up @@ -1076,6 +1077,7 @@ mod tests {
max_tokens: Some(1024),
toolshim: false,
toolshim_model: None,
fast_model: None,
};
let request = create_request(&model_config, "system", &[], &[], &ImageFormat::OpenAi)?;
let obj = request.as_object().unwrap();
Expand Down Expand Up @@ -1108,6 +1110,7 @@ mod tests {
max_tokens: Some(1024),
toolshim: false,
toolshim_model: None,
fast_model: None,
};
let request = create_request(&model_config, "system", &[], &[], &ImageFormat::OpenAi)?;
let obj = request.as_object().unwrap();
Expand Down
3 changes: 3 additions & 0 deletions crates/goose/src/providers/formats/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@ mod tests {
max_tokens: Some(1024),
toolshim: false,
toolshim_model: None,
fast_model: None,
};
let request = create_request(&model_config, "system", &[], &[], &ImageFormat::OpenAi)?;
let obj = request.as_object().unwrap();
Expand Down Expand Up @@ -1108,6 +1109,7 @@ mod tests {
max_tokens: Some(1024),
toolshim: false,
toolshim_model: None,
fast_model: None,
};
let request = create_request(&model_config, "system", &[], &[], &ImageFormat::OpenAi)?;
let obj = request.as_object().unwrap();
Expand Down Expand Up @@ -1140,6 +1142,7 @@ mod tests {
max_tokens: Some(1024),
toolshim: false,
toolshim_model: None,
fast_model: None,
};
let request = create_request(&model_config, "system", &[], &[], &ImageFormat::OpenAi)?;
let obj = request.as_object().unwrap();
Expand Down
55 changes: 42 additions & 13 deletions crates/goose/src/providers/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use crate::providers::base::MessageStream;
use crate::providers::formats::openai::response_to_streaming_message;
use rmcp::model::Tool;

const OPEN_AI_FAST_MODEL: &str = "gpt-4o-mini";

pub const OPEN_AI_DEFAULT_MODEL: &str = "gpt-4o";
pub const OPEN_AI_KNOWN_MODELS: &[(&str, usize)] = &[
("gpt-4o", 128_000),
Expand Down Expand Up @@ -160,6 +162,31 @@ impl OpenAiProvider {
.await?;
handle_response_openai_compat(response).await
}

// Core completion logic that takes a model config
Comment thread
katzdave marked this conversation as resolved.
Outdated
async fn complete_with_model(
&self,
model_config: &ModelConfig,
system: &str,
messages: &[Message],
tools: &[Tool],
) -> Result<(Message, ProviderUsage), ProviderError> {
let payload = create_request(model_config, system, messages, tools, &ImageFormat::OpenAi)?;

let json_response = self.post(&payload).await?;

let message = response_to_message(&json_response)?;
let usage = json_response
.get("usage")
.map(get_usage)
.unwrap_or_else(|| {
tracing::debug!("Failed to get usage data");
Usage::default()
});
let model = get_model(&json_response);
emit_debug_trace(model_config, &payload, &json_response, &usage);
Ok((message, ProviderUsage::new(model, usage)))
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was previously existing, but now that we pass in the model, no need to fish it out of the json response

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got rid of it, but confused by this one since we already had the model name from before the request?

}

#[async_trait]
Expand Down Expand Up @@ -202,21 +229,23 @@ impl Provider for OpenAiProvider {
messages: &[Message],
tools: &[Tool],
) -> Result<(Message, ProviderUsage), ProviderError> {
let payload = create_request(&self.model, system, messages, tools, &ImageFormat::OpenAi)?;
// Thin wrapper that calls complete_with_model with the configured model
Comment thread
katzdave marked this conversation as resolved.
Outdated
self.complete_with_model(&self.model, system, messages, tools)
.await
}

let json_response = self.post(&payload).await?;
async fn complete_fast(
&self,
Comment thread
katzdave marked this conversation as resolved.
Outdated
system: &str,
messages: &[Message],
tools: &[Tool],
) -> Result<(Message, ProviderUsage), ProviderError> {
// Use the fast model (gpt-4o-mini) for fast completions
let mut fast_config = self.model.clone();
fast_config.model_name = OPEN_AI_FAST_MODEL.to_string();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this a method on config - config.for_fast_model() should return a copy of itself with the model_name swapped out for the smart model if that is available

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


let message = response_to_message(&json_response)?;
let usage = json_response
.get("usage")
.map(get_usage)
.unwrap_or_else(|| {
tracing::debug!("Failed to get usage data");
Usage::default()
});
let model = get_model(&json_response);
emit_debug_trace(&self.model, &payload, &json_response, &usage);
Ok((message, ProviderUsage::new(model, usage)))
self.complete_with_model(&fast_config, system, messages, tools)
.await
}

async fn fetch_supported_models(&self) -> Result<Option<Vec<String>>, ProviderError> {
Expand Down
Loading