forest_simple_demo/
forest_simple_demo.rs

1//! Simple Forest of Agents Demo
2//!
3//! This is a simpler example that demonstrates the planning system
4//! with more straightforward prompts and better reliability.
5
6use 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    // 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}