pub struct TaskPlan {
pub plan_id: String,
pub objective: String,
pub tasks: HashMap<String, TaskItem>,
pub task_order: Vec<String>,
pub created_at: DateTime<Utc>,
}Expand description
A collaborative task plan created by the coordinator.
Fields§
§plan_id: StringUnique identifier for the plan.
objective: StringOverall goal/objective.
tasks: HashMap<String, TaskItem>Individual tasks in the plan (HashMap for O(1) lookup).
task_order: Vec<String>Task order (maintains insertion order for iteration).
created_at: DateTime<Utc>Timestamp when plan was created.
Implementations§
Source§impl TaskPlan
impl TaskPlan
pub fn new(plan_id: String, objective: String) -> Self
pub fn add_task(&mut self, task: TaskItem)
pub fn get_task_mut(&mut self, task_id: &str) -> Option<&mut TaskItem>
pub fn get_task(&self, task_id: &str) -> Option<&TaskItem>
Sourcepub fn get_next_ready_tasks(&self) -> Vec<&TaskItem>
pub fn get_next_ready_tasks(&self) -> Vec<&TaskItem>
Get next ready tasks with O(T * D) complexity instead of O(T²) where T = number of tasks, D = average dependencies per task
pub fn is_complete(&self) -> bool
Sourcepub fn get_progress(&self) -> (usize, usize)
pub fn get_progress(&self) -> (usize, usize)
Examples found in repository?
examples/forest_simple_demo.rs (line 73)
9async fn main() -> helios_engine::Result<()> {
10 println!("🚀 Forest of Agents - Simple Demo\n");
11
12 let config = Config::from_file("config.toml")?;
13
14 // Create a simpler forest with just 3 agents
15 let mut forest = ForestBuilder::new()
16 .config(config)
17 .agent(
18 "coordinator".to_string(),
19 Agent::builder("coordinator")
20 .system_prompt(
21 "You are a project coordinator. Your ONLY job is to create plans, not execute tasks.\n\
22 When given a task, IMMEDIATELY use the create_plan tool with this format:\n\
23 - objective: the overall goal\n\
24 - tasks: JSON array with structure [{\"id\":\"task_1\",\"description\":\"...\",\"assigned_to\":\"worker1\",\"dependencies\":[]}]\n\n\
25 Keep plans simple with 2-3 tasks max. Do NOT try to complete the task yourself."
26 )
27 .max_iterations(15)
28 )
29 .agent(
30 "worker1".to_string(),
31 Agent::builder("worker1")
32 .system_prompt(
33 "You are a helpful worker. Complete the task assigned to you and use the \
34 update_task_memory tool to save your results. Be brief and direct."
35 )
36 .max_iterations(8)
37 )
38 .agent(
39 "worker2".to_string(),
40 Agent::builder("worker2")
41 .system_prompt(
42 "You are a helpful worker. Complete the task assigned to you and use the \
43 update_task_memory tool to save your results. Be brief and direct."
44 )
45 .max_iterations(8)
46 )
47 .max_iterations(20)
48 .build()
49 .await?;
50
51 println!("✅ Forest created with 3 agents\n");
52
53 // Simple task
54 let task = "List 3 benefits of exercise. Keep it brief.";
55 println!("📋 Task: {}\n", task);
56
57 let result = forest
58 .execute_collaborative_task(
59 &"coordinator".to_string(),
60 task.to_string(),
61 vec!["worker1".to_string(), "worker2".to_string()],
62 )
63 .await?;
64
65 println!("\n{}\n", "=".repeat(60));
66 println!("✨ RESULT:\n{}\n", result);
67 println!("{}\n", "=".repeat(60));
68
69 // Show task breakdown
70 let context = forest.get_shared_context().await;
71 if let Some(plan) = context.get_plan() {
72 println!("📊 Plan Summary:");
73 let (completed, total) = plan.get_progress();
74 println!(" Completed: {}/{} tasks\n", completed, total);
75
76 for task in plan.tasks_in_order() {
77 let status = match task.status {
78 helios_engine::forest::TaskStatus::Completed => "✅",
79 helios_engine::forest::TaskStatus::InProgress => "🔄",
80 helios_engine::forest::TaskStatus::Pending => "⏳",
81 helios_engine::forest::TaskStatus::Failed => "❌",
82 };
83 println!(" {} [{}] {}", status, task.assigned_to, task.description);
84 }
85 } else {
86 println!("📊 No plan was created (coordinator handled directly)");
87 }
88
89 println!("\n✅ Demo completed!");
90
91 Ok(())
92}More examples
examples/forest_with_coordinator.rs (line 168)
19async fn main() -> helios_engine::Result<()> {
20 println!("🚀 Forest of Agents with Coordinator-Based Planning\n");
21
22 // Load configuration
23 let config = Config::from_file("config.toml")?;
24
25 // Create a Forest of Agents with specialized roles
26 let mut forest = ForestBuilder::new()
27 .config(config)
28 // Coordinator agent - creates plans and manages the team
29 .agent(
30 "coordinator".to_string(),
31 Agent::builder("coordinator")
32 .system_prompt(
33 "You are an expert project coordinator and task planner. Your role is to:\n\
34 1. Analyze complex tasks and break them into manageable subtasks\n\
35 2. Create detailed plans using the 'create_plan' tool\n\
36 3. Assign tasks to the most appropriate team members based on their expertise\n\
37 4. Define task dependencies to ensure proper execution order\n\
38 5. Synthesize final results from all team members\n\n\
39 Available team members:\n\
40 - researcher: Gathers information, conducts analysis, finds data\n\
41 - writer: Creates content, documentation, and written materials\n\
42 - analyst: Analyzes data, identifies patterns, provides insights\n\
43 - reviewer: Reviews work quality, provides feedback, ensures standards\n\n\
44 When creating a plan, think carefully about:\n\
45 - What information is needed first (research/data gathering)\n\
46 - What depends on what (task dependencies)\n\
47 - Who is best suited for each task\n\
48 - How to ensure quality (review steps)\n\n\
49 Always use the create_plan tool to structure the work.",
50 )
51 .max_iterations(20),
52 )
53 // Research agent - gathers information and data
54 .agent(
55 "researcher".to_string(),
56 Agent::builder("researcher")
57 .system_prompt(
58 "You are a research specialist who excels at:\n\
59 - Gathering comprehensive information on topics\n\
60 - Identifying key facts, statistics, and sources\n\
61 - Analyzing information for relevance and accuracy\n\
62 - Providing well-organized research findings\n\n\
63 When completing a task:\n\
64 1. Review the shared memory to see what other agents have done\n\
65 2. Conduct thorough research on your assigned topic\n\
66 3. Use 'update_task_memory' tool to save your findings\n\
67 4. Include key data points that other agents might need\n\n\
68 Be thorough but concise in your responses.",
69 )
70 .max_iterations(10),
71 )
72 // Writer agent - creates content
73 .agent(
74 "writer".to_string(),
75 Agent::builder("writer")
76 .system_prompt(
77 "You are a skilled content writer who excels at:\n\
78 - Creating clear, engaging, and well-structured content\n\
79 - Adapting tone and style to the audience\n\
80 - Incorporating research and data into narratives\n\
81 - Writing comprehensive yet accessible material\n\n\
82 When completing a task:\n\
83 1. Review the shared memory for research and data from other agents\n\
84 2. Create well-structured content based on the requirements\n\
85 3. Use 'update_task_memory' tool to save your written content\n\
86 4. Ensure your content is complete and ready for review\n\n\
87 Write clearly and professionally.",
88 )
89 .max_iterations(10),
90 )
91 // Analyst agent - analyzes data and provides insights
92 .agent(
93 "analyst".to_string(),
94 Agent::builder("analyst")
95 .system_prompt(
96 "You are a data analyst who excels at:\n\
97 - Analyzing information and identifying patterns\n\
98 - Drawing insights from data and research\n\
99 - Providing actionable recommendations\n\
100 - Summarizing complex information clearly\n\n\
101 When completing a task:\n\
102 1. Review the shared memory for available data and research\n\
103 2. Analyze the information thoroughly\n\
104 3. Use 'update_task_memory' tool to save your analysis and insights\n\
105 4. Provide clear, actionable conclusions\n\n\
106 Be analytical and data-driven in your responses.",
107 )
108 .max_iterations(10),
109 )
110 // Reviewer agent - ensures quality
111 .agent(
112 "reviewer".to_string(),
113 Agent::builder("reviewer")
114 .system_prompt(
115 "You are a quality reviewer who excels at:\n\
116 - Reviewing content for accuracy and completeness\n\
117 - Identifying areas for improvement\n\
118 - Ensuring consistency and quality standards\n\
119 - Providing constructive feedback\n\n\
120 When completing a task:\n\
121 1. Review the shared memory to see all completed work\n\
122 2. Evaluate the quality, accuracy, and completeness\n\
123 3. Use 'update_task_memory' tool to save your review and any improvements\n\
124 4. Provide clear assessment and final approval\n\n\
125 Be thorough and constructive in your reviews.",
126 )
127 .max_iterations(15),
128 )
129 .max_iterations(30)
130 .build()
131 .await?;
132
133 println!("✅ Forest created with 5 specialized agents\n");
134
135 let task1 = "Create a comprehensive guide about the benefits of renewable energy. \
136 Include research-backed information, clear explanations, data analysis, \
137 and ensure it's well-reviewed for quality.";
138
139 println!("📋 Task: {}\n", task1);
140
141 let result1 = forest
142 .execute_collaborative_task(
143 &"coordinator".to_string(),
144 task1.to_string(),
145 vec![
146 "researcher".to_string(),
147 "writer".to_string(),
148 "analyst".to_string(),
149 "reviewer".to_string(),
150 ],
151 )
152 .await?;
153
154 println!("\n{}\n", "=".repeat(70));
155 println!("✨ FINAL RESULT:\n{}\n", result1);
156 println!("{}\n", "=".repeat(70));
157
158 // Show the shared memory state
159 println!("📊 SHARED MEMORY STATE:");
160 let context = forest.get_shared_context().await;
161
162 if let Some(plan) = context.get_plan() {
163 println!("\n📋 Task Plan Summary:");
164 println!(" Objective: {}", plan.objective);
165 println!(" Total Tasks: {}", plan.tasks.len());
166 println!(
167 " Completed: {}/{}",
168 plan.get_progress().0,
169 plan.get_progress().1
170 );
171 println!("\n Task Breakdown:");
172 for task in plan.tasks_in_order() {
173 let status_icon = match task.status {
174 helios_engine::forest::TaskStatus::Completed => "✅",
175 helios_engine::forest::TaskStatus::InProgress => "🔄",
176 helios_engine::forest::TaskStatus::Pending => "⏳",
177 helios_engine::forest::TaskStatus::Failed => "❌",
178 };
179 println!(
180 " {} [{}] {} - {}",
181 status_icon, task.assigned_to, task.id, task.description
182 );
183 if let Some(result) = &task.result {
184 let preview = if result.len() > 100 {
185 format!("{}...", &result[..100])
186 } else {
187 result.clone()
188 };
189 println!(" Result: {}", preview);
190 }
191 }
192 }
193
194 println!("\n Shared Data Keys:");
195 for key in context.data.keys() {
196 if !key.starts_with("current_")
197 && !key.starts_with("involved_")
198 && !key.starts_with("task_status")
199 {
200 println!(" • {}", key);
201 }
202 }
203
204 println!("\n✅ Demo completed successfully!");
205
206 Ok(())
207}Sourcepub fn tasks_in_order(&self) -> Vec<&TaskItem>
pub fn tasks_in_order(&self) -> Vec<&TaskItem>
Get all tasks in order
Examples found in repository?
examples/forest_simple_demo.rs (line 76)
9async fn main() -> helios_engine::Result<()> {
10 println!("🚀 Forest of Agents - Simple Demo\n");
11
12 let config = Config::from_file("config.toml")?;
13
14 // Create a simpler forest with just 3 agents
15 let mut forest = ForestBuilder::new()
16 .config(config)
17 .agent(
18 "coordinator".to_string(),
19 Agent::builder("coordinator")
20 .system_prompt(
21 "You are a project coordinator. Your ONLY job is to create plans, not execute tasks.\n\
22 When given a task, IMMEDIATELY use the create_plan tool with this format:\n\
23 - objective: the overall goal\n\
24 - tasks: JSON array with structure [{\"id\":\"task_1\",\"description\":\"...\",\"assigned_to\":\"worker1\",\"dependencies\":[]}]\n\n\
25 Keep plans simple with 2-3 tasks max. Do NOT try to complete the task yourself."
26 )
27 .max_iterations(15)
28 )
29 .agent(
30 "worker1".to_string(),
31 Agent::builder("worker1")
32 .system_prompt(
33 "You are a helpful worker. Complete the task assigned to you and use the \
34 update_task_memory tool to save your results. Be brief and direct."
35 )
36 .max_iterations(8)
37 )
38 .agent(
39 "worker2".to_string(),
40 Agent::builder("worker2")
41 .system_prompt(
42 "You are a helpful worker. Complete the task assigned to you and use the \
43 update_task_memory tool to save your results. Be brief and direct."
44 )
45 .max_iterations(8)
46 )
47 .max_iterations(20)
48 .build()
49 .await?;
50
51 println!("✅ Forest created with 3 agents\n");
52
53 // Simple task
54 let task = "List 3 benefits of exercise. Keep it brief.";
55 println!("📋 Task: {}\n", task);
56
57 let result = forest
58 .execute_collaborative_task(
59 &"coordinator".to_string(),
60 task.to_string(),
61 vec!["worker1".to_string(), "worker2".to_string()],
62 )
63 .await?;
64
65 println!("\n{}\n", "=".repeat(60));
66 println!("✨ RESULT:\n{}\n", result);
67 println!("{}\n", "=".repeat(60));
68
69 // Show task breakdown
70 let context = forest.get_shared_context().await;
71 if let Some(plan) = context.get_plan() {
72 println!("📊 Plan Summary:");
73 let (completed, total) = plan.get_progress();
74 println!(" Completed: {}/{} tasks\n", completed, total);
75
76 for task in plan.tasks_in_order() {
77 let status = match task.status {
78 helios_engine::forest::TaskStatus::Completed => "✅",
79 helios_engine::forest::TaskStatus::InProgress => "🔄",
80 helios_engine::forest::TaskStatus::Pending => "⏳",
81 helios_engine::forest::TaskStatus::Failed => "❌",
82 };
83 println!(" {} [{}] {}", status, task.assigned_to, task.description);
84 }
85 } else {
86 println!("📊 No plan was created (coordinator handled directly)");
87 }
88
89 println!("\n✅ Demo completed!");
90
91 Ok(())
92}More examples
examples/forest_with_coordinator.rs (line 172)
19async fn main() -> helios_engine::Result<()> {
20 println!("🚀 Forest of Agents with Coordinator-Based Planning\n");
21
22 // Load configuration
23 let config = Config::from_file("config.toml")?;
24
25 // Create a Forest of Agents with specialized roles
26 let mut forest = ForestBuilder::new()
27 .config(config)
28 // Coordinator agent - creates plans and manages the team
29 .agent(
30 "coordinator".to_string(),
31 Agent::builder("coordinator")
32 .system_prompt(
33 "You are an expert project coordinator and task planner. Your role is to:\n\
34 1. Analyze complex tasks and break them into manageable subtasks\n\
35 2. Create detailed plans using the 'create_plan' tool\n\
36 3. Assign tasks to the most appropriate team members based on their expertise\n\
37 4. Define task dependencies to ensure proper execution order\n\
38 5. Synthesize final results from all team members\n\n\
39 Available team members:\n\
40 - researcher: Gathers information, conducts analysis, finds data\n\
41 - writer: Creates content, documentation, and written materials\n\
42 - analyst: Analyzes data, identifies patterns, provides insights\n\
43 - reviewer: Reviews work quality, provides feedback, ensures standards\n\n\
44 When creating a plan, think carefully about:\n\
45 - What information is needed first (research/data gathering)\n\
46 - What depends on what (task dependencies)\n\
47 - Who is best suited for each task\n\
48 - How to ensure quality (review steps)\n\n\
49 Always use the create_plan tool to structure the work.",
50 )
51 .max_iterations(20),
52 )
53 // Research agent - gathers information and data
54 .agent(
55 "researcher".to_string(),
56 Agent::builder("researcher")
57 .system_prompt(
58 "You are a research specialist who excels at:\n\
59 - Gathering comprehensive information on topics\n\
60 - Identifying key facts, statistics, and sources\n\
61 - Analyzing information for relevance and accuracy\n\
62 - Providing well-organized research findings\n\n\
63 When completing a task:\n\
64 1. Review the shared memory to see what other agents have done\n\
65 2. Conduct thorough research on your assigned topic\n\
66 3. Use 'update_task_memory' tool to save your findings\n\
67 4. Include key data points that other agents might need\n\n\
68 Be thorough but concise in your responses.",
69 )
70 .max_iterations(10),
71 )
72 // Writer agent - creates content
73 .agent(
74 "writer".to_string(),
75 Agent::builder("writer")
76 .system_prompt(
77 "You are a skilled content writer who excels at:\n\
78 - Creating clear, engaging, and well-structured content\n\
79 - Adapting tone and style to the audience\n\
80 - Incorporating research and data into narratives\n\
81 - Writing comprehensive yet accessible material\n\n\
82 When completing a task:\n\
83 1. Review the shared memory for research and data from other agents\n\
84 2. Create well-structured content based on the requirements\n\
85 3. Use 'update_task_memory' tool to save your written content\n\
86 4. Ensure your content is complete and ready for review\n\n\
87 Write clearly and professionally.",
88 )
89 .max_iterations(10),
90 )
91 // Analyst agent - analyzes data and provides insights
92 .agent(
93 "analyst".to_string(),
94 Agent::builder("analyst")
95 .system_prompt(
96 "You are a data analyst who excels at:\n\
97 - Analyzing information and identifying patterns\n\
98 - Drawing insights from data and research\n\
99 - Providing actionable recommendations\n\
100 - Summarizing complex information clearly\n\n\
101 When completing a task:\n\
102 1. Review the shared memory for available data and research\n\
103 2. Analyze the information thoroughly\n\
104 3. Use 'update_task_memory' tool to save your analysis and insights\n\
105 4. Provide clear, actionable conclusions\n\n\
106 Be analytical and data-driven in your responses.",
107 )
108 .max_iterations(10),
109 )
110 // Reviewer agent - ensures quality
111 .agent(
112 "reviewer".to_string(),
113 Agent::builder("reviewer")
114 .system_prompt(
115 "You are a quality reviewer who excels at:\n\
116 - Reviewing content for accuracy and completeness\n\
117 - Identifying areas for improvement\n\
118 - Ensuring consistency and quality standards\n\
119 - Providing constructive feedback\n\n\
120 When completing a task:\n\
121 1. Review the shared memory to see all completed work\n\
122 2. Evaluate the quality, accuracy, and completeness\n\
123 3. Use 'update_task_memory' tool to save your review and any improvements\n\
124 4. Provide clear assessment and final approval\n\n\
125 Be thorough and constructive in your reviews.",
126 )
127 .max_iterations(15),
128 )
129 .max_iterations(30)
130 .build()
131 .await?;
132
133 println!("✅ Forest created with 5 specialized agents\n");
134
135 let task1 = "Create a comprehensive guide about the benefits of renewable energy. \
136 Include research-backed information, clear explanations, data analysis, \
137 and ensure it's well-reviewed for quality.";
138
139 println!("📋 Task: {}\n", task1);
140
141 let result1 = forest
142 .execute_collaborative_task(
143 &"coordinator".to_string(),
144 task1.to_string(),
145 vec![
146 "researcher".to_string(),
147 "writer".to_string(),
148 "analyst".to_string(),
149 "reviewer".to_string(),
150 ],
151 )
152 .await?;
153
154 println!("\n{}\n", "=".repeat(70));
155 println!("✨ FINAL RESULT:\n{}\n", result1);
156 println!("{}\n", "=".repeat(70));
157
158 // Show the shared memory state
159 println!("📊 SHARED MEMORY STATE:");
160 let context = forest.get_shared_context().await;
161
162 if let Some(plan) = context.get_plan() {
163 println!("\n📋 Task Plan Summary:");
164 println!(" Objective: {}", plan.objective);
165 println!(" Total Tasks: {}", plan.tasks.len());
166 println!(
167 " Completed: {}/{}",
168 plan.get_progress().0,
169 plan.get_progress().1
170 );
171 println!("\n Task Breakdown:");
172 for task in plan.tasks_in_order() {
173 let status_icon = match task.status {
174 helios_engine::forest::TaskStatus::Completed => "✅",
175 helios_engine::forest::TaskStatus::InProgress => "🔄",
176 helios_engine::forest::TaskStatus::Pending => "⏳",
177 helios_engine::forest::TaskStatus::Failed => "❌",
178 };
179 println!(
180 " {} [{}] {} - {}",
181 status_icon, task.assigned_to, task.id, task.description
182 );
183 if let Some(result) = &task.result {
184 let preview = if result.len() > 100 {
185 format!("{}...", &result[..100])
186 } else {
187 result.clone()
188 };
189 println!(" Result: {}", preview);
190 }
191 }
192 }
193
194 println!("\n Shared Data Keys:");
195 for key in context.data.keys() {
196 if !key.starts_with("current_")
197 && !key.starts_with("involved_")
198 && !key.starts_with("task_status")
199 {
200 println!(" • {}", key);
201 }
202 }
203
204 println!("\n✅ Demo completed successfully!");
205
206 Ok(())
207}Trait Implementations§
Auto Trait Implementations§
impl Freeze for TaskPlan
impl RefUnwindSafe for TaskPlan
impl Send for TaskPlan
impl Sync for TaskPlan
impl Unpin for TaskPlan
impl UnwindSafe for TaskPlan
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more