react_agent/
react_agent.rs

1//! # Example: ReAct Agent
2//!
3//! This example demonstrates the ReAct (Reasoning and Acting) feature.
4//! When enabled, the agent will reason about the task and create a plan
5//! before taking actions, leading to more thoughtful and systematic problem-solving.
6
7use helios_engine::{Agent, CalculatorTool, Config, EchoTool, FileReadTool};
8
9#[tokio::main]
10async fn main() -> helios_engine::Result<()> {
11    println!("🧠 Helios Engine - ReAct Agent Example");
12    println!("======================================\n");
13
14    // Load configuration from `config.toml`.
15    let config = Config::from_file("config.toml")?;
16
17    // Create an agent with ReAct mode enabled.
18    // Notice the simple `.react()` call in the builder pattern!
19    let mut agent = Agent::builder("ReActAgent")
20        .config(config)
21        .system_prompt(
22            "You are a helpful assistant that thinks carefully before acting. \
23             Use your reasoning to plan your approach.",
24        )
25        .tools(vec![
26            Box::new(CalculatorTool),
27            Box::new(EchoTool),
28            Box::new(FileReadTool),
29        ])
30        .react() // Enable ReAct mode - that's all it takes!
31        .max_iterations(5)
32        .build()
33        .await?;
34
35    println!(
36        "Available tools: {:?}\n",
37        agent.tool_registry().list_tools()
38    );
39
40    println!("═══════════════════════════════════════════════════════════");
41    println!("Example 1: Mathematical Problem");
42    println!("═══════════════════════════════════════════════════════════\n");
43
44    // --- Test 1: Math problem requiring reasoning ---
45    println!("User: I need to calculate (25 * 4) + (100 / 5). Can you help?\n");
46    let response = agent
47        .chat("I need to calculate (25 * 4) + (100 / 5). Can you help?")
48        .await?;
49    println!("\nAgent: {}\n", response);
50
51    println!("═══════════════════════════════════════════════════════════");
52    println!("Example 2: Multi-step Task");
53    println!("═══════════════════════════════════════════════════════════\n");
54
55    // --- Test 2: Multi-step task ---
56    println!("User: First calculate 15 * 7, then echo the result back to me.\n");
57    let response = agent
58        .chat("First calculate 15 * 7, then echo the result back to me.")
59        .await?;
60    println!("\nAgent: {}\n", response);
61
62    println!("═══════════════════════════════════════════════════════════");
63    println!(" ReAct Demo Complete!");
64    println!("═══════════════════════════════════════════════════════════");
65    println!("\nNotice how the agent:");
66    println!("  1. 💭 First reasons about the task");
67    println!("  2. 📋 Creates a plan");
68    println!("  3. ⚡ Then executes the actions\n");
69    println!("This leads to more thoughtful and systematic problem-solving!");
70
71    Ok(())
72}