Skip to main content

spice_framework/
multi_turn.rs

1use crate::agent::AgentOutput;
2use std::ops::RangeInclusive;
3
4/// Collect all tool names called within the specified turn range.
5pub fn tools_in_range(output: &AgentOutput, range: &RangeInclusive<usize>) -> Vec<String> {
6    output
7        .turns
8        .iter()
9        .filter(|t| range.contains(&t.index))
10        .flat_map(|t| t.tool_calls.iter().map(|tc| tc.name.clone()))
11        .collect()
12}
13
14/// Find the first turn index where any of the specified tools appear.
15pub fn first_turn_with_tools(output: &AgentOutput, tools: &[String]) -> Option<usize> {
16    output.turns.iter().find_map(|t| {
17        if t.tool_calls.iter().any(|tc| tools.contains(&tc.name)) {
18            Some(t.index)
19        } else {
20            None
21        }
22    })
23}