forest_simple_demo/
forest_simple_demo.rs1use helios_engine::{Agent, Config, ForestBuilder};
7
8#[tokio::main]
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 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 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 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}