From 961bfadad9d5492b233f924b3b30b22e73b283a8 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 2 Apr 2025 11:24:37 -0400 Subject: [PATCH] agent: Return an error to the model when trying to use a tool that is disabled (#27928) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR makes it so we return an error to the model if it tries to use a tool that is not currently enabled: Screenshot 2025-04-02 at 11 10 55 AM This allows the model to adapt based on that: Screenshot 2025-04-02 at 11 08 38 AM Release Notes: - N/A --- crates/agent/src/thread.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rs index 94d83766872ee9d66276634be3108d799eb6d2c2..9eecd01bcc94154a564cb6f292c2488ac6c287c1 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, ) -> Task<()> { let tool_name: Arc = 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, cx| {