Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Add supports_disabling_thinking to Cloud model listings (#58980)

Eric Holk20a3f7705f18
diff --git a/crates/agent/src/tests/mod.rs b/crates/agent/src/tests/mod.rs
index beb1997309b..b75485420eb 100644
--- a/crates/agent/src/tests/mod.rs
+++ b/crates/agent/src/tests/mod.rs
@@ -481,6 +481,32 @@ async fn test_thinking(cx: &mut TestAppContext) {
assert_eq!(stop_events(events), vec![acp::StopReason::EndTurn]);
}
+#[gpui::test]
+async fn test_thinking_allowed_when_model_cannot_disable_thinking(cx: &mut TestAppContext) {
+ let ThreadTest { model, thread, .. } = setup(cx, TestModel::Fake).await;
+ let fake_model = model.as_fake();
+ fake_model.set_supports_thinking(true);
+
+ // With thinking toggled off, a model that can disable thinking honors
+ // the toggle...
+ thread.update(cx, |thread, cx| {
+ thread.set_thinking_enabled(false, cx);
+ let request = thread
+ .build_completion_request(CompletionIntent::UserPrompt, cx)
+ .unwrap();
+ assert!(!request.thinking_allowed);
+ });
+
+ // ...but a model that always thinks ignores the stale toggle state.
+ fake_model.set_supports_disabling_thinking(false);
+ thread.update(cx, |thread, cx| {
+ let request = thread
+ .build_completion_request(CompletionIntent::UserPrompt, cx)
+ .unwrap();
+ assert!(request.thinking_allowed);
+ });
+}
+
#[gpui::test]
async fn test_system_prompt(cx: &mut TestAppContext) {
let ThreadTest {
diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rs
index c34df08273c..19c5475c170 100644
--- a/crates/agent/src/thread.rs
+++ b/crates/agent/src/thread.rs
@@ -3678,7 +3678,10 @@ impl Thread {
tool_choice: None,
stop: Vec::new(),
temperature: AgentSettings::temperature_for_model(model, cx),
- thinking_allowed: self.thinking_enabled,
+ // Models that can't run with thinking disabled ignore the
+ // toggle state, which may be stale from a previously selected
+ // model that could.
+ thinking_allowed: self.thinking_enabled || !model.supports_disabling_thinking(),
thinking_effort: self.thinking_effort.clone(),
speed: self.speed(),
};
diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rs
index 825c70b780f..e92cb7dd051 100644
--- a/crates/agent_ui/src/conversation_view/thread_view.rs
+++ b/crates/agent_ui/src/conversation_view/thread_view.rs
@@ -4651,6 +4651,24 @@ impl ThreadView {
return None;
}
+ // A toggle would be dishonest for models that always think: only
+ // offer the effort selector.
+ if !model.supports_disabling_thinking() {
+ let effort_levels = model.supported_effort_levels();
+ if effort_levels.is_empty() {
+ return None;
+ }
+ return Some(
+ self.render_effort_selector(
+ effort_levels,
+ thread.thinking_effort().cloned(),
+ true,
+ cx,
+ )
+ .into_any_element(),
+ );
+ }
+
let thinking = thread.thinking_enabled();
let (tooltip_label, icon, color) = if thinking {
@@ -4715,6 +4733,7 @@ impl ThreadView {
let right_btn = self.render_effort_selector(
model.supported_effort_levels(),
thread.thinking_effort().cloned(),
+ false,
cx,
);
@@ -4729,6 +4748,7 @@ impl ThreadView {
&self,
supported_effort_levels: Vec<LanguageModelEffortLevel>,
selected_effort: Option<String>,
+ standalone: bool,
cx: &Context<Self>,
) -> impl IntoElement {
let weak_self = cx.weak_entity();
@@ -4794,9 +4814,17 @@ impl ThreadView {
}
});
+ // When rendered as the right half of the split button next to the
+ // thinking toggle, only the right corners are rounded.
+ let trigger = if standalone {
+ ButtonLike::new("effort-selector-trigger")
+ } else {
+ ButtonLike::new_rounded_right("effort-selector-trigger")
+ };
+
PopoverMenu::new("effort-selector")
.trigger_with_tooltip(
- ButtonLike::new_rounded_right("effort-selector-trigger")
+ trigger
.selected_style(ButtonStyle::Tinted(TintColor::Accent))
.child(Label::new(label).size(LabelSize::Small).color(label_color))
.child(Icon::new(icon).size(IconSize::XSmall).color(Color::Muted)),
@@ -10532,7 +10560,12 @@ impl Render for ThreadView {
}
if let Some(thread) = this.as_native_thread(cx) {
thread.update(cx, |thread, cx| {
- thread.set_thinking_enabled(!thread.thinking_enabled(), cx);
+ let model_allows_disabling = thread
+ .model()
+ .is_none_or(|model| model.supports_disabling_thinking());
+ if model_allows_disabling {
+ thread.set_thinking_enabled(!thread.thinking_enabled(), cx);
+ }
});
}
}))
diff --git a/crates/cloud_llm_client/src/cloud_llm_client.rs b/crates/cloud_llm_client/src/cloud_llm_client.rs
index 5796fb7c1b0..eb1a1194d80 100644
--- a/crates/cloud_llm_client/src/cloud_llm_client.rs
+++ b/crates/cloud_llm_client/src/cloud_llm_client.rs
@@ -298,6 +298,12 @@ pub struct LanguageModel {
pub supports_tools: bool,
pub supports_images: bool,
pub supports_thinking: bool,
+ /// Whether thinking can be turned off entirely for this model, allowing
+ /// clients to offer an "off" choice alongside `supported_effort_levels`.
+ /// Some models (e.g. Claude Fable 5) always think and cannot honor an
+ /// "off" request. Only meaningful when `supports_thinking` is `true`.
+ #[serde(default)]
+ pub supports_disabling_thinking: bool,
#[serde(default)]
pub supports_fast_mode: bool,
pub supported_effort_levels: Vec<SupportedEffortLevel>,
diff --git a/crates/language_model/src/fake_provider.rs b/crates/language_model/src/fake_provider.rs
index e9f4fba4430..7bb4f8100d3 100644
--- a/crates/language_model/src/fake_provider.rs
+++ b/crates/language_model/src/fake_provider.rs
@@ -124,6 +124,7 @@ pub struct FakeLanguageModel {
>,
forbid_requests: AtomicBool,
supports_thinking: AtomicBool,
+ supports_disabling_thinking: AtomicBool,
supports_streaming_tools: AtomicBool,
supports_images: AtomicBool,
max_token_count: AtomicU64,
@@ -140,6 +141,7 @@ impl Default for FakeLanguageModel {
current_completion_txs: Mutex::new(Vec::new()),
forbid_requests: AtomicBool::new(false),
supports_thinking: AtomicBool::new(false),
+ supports_disabling_thinking: AtomicBool::new(true),
supports_streaming_tools: AtomicBool::new(false),
supports_images: AtomicBool::new(false),
max_token_count: AtomicU64::new(1_000_000),
@@ -176,6 +178,10 @@ impl FakeLanguageModel {
self.supports_thinking.store(supports, SeqCst);
}
+ pub fn set_supports_disabling_thinking(&self, supports: bool) {
+ self.supports_disabling_thinking.store(supports, SeqCst);
+ }
+
pub fn set_supports_streaming_tools(&self, supports: bool) {
self.supports_streaming_tools.store(supports, SeqCst);
}
@@ -306,6 +312,10 @@ impl LanguageModel for FakeLanguageModel {
self.supports_thinking.load(SeqCst)
}
+ fn supports_disabling_thinking(&self) -> bool {
+ self.supports_disabling_thinking.load(SeqCst)
+ }
+
fn supports_streaming_tools(&self) -> bool {
self.supports_streaming_tools.load(SeqCst)
}
diff --git a/crates/language_model/src/language_model.rs b/crates/language_model/src/language_model.rs
index 1eb2ec5b680..fc91c00bdee 100644
--- a/crates/language_model/src/language_model.rs
+++ b/crates/language_model/src/language_model.rs
@@ -86,6 +86,13 @@ pub trait LanguageModel: Send + Sync {
false
}
+ /// Whether thinking can be turned off entirely for this model. Some
+ /// models (e.g. Claude Fable 5) always think and cannot honor an "off"
+ /// request. Only meaningful when `supports_thinking` returns `true`.
+ fn supports_disabling_thinking(&self) -> bool {
+ true
+ }
+
fn supports_fast_mode(&self) -> bool {
false
}
diff --git a/crates/language_models/src/provider/cloud.rs b/crates/language_models/src/provider/cloud.rs
index 92c21062367..47fcdaf3c4c 100644
--- a/crates/language_models/src/provider/cloud.rs
+++ b/crates/language_models/src/provider/cloud.rs
@@ -764,6 +764,7 @@ mod tests {
supports_tools: true,
supports_images: false,
supports_thinking: false,
+ supports_disabling_thinking: false,
supports_fast_mode: false,
supported_effort_levels: Vec::new(),
supports_streaming_tools: false,
diff --git a/crates/language_models_cloud/src/language_models_cloud.rs b/crates/language_models_cloud/src/language_models_cloud.rs
index 6fdd11caf57..d4598b89e70 100644
--- a/crates/language_models_cloud/src/language_models_cloud.rs
+++ b/crates/language_models_cloud/src/language_models_cloud.rs
@@ -354,6 +354,10 @@ impl<TP: CloudLlmTokenProvider + 'static> LanguageModel for CloudLanguageModel<T
self.model.supports_thinking
}
+ fn supports_disabling_thinking(&self) -> bool {
+ self.model.supports_disabling_thinking
+ }
+
fn supports_fast_mode(&self) -> bool {
self.model.supports_fast_mode
}