agent_with_file_tools/
agent_with_file_tools.rs1use helios_engine::{Agent, Config, FileSearchTool, FileReadTool, FileEditTool, FileWriteTool};
9
10#[tokio::main]
11async fn main() -> helios_engine::Result<()> {
12 println!("š Helios Engine - Agent with File Tools Example");
13 println!("=================================================\n");
14
15 let config = Config::from_file("config.toml").unwrap_or_else(|_| {
17 println!("ā No config.toml found, using default configuration");
18 Config::new_default()
19 });
20
21 let mut agent = Agent::builder("FileAssistant")
23 .config(config)
24 .system_prompt(
25 "You are a helpful file management assistant. You can search for files, \
26 read file contents, and edit files. Always confirm with the user before \
27 making changes to files. Keep track of important session information."
28 )
29 .tool(Box::new(FileSearchTool))
30 .tool(Box::new(FileReadTool))
31 .tool(Box::new(FileEditTool))
32 .tool(Box::new(FileWriteTool))
33 .max_iterations(10)
34 .build()
35 .await?;
36
37 println!("ā Agent created with file tools");
38 println!("ā Available tools: file_search, file_read, file_edit, file_write\n");
39
40 agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
42 agent.set_memory("working_directory", std::env::current_dir()?.display().to_string());
43 agent.set_memory("tasks_completed", "0");
44
45 println!("Example 1: Searching for Rust files");
47 println!("====================================\n");
48
49 let response = agent
50 .chat("Find all Rust source files in the src directory")
51 .await?;
52 println!("Agent: {}\n", response);
53
54 agent.increment_tasks_completed();
56 agent.set_memory("last_task", "file_search");
57
58 println!("\nExample 2: Reading file contents");
60 println!("==================================\n");
61
62 let response = agent
63 .chat("Read the contents of src/lib.rs and give me a summary")
64 .await?;
65 println!("Agent: {}\n", response);
66
67 agent.increment_tasks_completed();
69 agent.set_memory("last_task", "file_read");
70
71 println!("\nExample 3: Session Summary");
73 println!("==========================\n");
74
75 println!("{}", agent.get_session_summary());
76
77 println!("\nExample 4: Checking Session Memory");
79 println!("===================================\n");
80
81 println!("Working directory: {}", agent.get_memory("working_directory").unwrap_or(&"unknown".to_string()));
82 println!("Tasks completed: {}", agent.get_memory("tasks_completed").unwrap_or(&"0".to_string()));
83 println!("Last task: {}", agent.get_memory("last_task").unwrap_or(&"none".to_string()));
84
85 println!("\nā
Example completed successfully!");
86 println!("\nš” Key Features Demonstrated:");
87 println!(" ⢠File search with pattern matching and content search");
88 println!(" ⢠File reading with line range support");
89 println!(" ⢠File editing with find/replace functionality");
90 println!(" ⢠Session memory for tracking agent state");
91 println!(" ⢠Streaming responses (works with both local and remote models)");
92
93 Ok(())
94}