Agent

Struct Agent 

Source
pub struct Agent { /* private fields */ }

Implementations§

Source§

impl Agent

Source

pub async fn new(name: impl Into<String>, config: Config) -> Result<Self>

Source

pub fn builder(name: impl Into<String>) -> AgentBuilder

Examples found in repository?
examples/basic_chat.rs (line 9)
4async fn main() -> helios_engine::Result<()> {
5    // Load configuration
6    let config = Config::from_file("config.toml")?;
7
8    // Create a simple agent
9    let mut agent = Agent::builder("BasicAgent")
10        .config(config)
11        .system_prompt("You are a helpful assistant.")
12        .build()
13        .await?;
14
15    // Send a message
16    let response = agent.chat("Hello! How are you?").await?;
17    println!("Agent: {}", response);
18
19    // Continue the conversation
20    let response = agent.chat("What can you help me with?").await?;
21    println!("Agent: {}", response);
22
23    Ok(())
24}
More examples
Hide additional examples
examples/custom_tool.rs (line 70)
65async fn main() -> helios_engine::Result<()> {
66    // Load configuration
67    let config = Config::from_file("config.toml")?;
68
69    // Create an agent with custom tool
70    let mut agent = Agent::builder("WeatherAgent")
71        .config(config)
72        .system_prompt("You are a helpful weather assistant. Use the weather tool to answer questions about weather.")
73        .tool(Box::new(WeatherTool))
74        .build()
75        .await?;
76
77    // Ask about weather
78    let response = agent.chat("What's the weather like in New York?").await?;
79    println!("Agent: {}\n", response);
80
81    let response = agent.chat("How about in London, but in celsius?").await?;
82    println!("Agent: {}\n", response);
83
84    Ok(())
85}
examples/agent_with_tools.rs (line 9)
4async fn main() -> helios_engine::Result<()> {
5    // Load configuration
6    let config = Config::from_file("config.toml")?;
7
8    // Create an agent with tools
9    let mut agent = Agent::builder("ToolAgent")
10        .config(config)
11        .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
12        .tool(Box::new(CalculatorTool))
13        .tool(Box::new(EchoTool))
14        .max_iterations(5)
15        .build()
16        .await?;
17
18    println!(
19        "Available tools: {:?}\n",
20        agent.tool_registry().list_tools()
21    );
22
23    // Test calculator tool
24    let response = agent.chat("What is 25 * 4 + 10?").await?;
25    println!("Agent: {}\n", response);
26
27    // Test echo tool
28    let response = agent
29        .chat("Can you echo this message: 'Hello from Helios!'")
30        .await?;
31    println!("Agent: {}\n", response);
32
33    Ok(())
34}
examples/multiple_agents.rs (line 9)
4async fn main() -> helios_engine::Result<()> {
5    // Load configuration
6    let config = Config::from_file("config.toml")?;
7
8    // Create multiple agents with different personalities
9    let mut math_agent = Agent::builder("MathAgent")
10        .config(config.clone())
11        .system_prompt("You are a math expert. You love numbers and equations.")
12        .tool(Box::new(CalculatorTool))
13        .build()
14        .await?;
15
16    let mut creative_agent = Agent::builder("CreativeAgent")
17        .config(config)
18        .system_prompt("You are a creative writer who loves storytelling and poetry.")
19        .build()
20        .await?;
21
22    println!("=== Math Agent ===");
23    let response = math_agent.chat("What is the square root of 144?").await?;
24    println!("Math Agent: {}\n", response);
25
26    println!("=== Creative Agent ===");
27    let response = creative_agent
28        .chat("Write a haiku about programming.")
29        .await?;
30    println!("Creative Agent: {}\n", response);
31
32    Ok(())
33}
examples/agent_with_file_tools.rs (line 22)
11async fn main() -> helios_engine::Result<()> {
12    println!("šŸš€ Helios Engine - Agent with File Tools Example");
13    println!("=================================================\n");
14
15    // Load configuration
16    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    // Create agent with file tools
22    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    // Set initial session memory
41    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    // Example 1: Search for Rust files
46    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    // Update session memory
55    agent.increment_tasks_completed();
56    agent.set_memory("last_task", "file_search");
57
58    // Example 2: Read a specific file
59    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    // Update session memory
68    agent.increment_tasks_completed();
69    agent.set_memory("last_task", "file_read");
70
71    // Example 3: Show session summary
72    println!("\nExample 3: Session Summary");
73    println!("==========================\n");
74
75    println!("{}", agent.get_session_summary());
76
77    // Example 4: Check session memory
78    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}
examples/complete_demo.rs (line 24)
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}
Source

pub fn name(&self) -> &str

Source

pub fn set_system_prompt(&mut self, prompt: impl Into<String>)

Source

pub fn register_tool(&mut self, tool: Box<dyn Tool>)

Source

pub fn tool_registry(&self) -> &ToolRegistry

