complete_demo/
complete_demo.rs

1//! # Example: Complete Demo
2//!
3//! This example showcases all the new features of the Helios Engine working together:
4//! 1.  **Streaming Responses**: For both local and remote models.
5//! 2.  **File Management Tools**: `FileSearchTool`, `FileReadTool`, `FileEditTool`, and `FileWriteTool`.
6//! 3.  **Session Memory**: To track the agent's state and conversation history.
7
8use helios_engine::{Agent, Config, FileEditTool, FileReadTool, FileSearchTool, FileWriteTool};
9use std::io::{self, Write};
10
11#[tokio::main]
12async fn main() -> helios_engine::Result<()> {
13    println!("šŸš€ Helios Engine - Complete Feature Demo");
14    println!("=========================================\n");
15
16    // Load configuration from `config.toml` or use default.
17    let config = Config::from_file("config.toml").unwrap_or_else(|_| {
18        println!("⚠ No config.toml found, using default configuration");
19        Config::new_default()
20    });
21
22    // Create an agent named "SmartAssistant" and equip it with all file tools.
23    println!("šŸ“¦ Creating agent with file tools...");
24    let mut agent = Agent::builder("SmartAssistant")
25        .config(config)
26        .system_prompt(
27            "You are an intelligent assistant with file management capabilities. \
28             You can search files, read them, and make edits. Always explain what \
29             you're doing and track important information in session memory.",
30        )
31        .tool(Box::new(FileSearchTool))
32        .tool(Box::new(FileReadTool))
33        .tool(Box::new(FileEditTool))
34        .tool(Box::new(FileWriteTool))
35        .max_iterations(10)
36        .build()
37        .await?;
38
39    println!("āœ“ Agent created successfully!\n");
40
41    // Initialize session memory with some starting values.
42    println!("🧠 Initializing session memory...");
43    agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
44    agent.set_memory(
45        "working_directory",
46        std::env::current_dir()?.display().to_string(),
47    );
48    agent.set_memory("files_accessed", "0");
49    agent.set_memory("edits_made", "0");
50    println!("āœ“ Session memory initialized\n");
51
52    // --- Demo 1: Search for files with streaming response ---
53    println!("Demo 1: File Search with Streaming");
54    println!("===================================");
55    println!("User: Find all Rust example files\n");
56
57    print!("Agent: ");
58    io::stdout().flush()?;
59
60    let response1 = agent
61        .chat("Find all Rust example files in the examples directory")
62        .await?;
63    println!("{}\n", response1);
64
65    // Update session memory after the task.
66    agent.increment_counter("files_accessed");
67    agent.set_memory("last_action", "file_search");
68
69    // --- Demo 2: Read a file ---
70    println!("\nDemo 2: Reading File Contents");
71    println!("==============================");
72    println!("User: Read the NEW_FEATURES.md file and summarize the key points\n");
73
74    print!("Agent: ");
75    io::stdout().flush()?;
76
77    let response2 = agent
78        .chat("Read the NEW_FEATURES.md file and give me a brief summary of what's new")
79        .await?;
80    println!("{}\n", response2);
81
82    // Update session memory after the task.
83    agent.increment_counter("files_accessed");
84    agent.set_memory("last_action", "file_read");
85
86    // --- Demo 3: Show session summary ---
87    println!("\nDemo 3: Session Summary");
88    println!("=======================\n");
89    println!("{}", agent.get_session_summary());
90
91    // --- Demo 4: Interactive mode ---
92    println!("\n\nDemo 4: Interactive Mode");
93    println!("========================");
94    println!("You can now interact with the agent. Type 'exit' to quit.\n");
95
96    loop {
97        print!("\nYou: ");
98        io::stdout().flush()?;
99
100        let mut input = String::new();
101        io::stdin().read_line(&mut input)?;
102        let input = input.trim();
103
104        if input.is_empty() {
105            continue;
106        }
107
108        match input.to_lowercase().as_str() {
109            "exit" | "quit" => {
110                println!("\nšŸ‘‹ Goodbye!");
111                break;
112            }
113            "summary" => {
114                println!("\nšŸ“Š Session Summary:");
115                println!("{}", agent.get_session_summary());
116                continue;
117            }
118            "memory" => {
119                println!("\n🧠 Session Memory:");
120                if let Some(start) = agent.get_memory("session_start") {
121                    println!("  Session started: {}", start);
122                }
123                if let Some(dir) = agent.get_memory("working_directory") {
124                    println!("  Working directory: {}", dir);
125                }
126                if let Some(files) = agent.get_memory("files_accessed") {
127                    println!("  Files accessed: {}", files);
128                }
129                if let Some(edits) = agent.get_memory("edits_made") {
130                    println!("  Edits made: {}", edits);
131                }
132                if let Some(action) = agent.get_memory("last_action") {
133                    println!("  Last action: {}", action);
134                }
135                continue;
136            }
137            "help" => {
138                println!("\nšŸ“– Available Commands:");
139                println!("  exit, quit  - Exit the demo");
140                println!("  summary     - Show session summary");
141                println!("  memory      - Show session memory");
142                println!("  help        - Show this help");
143                println!("\nšŸ’” Try asking the agent to:");
144                println!("  • Search for specific files");
145                println!("  • Read file contents");
146                println!("  • Summarize what it has done");
147                continue;
148            }
149            _ => {}
150        }
151
152        // Send message to agent with streaming.
153        print!("\nAgent: ");
154        io::stdout().flush()?;
155
156        match agent.chat(input).await {
157            Ok(response) => {
158                println!("{}", response);
159
160                // Update memory after each interaction.
161                agent.increment_counter("files_accessed");
162            }
163            Err(e) => {
164                eprintln!("\nāŒ Error: {}", e);
165            }
166        }
167    }
168
169    // --- Final summary ---
170    println!("\nšŸ“Š Final Session Summary:");
171    println!("{}", agent.get_session_summary());
172
173    println!("\nāœ… Demo completed successfully!");
174    println!("\nšŸ’” Features Demonstrated:");
175    println!("  āœ“ Streaming responses (local/remote models)");
176    println!("  āœ“ File search with pattern matching");
177    println!("  āœ“ File reading with summaries");
178    println!("  āœ“ Session memory tracking");
179    println!("  āœ“ Interactive conversation");
180    println!("  āœ“ Real-time progress updates");
181
182    Ok(())
183}