fix Databricks GLM-5.3 and Kimi K3 reasoning effort (#12079)
This commit is contained in:
@@ -282,9 +282,43 @@ impl ModelConfig {
|
||||
self.is_openai_reasoning_model()
|
||||
|| self.model_name.to_lowercase().contains("claude")
|
||||
|| Self::is_gemini3_reasoning_model_name(&self.model_name)
|
||||
|| self.is_glm_5_3_reasoning_model()
|
||||
|| self.is_kimi_k3_reasoning_model()
|
||||
|| is_xai_reasoning_model(&self.model_name)
|
||||
}
|
||||
|
||||
pub fn is_glm_5_3_reasoning_model(&self) -> bool {
|
||||
let name = self
|
||||
.model_name
|
||||
.splitn(3, '.')
|
||||
.nth(2)
|
||||
.unwrap_or(&self.model_name);
|
||||
let lower = name.to_lowercase();
|
||||
let segments: Vec<_> = lower
|
||||
.split(|character: char| !character.is_ascii_alphanumeric())
|
||||
.filter(|segment| !segment.is_empty())
|
||||
.collect();
|
||||
segments
|
||||
.windows(3)
|
||||
.any(|segments| segments == ["glm", "5", "3"])
|
||||
}
|
||||
|
||||
pub fn is_kimi_k3_reasoning_model(&self) -> bool {
|
||||
let name = self
|
||||
.model_name
|
||||
.splitn(3, '.')
|
||||
.nth(2)
|
||||
.unwrap_or(&self.model_name);
|
||||
let lower = name.to_lowercase();
|
||||
let segments: Vec<_> = lower
|
||||
.split(|character: char| !character.is_ascii_alphanumeric())
|
||||
.filter(|segment| !segment.is_empty())
|
||||
.collect();
|
||||
segments
|
||||
.windows(2)
|
||||
.any(|segments| segments == ["kimi", "k3"])
|
||||
}
|
||||
|
||||
fn is_gemini3_reasoning_model_name(model_name: &str) -> bool {
|
||||
let lower = model_name.to_lowercase();
|
||||
lower.starts_with("gemini-3") || lower.contains("/gemini-3") || lower.contains("-gemini-3")
|
||||
@@ -967,11 +1001,38 @@ mod tests {
|
||||
assert!(ModelConfig::new("o3-mini").is_reasoning_model());
|
||||
assert!(ModelConfig::new("claude-sonnet-4").is_reasoning_model());
|
||||
assert!(ModelConfig::new("gemini-3-pro").is_reasoning_model());
|
||||
assert!(ModelConfig::new("glm-5.3").is_reasoning_model());
|
||||
assert!(
|
||||
ModelConfig::new("data_workflow_tools.goose.goose-glm-5-3").is_reasoning_model()
|
||||
);
|
||||
assert!(!ModelConfig::new("glm-5.30").is_reasoning_model());
|
||||
assert!(!ModelConfig::new("glm_5_3_models.prod.llama-3").is_reasoning_model());
|
||||
assert!(ModelConfig::new("grok-4.5").is_reasoning_model());
|
||||
assert!(ModelConfig::new("grok-4.20-0309-reasoning").is_reasoning_model());
|
||||
assert!(!ModelConfig::new("grok-4.20-0309-non-reasoning").is_reasoning_model());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recognizes_kimi_k3_without_matching_other_versions() {
|
||||
for model in [
|
||||
"kimi-k3",
|
||||
"moonshotai/kimi-k3",
|
||||
"catalog.schema.goose-kimi-k3",
|
||||
"Kimi-K3",
|
||||
] {
|
||||
assert!(ModelConfig::new(model).is_reasoning_model(), "{model}");
|
||||
let mut config = ModelConfig::new(model);
|
||||
config.reasoning = Some(false);
|
||||
assert!(!config.is_reasoning_model());
|
||||
}
|
||||
for model in ["kimi-k30", "kimi-k2.5", "kimi-k2-thinking", "notkimi-k3"] {
|
||||
assert!(
|
||||
!ModelConfig::new(model).is_kimi_k3_reasoning_model(),
|
||||
"{model}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uses_explicit_metadata_first() {
|
||||
let _guard = env_lock::lock_env(ENV_LOCK_KEYS);
|
||||
|
||||
@@ -34,6 +34,7 @@ use crate::retry::{
|
||||
RetryConfig, DEFAULT_BACKOFF_MULTIPLIER, DEFAULT_INITIAL_RETRY_INTERVAL_MS,
|
||||
DEFAULT_MAX_RETRIES, DEFAULT_MAX_RETRY_INTERVAL_MS,
|
||||
};
|
||||
use crate::thinking::ThinkingEffort;
|
||||
use rmcp::model::Tool;
|
||||
|
||||
const DATABRICKS_V2_PROVIDER_NAME: &str = "databricks_v2";
|
||||
@@ -254,6 +255,21 @@ impl DatabricksV2Provider {
|
||||
model_name.contains("claude")
|
||||
}
|
||||
|
||||
fn always_on_reasoning_effort(model_config: &ModelConfig) -> Option<&'static str> {
|
||||
if !model_config.is_reasoning_model()
|
||||
|| !(model_config.is_glm_5_3_reasoning_model()
|
||||
|| model_config.is_kimi_k3_reasoning_model())
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(match model_config.thinking_effort() {
|
||||
Some(ThinkingEffort::Off | ThinkingEffort::Low) => "low",
|
||||
Some(ThinkingEffort::Medium | ThinkingEffort::High) => "high",
|
||||
Some(ThinkingEffort::Max) | None => "max",
|
||||
})
|
||||
}
|
||||
|
||||
fn name_looks_chat_capable(name: &str) -> bool {
|
||||
if name.to_ascii_lowercase().contains("embedding") {
|
||||
return false;
|
||||
@@ -374,6 +390,9 @@ impl DatabricksV2Provider {
|
||||
if is_model_service {
|
||||
payload["model"] = Value::String(model_config.model_name.clone());
|
||||
}
|
||||
if let Some(effort) = Self::always_on_reasoning_effort(model_config) {
|
||||
payload["reasoning_effort"] = Value::String(effort.to_string());
|
||||
}
|
||||
if payload.get("max_tokens").is_none() {
|
||||
payload["max_tokens"] = Value::from(model_config.max_output_tokens());
|
||||
}
|
||||
@@ -615,6 +634,40 @@ impl DatabricksV2Provider {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn always_on_effort_mapping_preserves_supported_values() {
|
||||
for model in [
|
||||
"catalog.schema.goose-glm-5-3",
|
||||
"catalog.schema.goose-kimi-k3",
|
||||
] {
|
||||
for (effort, expected) in [
|
||||
(None, "max"),
|
||||
(Some(ThinkingEffort::Off), "low"),
|
||||
(Some(ThinkingEffort::Low), "low"),
|
||||
(Some(ThinkingEffort::Medium), "high"),
|
||||
(Some(ThinkingEffort::High), "high"),
|
||||
(Some(ThinkingEffort::Max), "max"),
|
||||
] {
|
||||
let mut config = ModelConfig::new(model).with_default_thinking_effort(effort);
|
||||
assert_eq!(
|
||||
DatabricksV2Provider::always_on_reasoning_effort(&config),
|
||||
Some(expected)
|
||||
);
|
||||
config.reasoning = Some(false);
|
||||
assert_eq!(
|
||||
DatabricksV2Provider::always_on_reasoning_effort(&config),
|
||||
None
|
||||
);
|
||||
}
|
||||
}
|
||||
assert_eq!(
|
||||
DatabricksV2Provider::always_on_reasoning_effort(&ModelConfig::new(
|
||||
"catalog.schema.custom"
|
||||
)),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn routes_known_model_families() {
|
||||
for model in [
|
||||
@@ -871,6 +924,39 @@ mod tests {
|
||||
.expect("GPT-6 model service should use the Responses API");
|
||||
}
|
||||
|
||||
#[test_case::test_case("catalog.schema.goose-glm-5-3" ; "glm 5.3")]
|
||||
#[test_case::test_case("catalog.schema.goose-kimi-k3" ; "kimi k3")]
|
||||
#[tokio::test]
|
||||
async fn model_service_forwards_reasoning_effort(model: &str) {
|
||||
let body = "data: {\"choices\":[{\"delta\":{},\"finish_reason\":\"stop\"}]}\n\ndata: [DONE]\n\n";
|
||||
|
||||
let server = MockServer::start().await;
|
||||
Mock::given(method("POST"))
|
||||
.and(path("/ai-gateway/mlflow/v1/chat/completions"))
|
||||
.and(body_partial_json(json!({
|
||||
"model": model,
|
||||
"reasoning_effort": "high"
|
||||
})))
|
||||
.respond_with(
|
||||
ResponseTemplate::new(200)
|
||||
.set_body_string(body)
|
||||
.append_header("content-type", "text/event-stream"),
|
||||
)
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
|
||||
provider(server.uri())
|
||||
.complete(
|
||||
&ModelConfig::new(model).with_thinking_effort(ThinkingEffort::High),
|
||||
"system",
|
||||
&[],
|
||||
&[],
|
||||
)
|
||||
.await
|
||||
.expect("model service should receive reasoning effort");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn responses_api_streams_text_tool_calls_and_usage_over_the_configured_path() {
|
||||
let created = r#"data: {"type":"response.created","sequence_number":1,"response":{"id":"resp_1","object":"response","created_at":0,"status":"in_progress","model":"databricks-gpt-5-5","output":[]}}"#;
|
||||
|
||||
@@ -384,7 +384,16 @@ fn capability_thinking_effort_value(
|
||||
}
|
||||
|
||||
fn thinking_effort_values(model_config: &ModelConfig) -> &'static [ThinkingEffort] {
|
||||
if model_config.is_reasoning_model() {
|
||||
if !model_config.is_reasoning_model() {
|
||||
&[ThinkingEffort::Off]
|
||||
} else if model_config.is_glm_5_3_reasoning_model() || model_config.is_kimi_k3_reasoning_model()
|
||||
{
|
||||
&[
|
||||
ThinkingEffort::Low,
|
||||
ThinkingEffort::High,
|
||||
ThinkingEffort::Max,
|
||||
]
|
||||
} else {
|
||||
&[
|
||||
ThinkingEffort::Off,
|
||||
ThinkingEffort::Low,
|
||||
@@ -392,21 +401,29 @@ fn thinking_effort_values(model_config: &ModelConfig) -> &'static [ThinkingEffor
|
||||
ThinkingEffort::High,
|
||||
ThinkingEffort::Max,
|
||||
]
|
||||
} else {
|
||||
&[ThinkingEffort::Off]
|
||||
}
|
||||
}
|
||||
|
||||
fn current_thinking_effort_value(model_config: &ModelConfig) -> String {
|
||||
if model_config.is_reasoning_model() {
|
||||
model_config
|
||||
.thinking_effort()
|
||||
.or_else(|| Config::global().get_goose_thinking_effort())
|
||||
.map(|effort| effort.to_string())
|
||||
.unwrap_or_else(|| "off".to_string())
|
||||
} else {
|
||||
"off".to_string()
|
||||
if !model_config.is_reasoning_model() {
|
||||
return "off".to_string();
|
||||
}
|
||||
|
||||
let configured = model_config
|
||||
.thinking_effort()
|
||||
.or_else(|| Config::global().get_goose_thinking_effort());
|
||||
if model_config.is_glm_5_3_reasoning_model() || model_config.is_kimi_k3_reasoning_model() {
|
||||
return match configured {
|
||||
Some(ThinkingEffort::Off | ThinkingEffort::Low) => ThinkingEffort::Low,
|
||||
Some(ThinkingEffort::Medium | ThinkingEffort::High) => ThinkingEffort::High,
|
||||
Some(ThinkingEffort::Max) | None => ThinkingEffort::Max,
|
||||
}
|
||||
.to_string();
|
||||
}
|
||||
|
||||
configured
|
||||
.map(|effort| effort.to_string())
|
||||
.unwrap_or_else(|| "off".to_string())
|
||||
}
|
||||
|
||||
fn slash_command_meta(entry: &SlashCommandEntry) -> serde_json::Map<String, serde_json::Value> {
|
||||
@@ -791,6 +808,42 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test_case("catalog.schema.goose-glm-5-3" ; "glm 5.3")]
|
||||
#[test_case("catalog.schema.goose-kimi-k3" ; "kimi k3")]
|
||||
fn test_build_config_options_offers_always_on_effort_levels(model_name: &str) {
|
||||
let _guard = env_lock::lock_env([("GOOSE_THINKING_EFFORT", None::<&str>)]);
|
||||
let mode_state = build_mode_state(GooseMode::Auto).unwrap();
|
||||
let model_state = model_selection(model_name, &[model_name]);
|
||||
let options = build_config_options(
|
||||
&mode_state,
|
||||
&model_state,
|
||||
&ModelConfig::new(model_name).with_thinking_effort(ThinkingEffort::Max),
|
||||
"databricks_v2",
|
||||
vec![SessionConfigSelectOption::new(
|
||||
"databricks_v2",
|
||||
"databricks_v2",
|
||||
)],
|
||||
&ThinkingEffortSupport::Unspecified,
|
||||
);
|
||||
let option = options
|
||||
.iter()
|
||||
.find(|option| option.id.0.as_ref() == "thinking_effort")
|
||||
.expect("thinking_effort option");
|
||||
let SessionConfigKind::Select(select) = &option.kind else {
|
||||
panic!("thinking_effort should be a select option");
|
||||
};
|
||||
|
||||
assert_eq!(select.current_value.0.as_ref(), "max");
|
||||
assert_eq!(
|
||||
select.options,
|
||||
agent_client_protocol::schema::v1::SessionConfigSelectOptions::Ungrouped(vec![
|
||||
SessionConfigSelectOption::new("low", "low"),
|
||||
SessionConfigSelectOption::new("high", "high"),
|
||||
SessionConfigSelectOption::new("max", "max"),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
fn effort_capability(values: &[&str], current: &str) -> ThinkingEffortCapability {
|
||||
ThinkingEffortCapability {
|
||||
option_id: "effort".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user