vv_agent/runtime/backends/
inline.rs1use super::{execute_cycle_loop, execute_cycle_loop_with_state};
2use crate::runtime::CancellationToken;
3use crate::types::{AgentResult, AgentTask, CycleRecord, Message, Metadata};
4
5#[derive(Debug, Clone, Copy, Default)]
6pub struct InlineBackend;
7
8impl InlineBackend {
9 pub fn execute<F>(
10 &self,
11 _task: &AgentTask,
12 initial_messages: Vec<Message>,
13 shared_state: Metadata,
14 cycle_executor: F,
15 cancellation_token: Option<&CancellationToken>,
16 max_cycles: u32,
17 ) -> AgentResult
18 where
19 F: FnMut(
20 u32,
21 &mut Vec<Message>,
22 &mut Vec<CycleRecord>,
23 &mut Metadata,
24 Option<&CancellationToken>,
25 ) -> Option<AgentResult>,
26 {
27 execute_cycle_loop(
28 initial_messages,
29 shared_state,
30 cycle_executor,
31 cancellation_token,
32 max_cycles,
33 )
34 }
35
36 #[allow(clippy::too_many_arguments)]
37 pub(crate) fn execute_with_state<F>(
38 &self,
39 _task: &AgentTask,
40 initial_messages: Vec<Message>,
41 initial_cycles: Vec<CycleRecord>,
42 shared_state: Metadata,
43 cycle_executor: F,
44 cancellation_token: Option<&CancellationToken>,
45 cycle_index_start: u32,
46 cycle_count: u32,
47 ) -> AgentResult
48 where
49 F: FnMut(
50 u32,
51 &mut Vec<Message>,
52 &mut Vec<CycleRecord>,
53 &mut Metadata,
54 Option<&CancellationToken>,
55 ) -> Option<AgentResult>,
56 {
57 execute_cycle_loop_with_state(
58 initial_messages,
59 initial_cycles,
60 shared_state,
61 cycle_executor,
62 cancellation_token,
63 cycle_index_start,
64 cycle_count,
65 )
66 }
67
68 pub fn parallel_map<T, R, F>(&self, function: F, items: Vec<T>) -> Vec<R>
69 where
70 F: Fn(T) -> R,
71 {
72 items.into_iter().map(function).collect()
73 }
74}