Skip to content
Merged
Changes from all commits
Commits
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
25 changes: 24 additions & 1 deletion crates/goose/src/agents/reply_parts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use regex::Regex;
use std::sync::Arc;

use async_stream::try_stream;
Expand All @@ -20,6 +21,27 @@ use crate::providers::toolshim::{
};
use rmcp::model::Tool;

async fn enhance_model_error(error: ProviderError, provider: &Arc<dyn Provider>) -> ProviderError {
let ProviderError::RequestFailed(ref msg) = error else {
return error;
};

let re = Regex::new(r"(?i)\b4\d{2}\b.*model|model.*\b4\d{2}\b").unwrap();
if !re.is_match(msg) {
return error;
}

let Ok(Some(models)) = provider.fetch_recommended_models().await else {
return error;
};

ProviderError::RequestFailed(format!(
"{}. Available models for this provider: {}",
msg,
models.join(", ")
))
}
Comment on lines 24 to 43
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The new enhance_model_error function lacks test coverage. Given that other functions in this file have tests, consider adding tests to verify this function correctly identifies model errors (with both "400" and "model" in the message), successfully fetches recommended models, and properly formats the enhanced error message.

Copilot uses AI. Check for mistakes.

fn coerce_value(s: &str, schema: &Value) -> Value {
let type_str = schema.get("type");

Expand Down Expand Up @@ -241,10 +263,11 @@ impl Agent {
let mut stream = match stream_result {
Ok(s) => s,
Err(e) => {
let enhanced_error = enhance_model_error(e, &provider).await;
// Return a stream that immediately yields the error
// This allows the error to be caught by existing error handling in agent.rs
return Ok(Box::pin(try_stream! {
yield Err(e)?;
yield Err(enhanced_error)?;
}));
}
};
Expand Down
Loading