react_comparison/
react_comparison.rs

1//! # Example: Comparing Agents With and Without ReAct
2//!
3//! This example demonstrates the difference between standard agents and ReAct agents
4//! by running the same queries through both and comparing their approaches.
5
6use helios_engine::{Agent, CalculatorTool, Config, EchoTool};
7
8#[tokio::main]
9async fn main() -> helios_engine::Result<()> {
10    println!("🔬 Helios Engine - ReAct Comparison Demo");
11    println!("=========================================\n");
12
13    let config1 = Config::from_file("config.toml")?;
14    let config2 = Config::from_file("config.toml")?;
15
16    // Create two identical agents, one with ReAct and one without
17    let mut standard_agent = Agent::builder("StandardAgent")
18        .config(config1)
19        .system_prompt("You are a helpful assistant with access to tools.")
20        .tools(vec![Box::new(CalculatorTool), Box::new(EchoTool)])
21        .build()
22        .await?;
23
24    let mut react_agent = Agent::builder("ReActAgent")
25        .config(config2)
26        .system_prompt("You are a helpful assistant with access to tools.")
27        .tools(vec![Box::new(CalculatorTool), Box::new(EchoTool)])
28        .react() // The only difference!
29        .build()
30        .await?;
31
32    println!(
33        "Tools available: {:?}\n",
34        standard_agent.tool_registry().list_tools()
35    );
36
37    // Test Case 1: Simple calculation
38    println!("═══════════════════════════════════════════════════════════");
39    println!("Test Case 1: Simple Mathematical Calculation");
40    println!("═══════════════════════════════════════════════════════════\n");
41
42    let query1 = "What is 25 * 8?";
43    println!("Query: {}\n", query1);
44
45    println!("--- STANDARD AGENT ---");
46    let response1 = standard_agent.chat(query1).await?;
47    println!("Response: {}\n", response1);
48
49    println!("--- REACT AGENT ---");
50    let response2 = react_agent.chat(query1).await?;
51    println!("Response: {}\n", response2);
52
53    // Test Case 2: Multi-step problem
54    println!("═══════════════════════════════════════════════════════════");
55    println!("Test Case 2: Multi-Step Problem");
56    println!("═══════════════════════════════════════════════════════════\n");
57
58    let query2 = "Calculate (15 + 25) * 3, then echo the result";
59    println!("Query: {}\n", query2);
60
61    println!("--- STANDARD AGENT ---");
62    let response3 = standard_agent.chat(query2).await?;
63    println!("Response: {}\n", response3);
64
65    println!("--- REACT AGENT ---");
66    let response4 = react_agent.chat(query2).await?;
67    println!("Response: {}\n", response4);
68
69    // Test Case 3: Complex multi-tool task
70    println!("═══════════════════════════════════════════════════════════");
71    println!("Test Case 3: Complex Multi-Tool Task");
72    println!("═══════════════════════════════════════════════════════════\n");
73
74    let query3 =
75        "First calculate 100 / 4, then multiply that by 3, and finally echo the final answer";
76    println!("Query: {}\n", query3);
77
78    println!("--- STANDARD AGENT ---");
79    let response5 = standard_agent.chat(query3).await?;
80    println!("Response: {}\n", response5);
81
82    println!("--- REACT AGENT ---");
83    let response6 = react_agent.chat(query3).await?;
84    println!("Response: {}\n", response6);
85
86    // Summary
87    println!("═══════════════════════════════════════════════════════════");
88    println!("📊 Comparison Summary");
89    println!("═══════════════════════════════════════════════════════════\n");
90
91    println!("STANDARD AGENT:");
92    println!("  ✓ Faster execution (no reasoning overhead)");
93    println!("  ✓ Direct tool usage");
94    println!("  ✗ No visible thought process");
95    println!("  ✗ May miss planning opportunities\n");
96
97    println!("REACT AGENT:");
98    println!("  ✓ Shows reasoning process (💭 ReAct Reasoning)");
99    println!("  ✓ Systematic approach to problems");
100    println!("  ✓ Better for complex tasks");
101    println!("  ✗ Slightly slower (extra LLM call)\n");
102
103    println!("WHEN TO USE:");
104    println!("  → Standard: Simple, direct tasks where speed matters");
105    println!("  → ReAct: Complex tasks, debugging, when you want transparency\n");
106
107    Ok(())
108}