Skip to main content

vv_agent/runtime/backends/distributed/
execution.rs

1use crate::runtime::CancellationToken;
2use crate::types::{AgentResult, AgentTask, CycleRecord, Message, Metadata};
3
4use super::super::{execute_cycle_loop, failed_backend_result};
5use super::backend::DistributedBackend;
6use super::r#loop::DistributedRunContext;
7
8impl DistributedBackend {
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        match (
28            &self.runtime_recipe,
29            &self.state_store,
30            &self.cycle_dispatcher,
31        ) {
32            (Some(recipe), Some(state_store), Some(cycle_dispatcher)) => {
33                return self.execute_distributed(
34                    initial_messages,
35                    shared_state,
36                    DistributedRunContext {
37                        task,
38                        recipe,
39                        state_store,
40                        cycle_dispatcher,
41                        cancellation_token,
42                        max_cycles,
43                    },
44                );
45            }
46            (Some(_), _, _) => {
47                return failed_backend_result(
48                    initial_messages,
49                    Vec::new(),
50                    shared_state,
51                    "Distributed backend requires a state_store and cycle_dispatcher".to_string(),
52                );
53            }
54            (None, _, _) => {}
55        }
56        execute_cycle_loop(
57            initial_messages,
58            shared_state,
59            cycle_executor,
60            cancellation_token,
61            max_cycles,
62        )
63    }
64}