complete_demo/
complete_demo.rs1use 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 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 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 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 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 let files_accessed = agent.get_memory("files_accessed")
62 .and_then(|v| v.parse::<u32>().ok())
63 .unwrap_or(0);
64 agent.set_memory("files_accessed", (files_accessed + 1).to_string());
65 agent.set_memory("last_action", "file_search");
66
67 println!("\nDemo 2: Reading File Contents");
69 println!("==============================");
70 println!("User: Read the NEW_FEATURES.md file and summarize the key points\n");
71
72 print!("Agent: ");
73 io::stdout().flush()?;
74
75 let response2 = agent.chat("Read the NEW_FEATURES.md file and give me a brief summary of what's new").await?;
76 println!("{}\n", response2);
77
78 let files_accessed = agent.get_memory("files_accessed")
80 .and_then(|v| v.parse::<u32>().ok())
81 .unwrap_or(0);
82 agent.set_memory("files_accessed", (files_accessed + 1).to_string());
83 agent.set_memory("last_action", "file_read");
84
85 println!("\nDemo 3: Session Summary");
87 println!("=======================\n");
88 println!("{}", agent.get_session_summary());
89
90 println!("\n\nDemo 4: Interactive Mode");
92 println!("========================");
93 println!("You can now interact with the agent. Type 'exit' to quit.\n");
94
95 loop {
96 print!("\nYou: ");
97 io::stdout().flush()?;
98
99 let mut input = String::new();
100 io::stdin().read_line(&mut input)?;
101 let input = input.trim();
102
103 if input.is_empty() {
104 continue;
105 }
106
107 match input.to_lowercase().as_str() {
108 "exit" | "quit" => {
109 println!("\nš Goodbye!");
110 break;
111 }
112 "summary" => {
113 println!("\nš Session Summary:");
114 println!("{}", agent.get_session_summary());
115 continue;
116 }
117 "memory" => {
118 println!("\nš§ Session Memory:");
119 if let Some(start) = agent.get_memory("session_start") {
120 println!(" Session started: {}", start);
121 }
122 if let Some(dir) = agent.get_memory("working_directory") {
123 println!(" Working directory: {}", dir);
124 }
125 if let Some(files) = agent.get_memory("files_accessed") {
126 println!(" Files accessed: {}", files);
127 }
128 if let Some(edits) = agent.get_memory("edits_made") {
129 println!(" Edits made: {}", edits);
130 }
131 if let Some(action) = agent.get_memory("last_action") {
132 println!(" Last action: {}", action);
133 }
134 continue;
135 }
136 "help" => {
137 println!("\nš Available Commands:");
138 println!(" exit, quit - Exit the demo");
139 println!(" summary - Show session summary");
140 println!(" memory - Show session memory");
141 println!(" help - Show this help");
142 println!("\nš” Try asking the agent to:");
143 println!(" ⢠Search for specific files");
144 println!(" ⢠Read file contents");
145 println!(" ⢠Summarize what it has done");
146 continue;
147 }
148 _ => {}
149 }
150
151 print!("\nAgent: ");
153 io::stdout().flush()?;
154
155 match agent.chat(input).await {
156 Ok(response) => {
157 println!("{}", response);
158
159 let files_accessed = agent.get_memory("files_accessed")
161 .and_then(|v| v.parse::<u32>().ok())
162 .unwrap_or(0);
163 agent.set_memory("files_accessed", (files_accessed + 1).to_string());
164 }
165 Err(e) => {
166 eprintln!("\nā Error: {}", e);
167 }
168 }
169 }
170
171 println!("\nš Final Session Summary:");
173 println!("{}", agent.get_session_summary());
174
175 println!("\nā
Demo completed successfully!");
176 println!("\nš” Features Demonstrated:");
177 println!(" ā Streaming responses (local/remote models)");
178 println!(" ā File search with pattern matching");
179 println!(" ā File reading with summaries");
180 println!(" ā Session memory tracking");
181 println!(" ā Interactive conversation");
182 println!(" ā Real-time progress updates");
183
184 Ok(())
185}