Examples found in repository?
examples/agent_with_tools.rs (line 20)
4async fn main() -> helios_engine::Result<()> {
5    // Load configuration
6    let config = Config::from_file("config.toml")?;
7
8    // Create an agent with tools
9    let mut agent = Agent::builder("ToolAgent")
10        .config(config)
11        .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
12        .tool(Box::new(CalculatorTool))
13        .tool(Box::new(EchoTool))
14        .max_iterations(5)
15        .build()
16        .await?;
17
18    println!(
19        "Available tools: {:?}\n",
20        agent.tool_registry().list_tools()
21    );
22
23    // Test calculator tool
24    let response = agent.chat("What is 25 * 4 + 10?").await?;
25    println!("Agent: {}\n", response);
26
27    // Test echo tool
28    let response = agent
29        .chat("Can you echo this message: 'Hello from Helios!'")
30        .await?;
31    println!("Agent: {}\n", response);
32
33    Ok(())
34}
Source

pub fn tool_registry_mut(&mut self) -> &mut ToolRegistry

Source

pub fn chat_session(&self) -> &ChatSession

Source

pub fn chat_session_mut(&mut self) -> &mut ChatSession

Source

pub fn clear_history(&mut self)

Source

pub async fn send_message( &mut self, message: impl Into<String>, ) -> Result<String>

Source

pub async fn chat(&mut self, message: impl Into<String>) -> Result<String>

Examples found in repository?
examples/basic_chat.rs (line 16)
4async fn main() -> helios_engine::Result<()> {
5    // Load configuration
6    let config = Config::from_file("config.toml")?;
7
8    // Create a simple agent
9    let mut agent = Agent::builder("BasicAgent")
10        .config(config)
11        .system_prompt("You are a helpful assistant.")
12        .build()
13        .await?;
14
15    // Send a message
16    let response = agent.chat("Hello! How are you?").await?;
17    println!("Agent: {}", response);
18
19    // Continue the conversation
20    let response = agent.chat("What can you help me with?").await?;
21    println!("Agent: {}", response);
22
23    Ok(())
24}
More examples
Hide additional examples
examples/custom_tool.rs (line 78)
65async fn main() -> helios_engine::Result<()> {
66    // Load configuration
67    let config = Config::from_file("config.toml")?;
68
69    // Create an agent with custom tool
70    let mut agent = Agent::builder("WeatherAgent")
71        .config(config)
72        .system_prompt("You are a helpful weather assistant. Use the weather tool to answer questions about weather.")
73        .tool(Box::new(WeatherTool))
74        .build()
75        .await?;
76
77    // Ask about weather
78    let response = agent.chat("What's the weather like in New York?").await?;
79    println!("Agent: {}\n", response);
80
81    let response = agent.chat("How about in London, but in celsius?").await?;
82    println!("Agent: {}\n", response);
83
84    Ok(())
85}
examples/agent_with_tools.rs (line 24)
4async fn main() -> helios_engine::Result<()> {
5    // Load configuration
6    let config = Config::from_file("config.toml")?;
7
8    // Create an agent with tools
9    let mut agent = Agent::builder("ToolAgent")
10        .config(config)
11        .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
12        .tool(Box::new(CalculatorTool))
13        .tool(Box::new(EchoTool))
14        .max_iterations(5)
15        .build()
16        .await?;
17
18    println!(
19        "Available tools: {:?}\n",
20        agent.tool_registry().list_tools()
21    );
22
23    // Test calculator tool
24    let response = agent.chat("What is 25 * 4 + 10?").await?;
25    println!("Agent: {}\n", response);
26
27    // Test echo tool
28    let response = agent
29        .chat("Can you echo this message: 'Hello from Helios!'")
30        .await?;
31    println!("Agent: {}\n", response);
32
33    Ok(())
34}
examples/multiple_agents.rs (line 23)
4async fn main() -> helios_engine::Result<()> {
5    // Load configuration
6    let config = Config::from_file("config.toml")?;
7
8    // Create multiple agents with different personalities
9    let mut math_agent = Agent::builder("MathAgent")
10        .config(config.clone())
11        .system_prompt("You are a math expert. You love numbers and equations.")
12        .tool(Box::new(CalculatorTool))
13        .build()
14        .await?;
15
16    let mut creative_agent = Agent::builder("CreativeAgent")
17        .config(config)
18        .system_prompt("You are a creative writer who loves storytelling and poetry.")
19        .build()
20        .await?;
21
22    println!("=== Math Agent ===");
23    let response = math_agent.chat("What is the square root of 144?").await?;
24    println!("Math Agent: {}\n", response);
25
26    println!("=== Creative Agent ===");
27    let response = creative_agent
28        .chat("Write a haiku about programming.")
29        .await?;
30    println!("Creative Agent: {}\n", response);
31
32    Ok(())
33}
examples/agent_with_file_tools.rs (line 50)
11async fn main() -> helios_engine::Result<()> {
12    println!("šŸš€ Helios Engine - Agent with File Tools Example");
13    println!("=================================================\n");
14
15    // Load configuration
16    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    // Create agent with file tools
22    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    // Set initial session memory
41    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    // Example 1: Search for Rust files
46    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    // Update session memory
55    agent.increment_tasks_completed();
56    agent.set_memory("last_task", "file_search");
57
58    // Example 2: Read a specific file
59    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    // Update session memory
68    agent.increment_tasks_completed();
69    agent.set_memory("last_task", "file_read");
70
71    // Example 3: Show session summary
72    println!("\nExample 3: Session Summary");
73    println!("==========================\n");
74
75    println!("{}", agent.get_session_summary());
76
77    // Example 4: Check session memory
78    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}
examples/complete_demo.rs (line 57)
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}
Source

