Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent: Return an error to the model when trying to use a tool that is disabled (#27928)
Marshall Bowers961bfadad9d5
diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rsindex 94d83766872..9eecd01bcc9 100644--- a/crates/agent/src/thread.rs+++ b/crates/agent/src/thread.rs@@ -3,7 +3,7 @@ use std::io::Write;use std::ops::Range;use std::sync::Arc;-use anyhow::{Context as _, Result};+use anyhow::{Context as _, Result, anyhow};use assistant_settings::AssistantSettings;use assistant_tool::{ActionLog, Tool, ToolWorkingSet};use chrono::{DateTime, Utc};@@ -1403,13 +1403,18 @@ impl Thread {cx: &mut Context<Thread>,) -> Task<()> {let tool_name: Arc<str> = tool.name().into();- let run_tool = tool.run(- input,- messages,- self.project.clone(),- self.action_log.clone(),- cx,- );++ let run_tool = if self.tools.is_disabled(&tool.source(), &tool_name) {+ Task::ready(Err(anyhow!("tool is disabled: {tool_name}")))+ } else {+ tool.run(+ input,+ messages,+ self.project.clone(),+ self.action_log.clone(),+ cx,+ )+ };cx.spawn({async move |thread: WeakEntity<Thread>, cx| {