vtcode_core/config/core/
tools.rs

1use indexmap::IndexMap;
2use serde::{Deserialize, Serialize};
3
4use crate::config::constants::defaults;
5
6/// Tools configuration
7#[derive(Debug, Clone, Deserialize, Serialize)]
8pub struct ToolsConfig {
9    /// Default policy for tools not explicitly listed
10    #[serde(default = "default_tool_policy")]
11    pub default_policy: ToolPolicy,
12
13    /// Specific tool policies
14    #[serde(default)]
15    pub policies: IndexMap<String, ToolPolicy>,
16
17    /// Maximum inner tool-call loops per user turn
18    ///
19    /// Prevents infinite tool-calling cycles in interactive chat. This limits how
20    /// many back-and-forths the agent will perform executing tools and
21    /// re-asking the model before returning a final answer.
22    ///
23    #[serde(default = "default_max_tool_loops")]
24    pub max_tool_loops: usize,
25}
26
27impl Default for ToolsConfig {
28    fn default() -> Self {
29        let mut policies = IndexMap::new();
30        policies.insert("run_terminal_cmd".to_string(), ToolPolicy::Allow);
31        policies.insert("bash".to_string(), ToolPolicy::Allow);
32        Self {
33            default_policy: default_tool_policy(),
34            policies,
35            max_tool_loops: default_max_tool_loops(),
36        }
37    }
38}
39
40/// Tool execution policy
41#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
42#[serde(rename_all = "lowercase")]
43pub enum ToolPolicy {
44    /// Allow execution without confirmation
45    Allow,
46    /// Prompt user for confirmation
47    Prompt,
48    /// Deny execution
49    Deny,
50}
51
52fn default_tool_policy() -> ToolPolicy {
53    ToolPolicy::Prompt
54}
55
56fn default_max_tool_loops() -> usize {
57    defaults::DEFAULT_MAX_TOOL_LOOPS
58}