complete_demo/
complete_demo.rs

1/// Complete Demo: All New Features
2///
3/// This example demonstrates all three new features working together:
4/// 1. Streaming for local models
5/// 2. File management tools
6/// 3. Session memory
7
8use helios_engine::{Agent, Config, FileSearchTool, FileReadTool, FileEditTool, 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
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 agent 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
42    println!("🧠 Initializing session memory...");
43    agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
44    agent.set_memory("working_directory", std::env::current_dir()?.display().to_string());
45    agent.set_memory("files_accessed", "0");
46    agent.set_memory("edits_made", "0");
47    println!("āœ“ Session memory initialized\n");
48
49    // Demo 1: Search for files with streaming response
50    println!("Demo 1: File Search with Streaming");
51    println!("===================================");
52    println!("User: Find all Rust example files\n");
53    
54    print!("Agent: ");
55    io::stdout().flush()?;
56
57    let response1 = agent.chat("Find all Rust example files in the examples directory").await?;
58    println!("{}\n", response1);
59
60    // Update memory
61    agent.increment_counter("files_accessed");
62    agent.set_memory("last_action", "file_search");
63
64    // Demo 2: Read a file
65    println!("\nDemo 2: Reading File Contents");
66    println!("==============================");
67    println!("User: Read the NEW_FEATURES.md file and summarize the key points\n");
68    
69    print!("Agent: ");
70    io::stdout().flush()?;
71
72    let response2 = agent.chat("Read the NEW_FEATURES.md file and give me a brief summary of what's new").await?;
73    println!("{}\n", response2);
74
75    // Update memory
76    agent.increment_counter("files_accessed");
77    agent.set_memory("last_action", "file_read");
78
79    // Demo 3: Show session summary
80    println!("\nDemo 3: Session Summary");
81    println!("=======================\n");
82    println!("{}", agent.get_session_summary());
83
84    // Demo 4: Interactive mode
85    println!("\n\nDemo 4: Interactive Mode");
86    println!("========================");
87    println!("You can now interact with the agent. Type 'exit' to quit.\n");
88
89    loop {
90        print!("\nYou: ");
91        io::stdout().flush()?;
92
93        let mut input = String::new();
94        io::stdin().read_line(&mut input)?;
95        let input = input.trim();
96
97        if input.is_empty() {
98            continue;
99        }
100
101        match input.to_lowercase().as_str() {
102            "exit" | "quit" => {
103                println!("\nšŸ‘‹ Goodbye!");
104                break;
105            }
106            "summary" => {
107                println!("\nšŸ“Š Session Summary:");
108                println!("{}", agent.get_session_summary());
109                continue;
110            }
111            "memory" => {
112                println!("\n🧠 Session Memory:");
113                if let Some(start) = agent.get_memory("session_start") {
114                    println!("  Session started: {}", start);
115                }
116                if let Some(dir) = agent.get_memory("working_directory") {
117                    println!("  Working directory: {}", dir);
118                }
119                if let Some(files) = agent.get_memory("files_accessed") {
120                    println!("  Files accessed: {}", files);
121                }
122                if let Some(edits) = agent.get_memory("edits_made") {
123                    println!("  Edits made: {}", edits);
124                }
125                if let Some(action) = agent.get_memory("last_action") {
126                    println!("  Last action: {}", action);
127                }
128                continue;
129            }
130            "help" => {
131                println!("\nšŸ“– Available Commands:");
132                println!("  exit, quit  - Exit the demo");
133                println!("  summary     - Show session summary");
134                println!("  memory      - Show session memory");
135                println!("  help        - Show this help");
136                println!("\nšŸ’” Try asking the agent to:");
137                println!("  • Search for specific files");
138                println!("  • Read file contents");
139                println!("  • Summarize what it has done");
140                continue;
141            }
142            _ => {}
143        }
144
145        // Send message to agent with streaming
146        print!("\nAgent: ");
147        io::stdout().flush()?;
148
149        match agent.chat(input).await {
150            Ok(response) => {
151                println!("{}", response);
152                
153                // Update memory after each interaction
154                agent.increment_counter("files_accessed");
155            }
156            Err(e) => {
157                eprintln!("\nāŒ Error: {}", e);
158            }
159        }
160    }
161
162    // Final summary
163    println!("\nšŸ“Š Final Session Summary:");
164    println!("{}", agent.get_session_summary());
165
166    println!("\nāœ… Demo completed successfully!");
167    println!("\nšŸ’” Features Demonstrated:");
168    println!("  āœ“ Streaming responses (local/remote models)");
169    println!("  āœ“ File search with pattern matching");
170    println!("  āœ“ File reading with summaries");
171    println!("  āœ“ Session memory tracking");
172    println!("  āœ“ Interactive conversation");
173    println!("  āœ“ Real-time progress updates");
174
175    Ok(())
176}