Skip to content

Commit bbe7c9a

Browse files
authored
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
1 parent f6345a6 commit bbe7c9a

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

crates/assistant2/src/active_thread.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,7 @@ impl ActiveThread {
297297
});
298298
}
299299
ThreadEvent::ToolFinished { .. } => {
300-
let all_tools_finished = self
301-
.thread
302-
.read(cx)
303-
.pending_tool_uses()
304-
.into_iter()
305-
.all(|tool_use| tool_use.status.is_error());
306-
if all_tools_finished {
300+
if self.thread.read(cx).all_tools_finished() {
307301
let model_registry = LanguageModelRegistry::read_global(cx);
308302
if let Some(model) = model_registry.active_model() {
309303
self.thread.update(cx, |thread, cx| {

crates/assistant2/src/thread.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ impl Thread {
202202
self.tool_use.pending_tool_uses()
203203
}
204204

205+
/// Returns whether all of the tool uses have finished running.
206+
pub fn all_tools_finished(&self) -> bool {
207+
// If the only pending tool uses left are the ones with errors, then that means that we've finished running all
208+
// of the pending tools.
209+
self.pending_tool_uses()
210+
.into_iter()
211+
.all(|tool_use| tool_use.status.is_error())
212+
}
213+
205214
pub fn tool_uses_for_message(&self, id: MessageId) -> Vec<ToolUse> {
206215
self.tool_use.tool_uses_for_message(id)
207216
}

0 commit comments

Comments
 (0)