diff --git a/.github/workflows/patched-release.yml b/.github/workflows/patched-release.yml index 170403b6c24d..d0a94ace81ab 100644 --- a/.github/workflows/patched-release.yml +++ b/.github/workflows/patched-release.yml @@ -61,6 +61,7 @@ jobs: cargo test --release -p goose --features "$F" --test self_compact cargo test --release -p goose --features "$F" --test turn_error cargo test --release -p goose-sdk-types --lib -- settings_request rolling_memory_dto + cargo test --release -p goose-provider-types --lib -- thinking_display native_claude_thinking summarized_thinking_round_trips test_create_request_adaptive_thinking test_create_request_enabled_thinking_with_budget cargo test --release -p goose-cli --lib -- cache_ttl cargo test --release -p agent-client-protocol-http --features server --lib diff --git a/crates/goose-provider-types/src/formats/anthropic.rs b/crates/goose-provider-types/src/formats/anthropic.rs index ceda368b3ca5..e2f895c55b10 100644 --- a/crates/goose-provider-types/src/formats/anthropic.rs +++ b/crates/goose-provider-types/src/formats/anthropic.rs @@ -877,6 +877,17 @@ fn apply_thinking_config( obj.insert("thinking".to_string(), json!({"type": "disabled"})); } + // Newer Claude models default to `display: "omitted"` and return empty thinking + // blocks. Request summaries explicitly; other models sharing this format don't + // accept the field. + if model_config.model_name.to_lowercase().contains("claude") { + if let Some(thinking) = obj.get_mut("thinking").and_then(|t| t.as_object_mut()) { + if thinking.get("type").and_then(|t| t.as_str()) != Some("disabled") { + thinking.insert("display".to_string(), json!("summarized")); + } + } + } + // `block_binding` is only accepted alongside adaptive or enabled thinking. if let Some(behavior) = options.prefix_mismatch_behavior { if let Some(thinking) = obj.get_mut("thinking").and_then(|t| t.as_object_mut()) { @@ -1826,9 +1837,11 @@ mod tests { let messages = vec![Message::user().with_text("Hello")]; let payload = create_request_with_default_options(&config, "system", &messages, &[])?; - assert_eq!(payload["thinking"]["type"], "adaptive"); + assert_eq!( + payload["thinking"], + json!({"type": "adaptive", "display": "summarized"}) + ); assert_eq!(payload["output_config"]["effort"], "high"); - assert!(payload["thinking"].get("budget_tokens").is_none()); Ok(()) } @@ -1847,6 +1860,7 @@ mod tests { let payload = create_request_with_default_options(&config, "system", &messages, &[])?; assert_eq!(payload["thinking"]["type"], "enabled"); + assert_eq!(payload["thinking"]["display"], "summarized"); let budget = payload["thinking"]["budget_tokens"].as_i64().unwrap(); assert!(budget > 0); assert_eq!(payload["max_tokens"], 64000); @@ -1905,6 +1919,101 @@ mod tests { Ok(()) } + #[test] + fn native_claude_thinking_carries_display_and_block_binding() -> Result<()> { + let _guard = env_lock::lock_env([("GOOSE_THINKING_EFFORT", None::<&str>)]); + + let config = cfg_with_effort("claude-opus-5", "high"); + let messages = vec![Message::user().with_text("Hello")]; + let payload = create_request_with_options_provider( + &config, + "system", + &messages, + &[], + AnthropicFormatOptions::native(), + )?; + + assert_eq!( + payload["thinking"], + json!({ + "type": "adaptive", + "display": "summarized", + "block_binding": {"prefix_mismatch_behavior": "drop_block"} + }) + ); + + Ok(()) + } + + #[tokio::test] + async fn summarized_thinking_round_trips_with_its_signature() -> Result<()> { + let events = concat!( + r#"data: {"type":"message_start","message":{"id":"msg_1","role":"assistant","content":[],"model":"claude-opus-5","usage":{"input_tokens":10,"output_tokens":0}}}"#, + "\n", + r#"data: {"type":"content_block_start","index":0,"content_block":{"type":"thinking","thinking":"","signature":""}}"#, + "\n", + r#"data: {"type":"content_block_delta","index":0,"delta":{"type":"thinking_delta","thinking":"Summary of my reasoning."}}"#, + "\n", + r#"data: {"type":"content_block_delta","index":0,"delta":{"type":"signature_delta","signature":"sig_full"}}"#, + "\n", + r#"data: {"type":"content_block_stop","index":0}"#, + "\n", + r#"data: {"type":"message_stop"}"#, + ); + let parts = collect_stream(events).await; + assert_eq!( + parts.thinking, + vec![( + "Summary of my reasoning.".to_string(), + "sig_full".to_string() + )] + ); + let (text, signature) = parts.thinking[0].clone(); + + let history = vec![ + Message::user().with_text("Question"), + Message::assistant() + .with_thinking(text, signature) + .with_text("Answer"), + Message::user().with_text("Follow-up"), + ]; + let config = cfg_with_effort("claude-opus-5", "high"); + let payload = create_request_with_options_provider( + &config, + "system", + &history, + &[], + AnthropicFormatOptions::native(), + )?; + let replayed = &payload["messages"][1]["content"][0]; + assert_eq!(replayed["type"], "thinking"); + assert_eq!(replayed["thinking"], "Summary of my reasoning."); + assert_eq!(replayed["signature"], "sig_full"); + + Ok(()) + } + + #[test] + fn test_create_request_non_claude_adaptive_omits_thinking_display() -> Result<()> { + let _guard = env_lock::lock_env([("GOOSE_THINKING_EFFORT", None::<&str>)]); + + let mut config = cfg("muse-spark"); + config.reasoning = Some(true); + let messages = vec![Message::user().with_text("Hello")]; + let payload = create_request( + "muse_code", + &config, + "system", + &messages, + &[], + AnthropicFormatOptions::default(), + )?; + + assert_eq!(payload["thinking"], json!({"type": "adaptive"})); + + Ok(()) + } + #[test] fn test_create_request_preserves_thinking_context_for_compatible_models() -> Result<()> { let _guard = env_lock::lock_env([ @@ -1936,6 +2045,7 @@ mod tests { assert_eq!(payload["thinking"]["type"], "enabled"); assert!(payload["thinking"]["budget_tokens"].as_i64().unwrap() >= 1024); assert_eq!(payload["thinking"]["clear_thinking"], false); + assert!(payload["thinking"].get("display").is_none()); assert_eq!(payload["max_tokens"], 64000); assert_eq!(payload["messages"][0]["content"][0]["type"], "thinking"); assert_eq!(payload["messages"][0]["content"][0]["thinking"], "internal"); diff --git a/crates/goose-provider-types/src/formats/databricks.rs b/crates/goose-provider-types/src/formats/databricks.rs index 79273e432340..6e4924d170cd 100644 --- a/crates/goose-provider-types/src/formats/databricks.rs +++ b/crates/goose-provider-types/src/formats/databricks.rs @@ -300,7 +300,10 @@ fn apply_claude_thinking_config( match thinking_type_for_provider(provider_name, model_config) { ThinkingType::Adaptive => { - obj.insert("thinking".to_string(), json!({ "type": "adaptive" })); + obj.insert( + "thinking".to_string(), + json!({ "type": "adaptive", "display": "summarized" }), + ); obj.insert( "output_config".to_string(), json!({ "effort": adaptive_output_effort(model_config).to_string() }), @@ -318,7 +321,8 @@ fn apply_claude_thinking_config( "thinking".to_string(), json!({ "type": "enabled", - "budget_tokens": budget_tokens + "budget_tokens": budget_tokens, + "display": "summarized" }), ); obj.insert("temperature".to_string(), json!(2)); @@ -1533,7 +1537,10 @@ mod tests { let request = create_request(&model_config, "system", &[], &[], &ImageFormat::OpenAi)?; - assert_eq!(request["thinking"]["type"], "adaptive"); + assert_eq!( + request["thinking"], + json!({"type": "adaptive", "display": "summarized"}) + ); assert_eq!(request["output_config"]["effort"], "low"); assert!(request.get("temperature").is_none()); assert_eq!(request["max_completion_tokens"], 4096); @@ -1587,6 +1594,26 @@ mod tests { Ok(()) } + #[test] + fn test_create_request_disabled_thinking_omits_display() -> anyhow::Result<()> { + let _guard = env_lock::lock_env([("GOOSE_THINKING_EFFORT", None::<&str>)]); + let mut params = std::collections::HashMap::new(); + params.insert("thinking_effort".to_string(), serde_json::json!("off")); + + let mut model_config = ModelConfig::new("databricks-claude-sonnet-4.5"); + model_config.request_params = Some(params.clone()); + let request = create_request(&model_config, "system", &[], &[], &ImageFormat::OpenAi)?; + assert!(request.get("thinking").is_none()); + + // Adaptive models need an explicit disable, which must not carry `display`. + let mut model_config = ModelConfig::new("databricks-claude-opus-4-7"); + model_config.request_params = Some(params); + let request = create_request(&model_config, "system", &[], &[], &ImageFormat::OpenAi)?; + assert_eq!(request["thinking"], json!({"type": "disabled"})); + + Ok(()) + } + #[test] fn test_create_request_enabled_thinking_with_budget() -> anyhow::Result<()> { let mut model_config = ModelConfig::new("databricks-claude-sonnet-4.5"); @@ -1597,8 +1624,10 @@ mod tests { let request = create_request(&model_config, "system", &[], &[], &ImageFormat::OpenAi)?; - assert_eq!(request["thinking"]["type"], "enabled"); - assert_eq!(request["thinking"]["budget_tokens"], 16000); + assert_eq!( + request["thinking"], + json!({"type": "enabled", "budget_tokens": 16000, "display": "summarized"}) + ); assert_eq!(request["max_tokens"], 20096); assert_eq!(request["temperature"], 2); assert!(request.get("max_completion_tokens").is_none()); diff --git a/crates/goose-providers/src/databricks_v2.rs b/crates/goose-providers/src/databricks_v2.rs index 59cd0ea2e7a4..f6b4649815f6 100644 --- a/crates/goose-providers/src/databricks_v2.rs +++ b/crates/goose-providers/src/databricks_v2.rs @@ -942,7 +942,8 @@ mod tests { .and(path("/ai-gateway/anthropic/v1/messages")) .and(body_partial_json(json!({ "model": model, - "system": [{"cache_control": {"type": "ephemeral"}}] + "system": [{"cache_control": {"type": "ephemeral"}}], + "thinking": {"type": "adaptive", "display": "summarized"} }))) .respond_with( ResponseTemplate::new(200) diff --git a/crates/goose/src/providers/formats/bedrock.rs b/crates/goose/src/providers/formats/bedrock.rs index 611ecf1b3e28..cc53726c617e 100644 --- a/crates/goose/src/providers/formats/bedrock.rs +++ b/crates/goose/src/providers/formats/bedrock.rs @@ -34,10 +34,13 @@ pub fn bedrock_anthropic_thinking_fields(model_config: &ModelConfig) -> Option Document::Object(HashMap::from([( - "type".to_string(), - Document::String("adaptive".to_string()), - )])), + ThinkingType::Adaptive => Document::Object(HashMap::from([ + ("type".to_string(), Document::String("adaptive".to_string())), + ( + "display".to_string(), + Document::String("summarized".to_string()), + ), + ])), ThinkingType::Enabled => { // Thinking tokens count against `maxTokens`, which `bedrock_inference_config` // now sends when explicitly configured. Mirror the Anthropic formatter: clamp @@ -57,6 +60,10 @@ pub fn bedrock_anthropic_thinking_fields(model_config: &ModelConfig) -> Option { @@ -671,7 +678,8 @@ mod tests { json!({ "thinking": { "type": "enabled", - "budget_tokens": 4000 + "budget_tokens": 4000, + "display": "summarized" } }) ); @@ -695,7 +703,8 @@ mod tests { json!({ "thinking": { "type": "enabled", - "budget_tokens": 3000 - 1024 + "budget_tokens": 3000 - 1024, + "display": "summarized" } }) ); @@ -747,7 +756,7 @@ mod tests { assert_eq!( from_bedrock_json(&fields).unwrap(), json!({ - "thinking": {"type": "adaptive"}, + "thinking": {"type": "adaptive", "display": "summarized"}, "output_config": {"effort": "high"} }) ); @@ -766,7 +775,7 @@ mod tests { assert_eq!( from_bedrock_json(&fields).unwrap(), json!({ - "thinking": {"type": "adaptive"}, + "thinking": {"type": "adaptive", "display": "summarized"}, "output_config": {"effort": "low"} }) ); @@ -785,7 +794,7 @@ mod tests { assert_eq!( from_bedrock_json(&fields).unwrap(), json!({ - "thinking": {"type": "adaptive"}, + "thinking": {"type": "adaptive", "display": "summarized"}, "output_config": {"effort": "low"} }) ); diff --git a/crates/goose/src/providers/formats/gcpvertexai.rs b/crates/goose/src/providers/formats/gcpvertexai.rs index f1b011599ac3..06b653d81319 100644 --- a/crates/goose/src/providers/formats/gcpvertexai.rs +++ b/crates/goose/src/providers/formats/gcpvertexai.rs @@ -378,6 +378,26 @@ mod tests { Ok(()) } + #[test] + fn claude_adaptive_thinking_requests_summarized_display() -> Result<()> { + let mut config = ModelConfig::new("claude-opus-5-5"); + config.reasoning = Some(true); + config.request_params = Some(std::collections::HashMap::from([( + "thinking_effort".to_string(), + serde_json::json!("high"), + )])); + let messages = vec![Message::user().with_text("Hello")]; + + let request = create_anthropic_request(&config, "system", &messages, &[])?; + + assert_eq!( + request["thinking"], + serde_json::json!({"type": "adaptive", "display": "summarized"}) + ); + assert_eq!(request["output_config"]["effort"], "high"); + Ok(()) + } + #[test] fn test_unknown_model_parsing() -> Result<()> { let model = GcpVertexAIModel::try_from("claude-future-version")?;