pub fn set_max_iterations(&mut self, max: usize)

Source

pub fn get_session_summary(&self) -> String

Examples found in repository?
examples/agent_with_file_tools.rs (line 75)
11async fn main() -> helios_engine::Result<()> {
12    println!("šŸš€ Helios Engine - Agent with File Tools Example");
13    println!("=================================================\n");
14
15    // Load configuration
16    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    // Create agent with file tools
22    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    // Set initial session memory
41    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    // Example 1: Search for Rust files
46    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    // Update session memory
55    agent.increment_tasks_completed();
56    agent.set_memory("last_task", "file_search");
57
58    // Example 2: Read a specific file
59    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    // Update session memory
68    agent.increment_tasks_completed();
69    agent.set_memory("last_task", "file_read");
70
71    // Example 3: Show session summary
72    println!("\nExample 3: Session Summary");
73    println!("==========================\n");
74
75    println!("{}", agent.get_session_summary());
76
77    // Example 4: Check session memory
78    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}
More examples
Hide additional examples
examples/complete_demo.rs (line 82)
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}
Source

pub fn clear_memory(&mut self)

Source

pub fn set_memory(&mut self, key: impl Into<String>, value: impl Into<String>)

Examples found in repository?
examples/agent_with_file_tools.rs (line 41)
11async fn main() -> helios_engine::Result<()> {
12    println!("šŸš€ Helios Engine - Agent with File Tools Example");
13    println!("=================================================\n");
14
15    // Load configuration
16    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    // Create agent with file tools
22    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    // Set initial session memory
41    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    // Example 1: Search for Rust files
46    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    // Update session memory
55    agent.increment_tasks_completed();
56    agent.set_memory("last_task", "file_search");
57
58    // Example 2: Read a specific file
59    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    // Update session memory
68    agent.increment_tasks_completed();
69    agent.set_memory("last_task", "file_read");
70
71    // Example 3: Show session summary
72    println!("\nExample 3: Session Summary");
73    println!("==========================\n");
74
75    println!("{}", agent.get_session_summary());
76
77    // Example 4: Check session memory
78    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}
More examples
Hide additional examples
examples/complete_demo.rs (line 43)
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}
Source

pub fn get_memory(&self, key: &str) -> Option<&String>

Examples found in repository?
examples/agent_with_file_tools.rs (line 81)
11async fn main() -> helios_engine::Result<()> {
12    println!("šŸš€ Helios Engine - Agent with File Tools Example");
13    println!("=================================================\n");
14
15    // Load configuration
16    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    // Create agent with file tools
22    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    // Set initial session memory
41    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    // Example 1: Search for Rust files
46    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    // Update session memory
55    agent.increment_tasks_completed();
56    agent.set_memory("last_task", "file_search");
57
58    // Example 2: Read a specific file
59    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    // Update session memory
68    agent.increment_tasks_completed();
69    agent.set_memory("last_task", "file_read");
70
71    // Example 3: Show session summary
72    println!("\nExample 3: Session Summary");
73    println!("==========================\n");
74
75    println!("{}", agent.get_session_summary());
76
77    // Example 4: Check session memory
78    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}
More examples
Hide additional examples
examples/complete_demo.rs (line 113)
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}
Source

pub fn remove_memory(&mut self, key: &str) -> Option<String>

Source

pub fn increment_counter(&mut self, key: &str) -> u32

Examples found in repository?
examples/complete_demo.rs (line 61)
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}
Source

pub fn increment_tasks_completed(&mut self) -> u32

Examples found in repository?
examples/agent_with_file_tools.rs (line 55)
11async fn main() -> helios_engine::Result<()> {
12    println!("šŸš€ Helios Engine - Agent with File Tools Example");
13    println!("=================================================\n");
14
15    // Load configuration
16    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    // Create agent with file tools
22    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    // Set initial session memory
41    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    // Example 1: Search for Rust files
46    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    // Update session memory
55    agent.increment_tasks_completed();
56    agent.set_memory("last_task", "file_search");
57
58    // Example 2: Read a specific file
59    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    // Update session memory
68    agent.increment_tasks_completed();
69    agent.set_memory("last_task", "file_read");
70
71    // Example 3: Show session summary
72    println!("\nExample 3: Session Summary");
73    println!("==========================\n");
74
75    println!("{}", agent.get_session_summary());
76
77    // Example 4: Check session memory
78    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}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more