agent: Only require confirmation for batch tool when subset of tool calls require confirmation (#28363)

Release Notes:

- agent: Only require confirmation for batch tool when subset of tool
calls require confirmation
This commit is contained in:
Bennet Bo Fenner 2025-04-08 15:37:10 -06:00 committed by GitHub
parent ef4b5b0698
commit 47eaf274d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 33 additions and 24 deletions

View file

@ -1414,7 +1414,7 @@ impl Thread {
for tool_use in pending_tool_uses.iter() { for tool_use in pending_tool_uses.iter() {
if let Some(tool) = self.tools.tool(&tool_use.name, cx) { if let Some(tool) = self.tools.tool(&tool_use.name, cx) {
if tool.needs_confirmation() if tool.needs_confirmation(&tool_use.input, cx)
&& !AssistantSettings::get_global(cx).always_allow_tool_actions && !AssistantSettings::get_global(cx).always_allow_tool_actions
{ {
self.tool_use.confirm_tool_use( self.tool_use.confirm_tool_use(

View file

@ -201,7 +201,7 @@ impl ToolUseState {
let (icon, needs_confirmation) = if let Some(tool) = self.tools.tool(&tool_use.name, cx) let (icon, needs_confirmation) = if let Some(tool) = self.tools.tool(&tool_use.name, cx)
{ {
(tool.icon(), tool.needs_confirmation()) (tool.icon(), tool.needs_confirmation(&tool_use.input, cx))
} else { } else {
(IconName::Cog, false) (IconName::Cog, false)
}; };

View file

@ -48,7 +48,7 @@ pub trait Tool: 'static + Send + Sync {
/// Returns true iff the tool needs the users's confirmation /// Returns true iff the tool needs the users's confirmation
/// before having permission to run. /// before having permission to run.
fn needs_confirmation(&self) -> bool; fn needs_confirmation(&self, input: &serde_json::Value, cx: &App) -> bool;
/// Returns the JSON schema that describes the tool's input. /// Returns the JSON schema that describes the tool's input.
fn input_schema(&self, _: LanguageModelToolSchemaFormat) -> serde_json::Value { fn input_schema(&self, _: LanguageModelToolSchemaFormat) -> serde_json::Value {

View file

@ -29,7 +29,7 @@ impl Tool for BashTool {
"bash".to_string() "bash".to_string()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
true true
} }

View file

@ -151,8 +151,17 @@ impl Tool for BatchTool {
"batch_tool".into() "batch_tool".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, input: &serde_json::Value, cx: &App) -> bool {
true serde_json::from_value::<BatchToolInput>(input.clone())
.map(|input| {
let working_set = ToolWorkingSet::default();
input.invocations.iter().any(|invocation| {
working_set
.tool(&invocation.name, cx)
.map_or(false, |tool| tool.needs_confirmation(&invocation.input, cx))
})
})
.unwrap_or(false)
} }
fn description(&self) -> String { fn description(&self) -> String {

View file

@ -79,7 +79,7 @@ impl Tool for CodeSymbolsTool {
"code_symbols".into() "code_symbols".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
false false
} }

View file

@ -43,7 +43,7 @@ impl Tool for CopyPathTool {
"copy_path".into() "copy_path".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
true true
} }

View file

@ -33,7 +33,7 @@ impl Tool for CreateDirectoryTool {
"create_directory".into() "create_directory".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
true true
} }

View file

@ -40,7 +40,7 @@ impl Tool for CreateFileTool {
"create_file".into() "create_file".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
false false
} }

View file

@ -33,7 +33,7 @@ impl Tool for DeletePathTool {
"delete_path".into() "delete_path".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
true true
} }

View file

@ -46,7 +46,7 @@ impl Tool for DiagnosticsTool {
"diagnostics".into() "diagnostics".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
false false
} }

View file

@ -116,7 +116,7 @@ impl Tool for FetchTool {
"fetch".to_string() "fetch".to_string()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
true true
} }

View file

@ -129,7 +129,7 @@ impl Tool for FindReplaceFileTool {
"find_replace_file".into() "find_replace_file".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
false false
} }

View file

@ -44,7 +44,7 @@ impl Tool for ListDirectoryTool {
"list_directory".into() "list_directory".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
false false
} }

View file

@ -42,7 +42,7 @@ impl Tool for MovePathTool {
"move_path".into() "move_path".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
true true
} }

View file

@ -33,7 +33,7 @@ impl Tool for NowTool {
"now".into() "now".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
false false
} }

View file

@ -23,7 +23,7 @@ impl Tool for OpenTool {
"open".to_string() "open".to_string()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
true true
} }

View file

@ -41,7 +41,7 @@ impl Tool for PathSearchTool {
"path_search".into() "path_search".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
false false
} }

View file

@ -51,7 +51,7 @@ impl Tool for ReadFileTool {
"read_file".into() "read_file".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
false false
} }

View file

@ -44,7 +44,7 @@ impl Tool for RegexSearchTool {
"regex_search".into() "regex_search".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
false false
} }

View file

@ -72,7 +72,7 @@ impl Tool for SymbolInfoTool {
"symbol_info".into() "symbol_info".into()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
false false
} }

View file

@ -24,7 +24,7 @@ impl Tool for ThinkingTool {
"thinking".to_string() "thinking".to_string()
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
false false
} }

View file

@ -49,7 +49,7 @@ impl Tool for ContextServerTool {
} }
} }
fn needs_confirmation(&self) -> bool { fn needs_confirmation(&self, _: &serde_json::Value, _: &App) -> bool {
true true
} }