Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/workflows/patched-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
114 changes: 112 additions & 2 deletions crates/goose-provider-types/src/formats/anthropic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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(())
}
Expand All @@ -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);
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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");
Expand Down
39 changes: 34 additions & 5 deletions crates/goose-provider-types/src/formats/databricks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }),
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion crates/goose-providers/src/databricks_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 18 additions & 9 deletions crates/goose/src/providers/formats/bedrock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ pub fn bedrock_anthropic_thinking_fields(model_config: &ModelConfig) -> Option<D
let anthropic_config = bedrock_anthropic_model_config(model_config)?;
let thinking_type = thinking_type_for_provider(ANTHROPIC_PROVIDER_NAME, &anthropic_config);
let thinking = match thinking_type {
ThinkingType::Adaptive => 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
Expand All @@ -57,6 +60,10 @@ pub fn bedrock_anthropic_thinking_fields(model_config: &ModelConfig) -> Option<D
"budget_tokens".to_string(),
Document::Number(Number::PosInt(budget_tokens as u64)),
),
(
"display".to_string(),
Document::String("summarized".to_string()),
),
]))
}
ThinkingType::Disabled => {
Expand Down Expand Up @@ -671,7 +678,8 @@ mod tests {
json!({
"thinking": {
"type": "enabled",
"budget_tokens": 4000
"budget_tokens": 4000,
"display": "summarized"
}
})
);
Expand All @@ -695,7 +703,8 @@ mod tests {
json!({
"thinking": {
"type": "enabled",
"budget_tokens": 3000 - 1024
"budget_tokens": 3000 - 1024,
"display": "summarized"
}
})
);
Expand Down Expand Up @@ -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"}
})
);
Expand All @@ -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"}
})
);
Expand All @@ -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"}
})
);
Expand Down
20 changes: 20 additions & 0 deletions crates/goose/src/providers/formats/gcpvertexai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;
Expand Down