Skip to main content

vv_agent/runtime/engine/
construction.rs

1use std::path::PathBuf;
2use std::sync::{Arc, Mutex};
3
4use crate::llm::LlmClient;
5use crate::runtime::backends::RuntimeExecutionBackend;
6use crate::runtime::hooks::RuntimeHook;
7use crate::tools::{build_default_registry, ToolRegistry};
8use crate::workspace::{LocalWorkspaceBackend, WorkspaceBackend};
9
10use super::AgentRuntime;
11
12impl<C: LlmClient> AgentRuntime<C> {
13    pub fn new(llm_client: C) -> Self {
14        Self {
15            llm_client,
16            tool_registry: build_default_registry(),
17            default_workspace: None,
18            log_handler: None,
19            log_preview_chars: None,
20            workspace_backend: Arc::new(LocalWorkspaceBackend::new(PathBuf::from("./workspace"))),
21            hooks: Vec::new(),
22            execution_backend: RuntimeExecutionBackend::default(),
23            settings_file: None,
24            default_backend: None,
25            sub_agent_timeout_seconds: 90.0,
26            tool_policy: None,
27            pending_tool_approval: None,
28        }
29    }
30
31    pub fn with_tool_registry(mut self, tool_registry: ToolRegistry) -> Self {
32        self.tool_registry = tool_registry;
33        self
34    }
35
36    pub fn with_default_workspace(mut self, workspace: impl Into<PathBuf>) -> Self {
37        self.default_workspace = Some(workspace.into());
38        self
39    }
40
41    pub fn with_workspace_backend(mut self, backend: Arc<dyn WorkspaceBackend>) -> Self {
42        self.workspace_backend = backend;
43        self
44    }
45
46    pub fn with_hooks(mut self, hooks: Vec<Arc<dyn RuntimeHook>>) -> Self {
47        self.hooks = hooks;
48        self
49    }
50
51    pub fn with_execution_backend(
52        mut self,
53        execution_backend: impl Into<RuntimeExecutionBackend>,
54    ) -> Self {
55        self.execution_backend = execution_backend.into();
56        self
57    }
58
59    pub fn with_settings_file(mut self, settings_file: impl Into<PathBuf>) -> Self {
60        self.settings_file = Some(settings_file.into());
61        self
62    }
63
64    pub fn with_default_backend(mut self, default_backend: impl Into<String>) -> Self {
65        self.default_backend = Some(default_backend.into());
66        self
67    }
68
69    pub fn with_log_preview_chars(mut self, log_preview_chars: usize) -> Self {
70        self.log_preview_chars = Some(log_preview_chars);
71        self
72    }
73
74    pub fn with_sub_agent_timeout_seconds(mut self, timeout_seconds: f64) -> Self {
75        self.sub_agent_timeout_seconds = timeout_seconds.max(1.0);
76        self
77    }
78
79    pub(crate) fn with_tool_policy(mut self, tool_policy: crate::tools::ToolPolicy) -> Self {
80        self.tool_policy = Some(tool_policy);
81        self
82    }
83
84    pub(crate) fn with_pending_tool_approval(
85        mut self,
86        pending: Arc<Mutex<Option<crate::result::PendingToolApproval>>>,
87    ) -> Self {
88        self.pending_tool_approval = Some(pending);
89        self
90    }
91}