From bbe7c9a738d4103d7180fabdc623d7522d39e25b Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Fri, 7 Mar 2025 18:35:32 -0500 Subject: [PATCH] assistant2: Factor out `Thread::all_tools_finished` method (#26314) This PR factors out a new `Thread::all_tools_finished` method to encapsulate some of the boilerplate in the `ThreadEvent::ToolFinished` event handler. This should make this event handler easier to replicate for the eval use-case. Release Notes: - N/A --- crates/assistant2/src/active_thread.rs | 8 +------- crates/assistant2/src/thread.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/assistant2/src/active_thread.rs b/crates/assistant2/src/active_thread.rs index 9a6239744b457b..f50689ec4cd5ac 100644 --- a/crates/assistant2/src/active_thread.rs +++ b/crates/assistant2/src/active_thread.rs @@ -297,13 +297,7 @@ impl ActiveThread { }); } ThreadEvent::ToolFinished { .. } => { - let all_tools_finished = self - .thread - .read(cx) - .pending_tool_uses() - .into_iter() - .all(|tool_use| tool_use.status.is_error()); - if all_tools_finished { + if self.thread.read(cx).all_tools_finished() { let model_registry = LanguageModelRegistry::read_global(cx); if let Some(model) = model_registry.active_model() { self.thread.update(cx, |thread, cx| { diff --git a/crates/assistant2/src/thread.rs b/crates/assistant2/src/thread.rs index c54ae4d7380d19..95f42f75453d55 100644 --- a/crates/assistant2/src/thread.rs +++ b/crates/assistant2/src/thread.rs @@ -202,6 +202,15 @@ impl Thread { self.tool_use.pending_tool_uses() } + /// Returns whether all of the tool uses have finished running. + pub fn all_tools_finished(&self) -> bool { + // If the only pending tool uses left are the ones with errors, then that means that we've finished running all + // of the pending tools. + self.pending_tool_uses() + .into_iter() + .all(|tool_use| tool_use.status.is_error()) + } + pub fn tool_uses_for_message(&self, id: MessageId) -> Vec { self.tool_use.tool_uses_for_message(id) }