Skip to main content

vv_agent/types/
tasks.rs

1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use super::{json_value_from_serializable, AgentStatus, Message, Metadata, NoToolPolicy};
7
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9pub struct SubAgentConfig {
10    pub model: String,
11    pub description: String,
12    pub backend: Option<String>,
13    pub system_prompt: Option<String>,
14    pub max_cycles: u32,
15    pub exclude_tools: Vec<String>,
16    pub metadata: Metadata,
17}
18
19impl SubAgentConfig {
20    pub fn new(model: impl Into<String>, description: impl Into<String>) -> Self {
21        Self {
22            model: model.into(),
23            description: description.into(),
24            backend: None,
25            system_prompt: None,
26            max_cycles: 8,
27            exclude_tools: Vec::new(),
28            metadata: Metadata::new(),
29        }
30    }
31}
32
33#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
34pub struct AgentTask {
35    pub task_id: String,
36    pub model: String,
37    pub system_prompt: String,
38    pub user_prompt: String,
39    pub max_cycles: u32,
40    pub memory_compact_threshold: u64,
41    pub memory_threshold_percentage: u8,
42    pub no_tool_policy: NoToolPolicy,
43    pub allow_interruption: bool,
44    pub use_workspace: bool,
45    pub has_sub_agents: bool,
46    pub sub_agents: BTreeMap<String, SubAgentConfig>,
47    pub agent_type: Option<String>,
48    pub native_multimodal: bool,
49    pub extra_tool_names: Vec<String>,
50    pub exclude_tools: Vec<String>,
51    pub initial_messages: Vec<Message>,
52    pub initial_shared_state: Metadata,
53    pub metadata: Metadata,
54}
55
56impl AgentTask {
57    pub fn new(
58        task_id: impl Into<String>,
59        model: impl Into<String>,
60        system_prompt: impl Into<String>,
61        user_prompt: impl Into<String>,
62    ) -> Self {
63        Self {
64            task_id: task_id.into(),
65            model: model.into(),
66            system_prompt: system_prompt.into(),
67            user_prompt: user_prompt.into(),
68            max_cycles: 8,
69            memory_compact_threshold: 128_000,
70            memory_threshold_percentage: 90,
71            no_tool_policy: NoToolPolicy::Continue,
72            allow_interruption: true,
73            use_workspace: true,
74            has_sub_agents: false,
75            sub_agents: BTreeMap::new(),
76            agent_type: None,
77            native_multimodal: false,
78            extra_tool_names: Vec::new(),
79            exclude_tools: Vec::new(),
80            initial_messages: Vec::new(),
81            initial_shared_state: Metadata::new(),
82            metadata: Metadata::new(),
83        }
84    }
85
86    pub fn sub_agents_enabled(&self) -> bool {
87        self.has_sub_agents || !self.sub_agents.is_empty()
88    }
89}
90
91#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
92pub struct SubTaskRequest {
93    pub agent_name: String,
94    pub task_description: String,
95    pub output_requirements: String,
96    pub include_main_summary: bool,
97    pub exclude_files_pattern: Option<String>,
98    pub metadata: Metadata,
99}
100
101impl SubTaskRequest {
102    pub fn new(agent_name: impl Into<String>, task_description: impl Into<String>) -> Self {
103        Self {
104            agent_name: agent_name.into(),
105            task_description: task_description.into(),
106            output_requirements: String::new(),
107            include_main_summary: false,
108            exclude_files_pattern: None,
109            metadata: Metadata::new(),
110        }
111    }
112}
113
114#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
115pub struct SubTaskOutcome {
116    pub task_id: String,
117    pub agent_name: String,
118    pub status: AgentStatus,
119    pub session_id: Option<String>,
120    pub final_answer: Option<String>,
121    pub wait_reason: Option<String>,
122    pub error: Option<String>,
123    pub cycles: u32,
124    pub todo_list: Vec<Value>,
125    pub resolved: BTreeMap<String, String>,
126}
127
128impl SubTaskOutcome {
129    pub fn to_dict(&self) -> Value {
130        self.to_value()
131    }
132
133    pub fn to_value(&self) -> Value {
134        json_value_from_serializable(self)
135    }
136}