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