Skip to content

Commit 35b8193

Browse files
bennetbolidm0707
authored andcommitted
agent: Only show compatible tools in profile selector (zed-industries#40917)
In practice this just hides the web search tool when not using the Zed provider Release Notes: - Fixed an issue where the web search tool would show up in the profile selector even when not using a model via Zed Pro
1 parent 74367b5 commit 35b8193

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

crates/agent/src/thread.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@ impl Thread {
18571857
.tools
18581858
.iter()
18591859
.filter_map(|(tool_name, tool)| {
1860-
if tool.supported_provider(&model.provider_id())
1860+
if tool.supports_provider(&model.provider_id())
18611861
&& profile.is_tool_enabled(tool_name)
18621862
{
18631863
Some((truncate(tool_name), tool.clone()))
@@ -2133,7 +2133,7 @@ where
21332133

21342134
/// Some tools rely on a provider for the underlying billing or other reasons.
21352135
/// Allow the tool to check if they are compatible, or should be filtered out.
2136-
fn supported_provider(&self, _provider: &LanguageModelProviderId) -> bool {
2136+
fn supports_provider(_provider: &LanguageModelProviderId) -> bool {
21372137
true
21382138
}
21392139

@@ -2174,7 +2174,7 @@ pub trait AnyAgentTool {
21742174
fn kind(&self) -> acp::ToolKind;
21752175
fn initial_title(&self, input: serde_json::Value, _cx: &mut App) -> SharedString;
21762176
fn input_schema(&self, format: LanguageModelToolSchemaFormat) -> Result<serde_json::Value>;
2177-
fn supported_provider(&self, _provider: &LanguageModelProviderId) -> bool {
2177+
fn supports_provider(&self, _provider: &LanguageModelProviderId) -> bool {
21782178
true
21792179
}
21802180
fn run(
@@ -2219,8 +2219,8 @@ where
22192219
Ok(json)
22202220
}
22212221

2222-
fn supported_provider(&self, provider: &LanguageModelProviderId) -> bool {
2223-
self.0.supported_provider(provider)
2222+
fn supports_provider(&self, provider: &LanguageModelProviderId) -> bool {
2223+
T::supports_provider(provider)
22242224
}
22252225

22262226
fn run(

crates/agent/src/tools.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,19 @@ pub use web_search_tool::*;
4040
macro_rules! tools {
4141
($($tool:ty),* $(,)?) => {
4242
/// A list of all built-in tool names
43-
pub fn built_in_tool_names() -> impl Iterator<Item = String> {
43+
pub fn supported_built_in_tool_names(provider: Option<language_model::LanguageModelProviderId>) -> impl Iterator<Item = String> {
4444
[
4545
$(
46-
<$tool>::name().to_string(),
46+
(if let Some(provider) = provider.as_ref() {
47+
<$tool>::supports_provider(provider)
48+
} else {
49+
true
50+
})
51+
.then(|| <$tool>::name().to_string()),
4752
)*
4853
]
4954
.into_iter()
55+
.flatten()
5056
}
5157

5258
/// A list of all built-in tools

crates/agent/src/tools/web_search_tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl AgentTool for WebSearchTool {
5757
}
5858

5959
/// We currently only support Zed Cloud as a provider.
60-
fn supported_provider(&self, provider: &LanguageModelProviderId) -> bool {
60+
fn supports_provider(provider: &LanguageModelProviderId) -> bool {
6161
provider == &ZED_CLOUD_PROVIDER_ID
6262
}
6363

crates/agent_ui/src/agent_configuration/manage_profiles_modal.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use agent_settings::{AgentProfile, AgentProfileId, AgentSettings, builtin_profil
77
use editor::Editor;
88
use fs::Fs;
99
use gpui::{DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Subscription, prelude::*};
10+
use language_model::LanguageModel;
1011
use settings::Settings as _;
1112
use ui::{
1213
KeyBinding, ListItem, ListItemSpacing, ListSeparator, Navigable, NavigableEntry, prelude::*,
@@ -96,6 +97,7 @@ pub struct NewProfileMode {
9697
pub struct ManageProfilesModal {
9798
fs: Arc<dyn Fs>,
9899
context_server_registry: Entity<ContextServerRegistry>,
100+
active_model: Option<Arc<dyn LanguageModel>>,
99101
focus_handle: FocusHandle,
100102
mode: Mode,
101103
}
@@ -109,9 +111,14 @@ impl ManageProfilesModal {
109111
workspace.register_action(|workspace, action: &ManageProfiles, window, cx| {
110112
if let Some(panel) = workspace.panel::<AgentPanel>(cx) {
111113
let fs = workspace.app_state().fs.clone();
114+
let active_model = panel
115+
.read(cx)
116+
.active_native_agent_thread(cx)
117+
.and_then(|thread| thread.read(cx).model().cloned());
118+
112119
let context_server_registry = panel.read(cx).context_server_registry().clone();
113120
workspace.toggle_modal(window, cx, |window, cx| {
114-
let mut this = Self::new(fs, context_server_registry, window, cx);
121+
let mut this = Self::new(fs, active_model, context_server_registry, window, cx);
115122

116123
if let Some(profile_id) = action.customize_tools.clone() {
117124
this.configure_builtin_tools(profile_id, window, cx);
@@ -125,6 +132,7 @@ impl ManageProfilesModal {
125132

126133
pub fn new(
127134
fs: Arc<dyn Fs>,
135+
active_model: Option<Arc<dyn LanguageModel>>,
128136
context_server_registry: Entity<ContextServerRegistry>,
129137
window: &mut Window,
130138
cx: &mut Context<Self>,
@@ -133,6 +141,7 @@ impl ManageProfilesModal {
133141

134142
Self {
135143
fs,
144+
active_model,
136145
context_server_registry,
137146
focus_handle,
138147
mode: Mode::choose_profile(window, cx),
@@ -228,9 +237,11 @@ impl ManageProfilesModal {
228237
let tool_picker = cx.new(|cx| {
229238
let delegate = ToolPickerDelegate::builtin_tools(
230239
//todo: This causes the web search tool to show up even it only works when using zed hosted models
231-
agent::built_in_tool_names()
232-
.map(|s| s.into())
233-
.collect::<Vec<_>>(),
240+
agent::supported_built_in_tool_names(
241+
self.active_model.as_ref().map(|model| model.provider_id()),
242+
)
243+
.map(|s| s.into())
244+
.collect::<Vec<_>>(),
234245
self.fs.clone(),
235246
profile_id.clone(),
236247
profile,

0 commit comments

Comments
 (0)