pub struct Config {
pub llm: LLMConfig,
pub local: Option<LocalConfig>,
}Fields§
§llm: LLMConfig§local: Option<LocalConfig>Implementations§
Source§impl Config
impl Config
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
Load configuration from a TOML file
Examples found in repository?
examples/basic_chat.rs (line 6)
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
examples/custom_tool.rs (line 67)
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 6)
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 6)
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 16)
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 let tasks = agent.get_memory("tasks_completed")
56 .and_then(|v| v.parse::<u32>().ok())
57 .unwrap_or(0);
58 agent.set_memory("tasks_completed", (tasks + 1).to_string());
59 agent.set_memory("last_task", "file_search");
60
61 // Example 2: Read a specific file
62 println!("\nExample 2: Reading file contents");
63 println!("==================================\n");
64
65 let response = agent
66 .chat("Read the contents of src/lib.rs and give me a summary")
67 .await?;
68 println!("Agent: {}\n", response);
69
70 // Update session memory
71 let tasks = agent.get_memory("tasks_completed")
72 .and_then(|v| v.parse::<u32>().ok())
73 .unwrap_or(0);
74 agent.set_memory("tasks_completed", (tasks + 1).to_string());
75 agent.set_memory("last_task", "file_read");
76
77 // Example 3: Show session summary
78 println!("\nExample 3: Session Summary");
79 println!("==========================\n");
80
81 println!("{}", agent.get_session_summary());
82
83 // Example 4: Check session memory
84 println!("\nExample 4: Checking Session Memory");
85 println!("===================================\n");
86
87 println!("Working directory: {}", agent.get_memory("working_directory").unwrap_or(&"unknown".to_string()));
88 println!("Tasks completed: {}", agent.get_memory("tasks_completed").unwrap_or(&"0".to_string()));
89 println!("Last task: {}", agent.get_memory("last_task").unwrap_or(&"none".to_string()));
90
91 println!("\n✅ Example completed successfully!");
92 println!("\n💡 Key Features Demonstrated:");
93 println!(" • File search with pattern matching and content search");
94 println!(" • File reading with line range support");
95 println!(" • File editing with find/replace functionality");
96 println!(" • Session memory for tracking agent state");
97 println!(" • Streaming responses (works with both local and remote models)");
98
99 Ok(())
100}examples/complete_demo.rs (line 17)
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 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 // Demo 2: Read a file
68 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 // Update memory
79 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 // Demo 3: Show session summary
86 println!("\nDemo 3: Session Summary");
87 println!("=======================\n");
88 println!("{}", agent.get_session_summary());
89
90 // Demo 4: Interactive mode
91 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 // Send message to agent with streaming
152 print!("\nAgent: ");
153 io::stdout().flush()?;
154
155 match agent.chat(input).await {
156 Ok(response) => {
157 println!("{}", response);
158
159 // Update memory after each interaction
160 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 // Final summary
172 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}Sourcepub fn new_default() -> Self
pub fn new_default() -> Self
Create a default configuration
Examples found in repository?
examples/agent_with_file_tools.rs (line 18)
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 let tasks = agent.get_memory("tasks_completed")
56 .and_then(|v| v.parse::<u32>().ok())
57 .unwrap_or(0);
58 agent.set_memory("tasks_completed", (tasks + 1).to_string());
59 agent.set_memory("last_task", "file_search");
60
61 // Example 2: Read a specific file
62 println!("\nExample 2: Reading file contents");
63 println!("==================================\n");
64
65 let response = agent
66 .chat("Read the contents of src/lib.rs and give me a summary")
67 .await?;
68 println!("Agent: {}\n", response);
69
70 // Update session memory
71 let tasks = agent.get_memory("tasks_completed")
72 .and_then(|v| v.parse::<u32>().ok())
73 .unwrap_or(0);
74 agent.set_memory("tasks_completed", (tasks + 1).to_string());
75 agent.set_memory("last_task", "file_read");
76
77 // Example 3: Show session summary
78 println!("\nExample 3: Session Summary");
79 println!("==========================\n");
80
81 println!("{}", agent.get_session_summary());
82
83 // Example 4: Check session memory
84 println!("\nExample 4: Checking Session Memory");
85 println!("===================================\n");
86
87 println!("Working directory: {}", agent.get_memory("working_directory").unwrap_or(&"unknown".to_string()));
88 println!("Tasks completed: {}", agent.get_memory("tasks_completed").unwrap_or(&"0".to_string()));
89 println!("Last task: {}", agent.get_memory("last_task").unwrap_or(&"none".to_string()));
90
91 println!("\n✅ Example completed successfully!");
92 println!("\n💡 Key Features Demonstrated:");
93 println!(" • File search with pattern matching and content search");
94 println!(" • File reading with line range support");
95 println!(" • File editing with find/replace functionality");
96 println!(" • Session memory for tracking agent state");
97 println!(" • Streaming responses (works with both local and remote models)");
98
99 Ok(())
100}More examples
examples/complete_demo.rs (line 19)
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 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 // Demo 2: Read a file
68 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 // Update memory
79 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 // Demo 3: Show session summary
86 println!("\nDemo 3: Session Summary");
87 println!("=======================\n");
88 println!("{}", agent.get_session_summary());
89
90 // Demo 4: Interactive mode
91 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 // Send message to agent with streaming
152 print!("\nAgent: ");
153 io::stdout().flush()?;
154
155 match agent.chat(input).await {
156 Ok(response) => {
157 println!("{}", response);
158
159 // Update memory after each interaction
160 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 // Final summary
172 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}Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more