pub struct Agent { /* private fields */ }Expand description
Represents an LLM-powered agent that can chat, use tools, and manage a conversation.
Implementations§
Source§impl Agent
impl Agent
Sourcepub fn builder(name: impl Into<String>) -> AgentBuilder
pub fn builder(name: impl Into<String>) -> AgentBuilder
Examples found in repository?
10async fn main() -> helios_engine::Result<()> {
11 // Load configuration from `config.toml`.
12 let config = Config::from_file("config.toml")?;
13
14 // Create a simple agent named "BasicAgent".
15 let mut agent = Agent::builder("BasicAgent")
16 .config(config)
17 .system_prompt("You are a helpful assistant.")
18 .build()
19 .await?;
20
21 // --- Send a message to the agent ---
22 let response = agent.chat("Hello! How are you?").await?;
23 println!("Agent: {}", response);
24
25 // --- Continue the conversation ---
26 let response = agent.chat("What can you help me with?").await?;
27 println!("Agent: {}", response);
28
29 Ok(())
30}More examples
74async fn main() -> helios_engine::Result<()> {
75 // Load configuration from `config.toml`.
76 let config = Config::from_file("config.toml")?;
77
78 // Create an agent named "WeatherAgent" and equip it with the `WeatherTool`.
79 let mut agent = Agent::builder("WeatherAgent")
80 .config(config)
81 .system_prompt("You are a helpful weather assistant. Use the weather tool to answer questions about weather.")
82 .tool(Box::new(WeatherTool))
83 .build()
84 .await?;
85
86 // --- Ask the agent about the weather ---
87 let response = agent.chat("What's the weather like in New York?").await?;
88 println!("Agent: {}\n", response);
89
90 // --- Ask again, but with a different unit ---
91 let response = agent.chat("How about in London, but in celsius?").await?;
92 println!("Agent: {}\n", response);
93
94 Ok(())
95}9async fn main() -> helios_engine::Result<()> {
10 // Load configuration from `config.toml`.
11 let config = Config::from_file("config.toml")?;
12
13 // Create an agent named "ToolAgent" and equip it with the `CalculatorTool` and `EchoTool`.
14 let mut agent = Agent::builder("ToolAgent")
15 .config(config)
16 .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
17 .tool(Box::new(CalculatorTool))
18 .tool(Box::new(EchoTool))
19 .max_iterations(5)
20 .build()
21 .await?;
22
23 println!(
24 "Available tools: {:?}\n",
25 agent.tool_registry().list_tools()
26 );
27
28 // --- Test the calculator tool ---
29 let response = agent.chat("What is 25 * 4 + 10?").await?;
30 println!("Agent: {}\n", response);
31
32 // --- Test the echo tool ---
33 let response = agent
34 .chat("Can you echo this message: 'Hello from Helios!'")
35 .await?;
36 println!("Agent: {}\n", response);
37
38 Ok(())
39}9async fn main() -> helios_engine::Result<()> {
10 // Initialize tracing
11 tracing_subscriber::fmt()
12 .with_max_level(tracing::Level::INFO)
13 .init();
14
15 // Load configuration
16 let config = Config::from_file("config.toml")?;
17
18 // Create an agent with tools
19 let agent = Agent::builder("API Agent")
20 .config(config)
21 .system_prompt("You are a helpful AI assistant with access to a calculator tool.")
22 .tool(Box::new(CalculatorTool))
23 .max_iterations(5)
24 .build()
25 .await?;
26
27 // Start the server
28 println!("Starting server on http://127.0.0.1:8000");
29 println!("Try: curl http://127.0.0.1:8000/v1/chat/completions \\");
30 println!(" -H 'Content-Type: application/json' \\");
31 println!(" -d '{{\"model\": \"local-model\", \"messages\": [{{\"role\": \"user\", \"content\": \"What is 15 * 7?\"}}]}}'");
32
33 helios_engine::serve::start_server_with_agent(
34 agent,
35 "local-model".to_string(),
36 "127.0.0.1:8000",
37 )
38 .await?;
39
40 Ok(())
41}10async fn main() -> helios_engine::Result<()> {
11 // Load configuration from `config.toml`.
12 let config = Config::from_file("config.toml")?;
13
14 // --- Create multiple agents with different personalities and tools ---
15
16 // An agent specialized in math, equipped with a calculator tool.
17 let mut math_agent = Agent::builder("MathAgent")
18 .config(config.clone())
19 .system_prompt("You are a math expert. You love numbers and equations.")
20 .tool(Box::new(CalculatorTool))
21 .build()
22 .await?;
23
24 // A creative agent for writing and storytelling.
25 let mut creative_agent = Agent::builder("CreativeAgent")
26 .config(config)
27 .system_prompt("You are a creative writer who loves storytelling and poetry.")
28 .build()
29 .await?;
30
31 // --- Interact with the Math Agent ---
32 println!("=== Math Agent ===");
33 let response = math_agent.chat("What is the square root of 144?").await?;
34 println!("Math Agent: {}\n", response);
35
36 // --- Interact with the Creative Agent ---
37 println!("=== Creative Agent ===");
38 let response = creative_agent
39 .chat("Write a haiku about programming.")
40 .await?;
41 println!("Creative Agent: {}\n", response);
42
43 Ok(())
44}19async fn demonstrate_in_memory() -> helios_engine::Result<()> {
20 println!("=== IN-MEMORY RAG DEMONSTRATION ===\n");
21
22 let api_key = std::env::var("OPENAI_API_KEY").unwrap_or_else(|_| {
23 println!("⚠ Warning: OPENAI_API_KEY not set. Using placeholder.");
24 "your-api-key-here".to_string()
25 });
26
27 let config = Config::from_file("config.toml").unwrap_or_else(|_| Config::new_default());
28
29 // Create in-memory RAG tool
30 let rag_tool = RAGTool::new_in_memory("https://api.openai.com/v1/embeddings", &api_key);
31
32 let mut agent = Agent::builder("InMemoryAgent")
33 .config(config)
34 .system_prompt("You are a helpful assistant with in-memory RAG capabilities.")
35 .tool(Box::new(rag_tool))
36 .max_iterations(8)
37 .build()
38 .await?;
39
40 println!("✓ In-memory agent created\n");
41
42 // Add some documents
43 println!("Adding documents...");
44 agent.chat("Store: The capital of France is Paris.").await?;
45 agent
46 .chat("Store: The capital of Germany is Berlin.")
47 .await?;
48 agent.chat("Store: The capital of Italy is Rome.").await?;
49 println!("✓ Documents added\n");
50
51 // Search
52 println!("Searching...");
53 let response = agent.chat("What is the capital of Germany?").await?;
54 println!("Agent: {}\n", response);
55
56 println!("Advantages of in-memory:");
57 println!(" ✓ No external dependencies");
58 println!(" ✓ Fast and simple");
59 println!(" ✓ Perfect for development");
60 println!(" ✗ No persistence (data lost on restart)");
61 println!(" ✗ Limited scalability\n");
62
63 Ok(())
64}
65
66async fn demonstrate_qdrant() -> helios_engine::Result<()> {
67 println!("=== QDRANT RAG DEMONSTRATION ===\n");
68
69 let api_key = std::env::var("OPENAI_API_KEY").unwrap_or_else(|_| {
70 println!("⚠ Warning: OPENAI_API_KEY not set. Using placeholder.");
71 "your-api-key-here".to_string()
72 });
73
74 let config = Config::from_file("config.toml").unwrap_or_else(|_| Config::new_default());
75
76 // Create Qdrant RAG tool
77 let rag_tool = RAGTool::new_qdrant(
78 "http://localhost:6333",
79 "comparison_demo",
80 "https://api.openai.com/v1/embeddings",
81 &api_key,
82 );
83
84 let mut agent = Agent::builder("QdrantAgent")
85 .config(config)
86 .system_prompt("You are a helpful assistant with Qdrant RAG capabilities.")
87 .tool(Box::new(rag_tool))
88 .max_iterations(8)
89 .build()
90 .await?;
91
92 println!("✓ Qdrant agent created\n");
93
94 // Clear any existing data
95 println!("Clearing existing data...");
96 agent.chat("Clear all documents").await?;
97 println!("✓ Cleared\n");
98
99 // Add some documents
100 println!("Adding documents...");
101 agent
102 .chat("Store: The Eiffel Tower is located in Paris, France.")
103 .await?;
104 agent
105 .chat("Store: The Colosseum is located in Rome, Italy.")
106 .await?;
107 agent
108 .chat("Store: The Brandenburg Gate is located in Berlin, Germany.")
109 .await?;
110 println!("✓ Documents added\n");
111
112 // Search
113 println!("Searching...");
114 let response = agent.chat("What famous landmark is in Berlin?").await?;
115 println!("Agent: {}\n", response);
116
117 println!("Advantages of Qdrant:");
118 println!(" ✓ Persistent storage");
119 println!(" ✓ Highly scalable");
120 println!(" ✓ Production-ready");
121 println!(" ✓ Advanced features (filtering, etc.)");
122 println!(" ✗ Requires external service");
123 println!(" ✗ More complex setup\n");
124
125 Ok(())
126}Sourcepub fn set_system_prompt(&mut self, prompt: impl Into<String>)
pub fn set_system_prompt(&mut self, prompt: impl Into<String>)
Sourcepub fn register_tool(&mut self, tool: Box<dyn Tool>)
pub fn register_tool(&mut self, tool: Box<dyn Tool>)
Sourcepub fn tool_registry(&self) -> &ToolRegistry
pub fn tool_registry(&self) -> &ToolRegistry
Returns a reference to the agent’s tool registry.
Examples found in repository?
9async fn main() -> helios_engine::Result<()> {
10 // Load configuration from `config.toml`.
11 let config = Config::from_file("config.toml")?;
12
13 // Create an agent named "ToolAgent" and equip it with the `CalculatorTool` and `EchoTool`.
14 let mut agent = Agent::builder("ToolAgent")
15 .config(config)
16 .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
17 .tool(Box::new(CalculatorTool))
18 .tool(Box::new(EchoTool))
19 .max_iterations(5)
20 .build()
21 .await?;
22
23 println!(
24 "Available tools: {:?}\n",
25 agent.tool_registry().list_tools()
26 );
27
28 // --- Test the calculator tool ---
29 let response = agent.chat("What is 25 * 4 + 10?").await?;
30 println!("Agent: {}\n", response);
31
32 // --- Test the echo tool ---
33 let response = agent
34 .chat("Can you echo this message: 'Hello from Helios!'")
35 .await?;
36 println!("Agent: {}\n", response);
37
38 Ok(())
39}Sourcepub fn tool_registry_mut(&mut self) -> &mut ToolRegistry
pub fn tool_registry_mut(&mut self) -> &mut ToolRegistry
Returns a mutable reference to the agent’s tool registry.
Sourcepub fn chat_session(&self) -> &ChatSession
pub fn chat_session(&self) -> &ChatSession
Returns a reference to the agent’s chat session.
Sourcepub fn chat_session_mut(&mut self) -> &mut ChatSession
pub fn chat_session_mut(&mut self) -> &mut ChatSession
Returns a mutable reference to the agent’s chat session.
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Clears the agent’s chat history.
Sourcepub async fn chat(&mut self, message: impl Into<String>) -> Result<String>
pub async fn chat(&mut self, message: impl Into<String>) -> Result<String>
A convenience method for sending a message to the agent.
Examples found in repository?
10async fn main() -> helios_engine::Result<()> {
11 // Load configuration from `config.toml`.
12 let config = Config::from_file("config.toml")?;
13
14 // Create a simple agent named "BasicAgent".
15 let mut agent = Agent::builder("BasicAgent")
16 .config(config)
17 .system_prompt("You are a helpful assistant.")
18 .build()
19 .await?;
20
21 // --- Send a message to the agent ---
22 let response = agent.chat("Hello! How are you?").await?;
23 println!("Agent: {}", response);
24
25 // --- Continue the conversation ---
26 let response = agent.chat("What can you help me with?").await?;
27 println!("Agent: {}", response);
28
29 Ok(())
30}More examples
74async fn main() -> helios_engine::Result<()> {
75 // Load configuration from `config.toml`.
76 let config = Config::from_file("config.toml")?;
77
78 // Create an agent named "WeatherAgent" and equip it with the `WeatherTool`.
79 let mut agent = Agent::builder("WeatherAgent")
80 .config(config)
81 .system_prompt("You are a helpful weather assistant. Use the weather tool to answer questions about weather.")
82 .tool(Box::new(WeatherTool))
83 .build()
84 .await?;
85
86 // --- Ask the agent about the weather ---
87 let response = agent.chat("What's the weather like in New York?").await?;
88 println!("Agent: {}\n", response);
89
90 // --- Ask again, but with a different unit ---
91 let response = agent.chat("How about in London, but in celsius?").await?;
92 println!("Agent: {}\n", response);
93
94 Ok(())
95}9async fn main() -> helios_engine::Result<()> {
10 // Load configuration from `config.toml`.
11 let config = Config::from_file("config.toml")?;
12
13 // Create an agent named "ToolAgent" and equip it with the `CalculatorTool` and `EchoTool`.
14 let mut agent = Agent::builder("ToolAgent")
15 .config(config)
16 .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
17 .tool(Box::new(CalculatorTool))
18 .tool(Box::new(EchoTool))
19 .max_iterations(5)
20 .build()
21 .await?;
22
23 println!(
24 "Available tools: {:?}\n",
25 agent.tool_registry().list_tools()
26 );
27
28 // --- Test the calculator tool ---
29 let response = agent.chat("What is 25 * 4 + 10?").await?;
30 println!("Agent: {}\n", response);
31
32 // --- Test the echo tool ---
33 let response = agent
34 .chat("Can you echo this message: 'Hello from Helios!'")
35 .await?;
36 println!("Agent: {}\n", response);
37
38 Ok(())
39}10async fn main() -> helios_engine::Result<()> {
11 // Load configuration from `config.toml`.
12 let config = Config::from_file("config.toml")?;
13
14 // --- Create multiple agents with different personalities and tools ---
15
16 // An agent specialized in math, equipped with a calculator tool.
17 let mut math_agent = Agent::builder("MathAgent")
18 .config(config.clone())
19 .system_prompt("You are a math expert. You love numbers and equations.")
20 .tool(Box::new(CalculatorTool))
21 .build()
22 .await?;
23
24 // A creative agent for writing and storytelling.
25 let mut creative_agent = Agent::builder("CreativeAgent")
26 .config(config)
27 .system_prompt("You are a creative writer who loves storytelling and poetry.")
28 .build()
29 .await?;
30
31 // --- Interact with the Math Agent ---
32 println!("=== Math Agent ===");
33 let response = math_agent.chat("What is the square root of 144?").await?;
34 println!("Math Agent: {}\n", response);
35
36 // --- Interact with the Creative Agent ---
37 println!("=== Creative Agent ===");
38 let response = creative_agent
39 .chat("Write a haiku about programming.")
40 .await?;
41 println!("Creative Agent: {}\n", response);
42
43 Ok(())
44}19async fn demonstrate_in_memory() -> helios_engine::Result<()> {
20 println!("=== IN-MEMORY RAG DEMONSTRATION ===\n");
21
22 let api_key = std::env::var("OPENAI_API_KEY").unwrap_or_else(|_| {
23 println!("⚠ Warning: OPENAI_API_KEY not set. Using placeholder.");
24 "your-api-key-here".to_string()
25 });
26
27 let config = Config::from_file("config.toml").unwrap_or_else(|_| Config::new_default());
28
29 // Create in-memory RAG tool
30 let rag_tool = RAGTool::new_in_memory("https://api.openai.com/v1/embeddings", &api_key);
31
32 let mut agent = Agent::builder("InMemoryAgent")
33 .config(config)
34 .system_prompt("You are a helpful assistant with in-memory RAG capabilities.")
35 .tool(Box::new(rag_tool))
36 .max_iterations(8)
37 .build()
38 .await?;
39
40 println!("✓ In-memory agent created\n");
41
42 // Add some documents
43 println!("Adding documents...");
44 agent.chat("Store: The capital of France is Paris.").await?;
45 agent
46 .chat("Store: The capital of Germany is Berlin.")
47 .await?;
48 agent.chat("Store: The capital of Italy is Rome.").await?;
49 println!("✓ Documents added\n");
50
51 // Search
52 println!("Searching...");
53 let response = agent.chat("What is the capital of Germany?").await?;
54 println!("Agent: {}\n", response);
55
56 println!("Advantages of in-memory:");
57 println!(" ✓ No external dependencies");
58 println!(" ✓ Fast and simple");
59 println!(" ✓ Perfect for development");
60 println!(" ✗ No persistence (data lost on restart)");
61 println!(" ✗ Limited scalability\n");
62
63 Ok(())
64}
65
66async fn demonstrate_qdrant() -> helios_engine::Result<()> {
67 println!("=== QDRANT RAG DEMONSTRATION ===\n");
68
69 let api_key = std::env::var("OPENAI_API_KEY").unwrap_or_else(|_| {
70 println!("⚠ Warning: OPENAI_API_KEY not set. Using placeholder.");
71 "your-api-key-here".to_string()
72 });
73
74 let config = Config::from_file("config.toml").unwrap_or_else(|_| Config::new_default());
75
76 // Create Qdrant RAG tool
77 let rag_tool = RAGTool::new_qdrant(
78 "http://localhost:6333",
79 "comparison_demo",
80 "https://api.openai.com/v1/embeddings",
81 &api_key,
82 );
83
84 let mut agent = Agent::builder("QdrantAgent")
85 .config(config)
86 .system_prompt("You are a helpful assistant with Qdrant RAG capabilities.")
87 .tool(Box::new(rag_tool))
88 .max_iterations(8)
89 .build()
90 .await?;
91
92 println!("✓ Qdrant agent created\n");
93
94 // Clear any existing data
95 println!("Clearing existing data...");
96 agent.chat("Clear all documents").await?;
97 println!("✓ Cleared\n");
98
99 // Add some documents
100 println!("Adding documents...");
101 agent
102 .chat("Store: The Eiffel Tower is located in Paris, France.")
103 .await?;
104 agent
105 .chat("Store: The Colosseum is located in Rome, Italy.")
106 .await?;
107 agent
108 .chat("Store: The Brandenburg Gate is located in Berlin, Germany.")
109 .await?;
110 println!("✓ Documents added\n");
111
112 // Search
113 println!("Searching...");
114 let response = agent.chat("What famous landmark is in Berlin?").await?;
115 println!("Agent: {}\n", response);
116
117 println!("Advantages of Qdrant:");
118 println!(" ✓ Persistent storage");
119 println!(" ✓ Highly scalable");
120 println!(" ✓ Production-ready");
121 println!(" ✓ Advanced features (filtering, etc.)");
122 println!(" ✗ Requires external service");
123 println!(" ✗ More complex setup\n");
124
125 Ok(())
126}10async fn main() -> helios_engine::Result<()> {
11 println!("🚀 Helios Engine - Agent with File Tools Example");
12 println!("=================================================\n");
13
14 // Load configuration
15 let config = Config::from_file("config.toml").unwrap_or_else(|_| {
16 println!("⚠ No config.toml found, using default configuration");
17 Config::new_default()
18 });
19
20 // Create an agent named "FileAssistant" and equip it with file tools.
21 let mut agent = Agent::builder("FileAssistant")
22 .config(config)
23 .system_prompt(
24 "You are a helpful file management assistant. You can search for files, \
25 read file contents, and edit files. Always confirm with the user before \
26 making changes to files. Keep track of important session information.",
27 )
28 .tool(Box::new(FileSearchTool))
29 .tool(Box::new(FileReadTool))
30 .tool(Box::new(FileEditTool))
31 .tool(Box::new(FileWriteTool))
32 .max_iterations(10)
33 .build()
34 .await?;
35
36 println!("✓ Agent created with file tools");
37 println!("✓ Available tools: file_search, file_read, file_edit, file_write\n");
38
39 // Set initial session memory for the agent.
40 agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
41 agent.set_memory(
42 "working_directory",
43 std::env::current_dir()?.display().to_string(),
44 );
45 agent.set_memory("tasks_completed", "0");
46
47 // --- Example 1: Search for Rust files ---
48 println!("Example 1: Searching for Rust files");
49 println!("====================================\n");
50
51 let response = agent
52 .chat("Find all Rust source files in the src directory")
53 .await?;
54 println!("Agent: {}\n", response);
55
56 // Update session memory after the task.
57 agent.increment_tasks_completed();
58 agent.set_memory("last_task", "file_search");
59
60 // --- Example 2: Read a specific file ---
61 println!("\nExample 2: Reading file contents");
62 println!("==================================\n");
63
64 let response = agent
65 .chat("Read the contents of src/lib.rs and give me a summary")
66 .await?;
67 println!("Agent: {}\n", response);
68
69 // Update session memory after the task.
70 agent.increment_tasks_completed();
71 agent.set_memory("last_task", "file_read");
72
73 // --- Example 3: Show session summary ---
74 println!("\nExample 3: Session Summary");
75 println!("==========================\n");
76
77 println!("{}", agent.get_session_summary());
78
79 // --- Example 4: Check session memory ---
80 println!("\nExample 4: Checking Session Memory");
81 println!("===================================\n");
82
83 println!(
84 "Working directory: {}",
85 agent
86 .get_memory("working_directory")
87 .unwrap_or(&"unknown".to_string())
88 );
89 println!(
90 "Tasks completed: {}",
91 agent
92 .get_memory("tasks_completed")
93 .unwrap_or(&"0".to_string())
94 );
95 println!(
96 "Last task: {}",
97 agent.get_memory("last_task").unwrap_or(&"none".to_string())
98 );
99
100 println!("\n✅ Example completed successfully!");
101 println!("\n💡 Key Features Demonstrated:");
102 println!(" • File search with pattern matching and content search");
103 println!(" • File reading with line range support");
104 println!(" • File editing with find/replace functionality");
105 println!(" • Session memory for tracking agent state");
106 println!(" • Streaming responses (works with both local and remote models)");
107
108 Ok(())
109}Sourcepub fn set_max_iterations(&mut self, max: usize)
pub fn set_max_iterations(&mut self, max: usize)
Sets the maximum number of iterations for tool execution.
§Arguments
max- The maximum number of iterations.
Sourcepub fn get_session_summary(&self) -> String
pub fn get_session_summary(&self) -> String
Returns a summary of the current chat session.
Examples found in repository?
10async fn main() -> helios_engine::Result<()> {
11 println!("🚀 Helios Engine - Agent with File Tools Example");
12 println!("=================================================\n");
13
14 // Load configuration
15 let config = Config::from_file("config.toml").unwrap_or_else(|_| {
16 println!("⚠ No config.toml found, using default configuration");
17 Config::new_default()
18 });
19
20 // Create an agent named "FileAssistant" and equip it with file tools.
21 let mut agent = Agent::builder("FileAssistant")
22 .config(config)
23 .system_prompt(
24 "You are a helpful file management assistant. You can search for files, \
25 read file contents, and edit files. Always confirm with the user before \
26 making changes to files. Keep track of important session information.",
27 )
28 .tool(Box::new(FileSearchTool))
29 .tool(Box::new(FileReadTool))
30 .tool(Box::new(FileEditTool))
31 .tool(Box::new(FileWriteTool))
32 .max_iterations(10)
33 .build()
34 .await?;
35
36 println!("✓ Agent created with file tools");
37 println!("✓ Available tools: file_search, file_read, file_edit, file_write\n");
38
39 // Set initial session memory for the agent.
40 agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
41 agent.set_memory(
42 "working_directory",
43 std::env::current_dir()?.display().to_string(),
44 );
45 agent.set_memory("tasks_completed", "0");
46
47 // --- Example 1: Search for Rust files ---
48 println!("Example 1: Searching for Rust files");
49 println!("====================================\n");
50
51 let response = agent
52 .chat("Find all Rust source files in the src directory")
53 .await?;
54 println!("Agent: {}\n", response);
55
56 // Update session memory after the task.
57 agent.increment_tasks_completed();
58 agent.set_memory("last_task", "file_search");
59
60 // --- Example 2: Read a specific file ---
61 println!("\nExample 2: Reading file contents");
62 println!("==================================\n");
63
64 let response = agent
65 .chat("Read the contents of src/lib.rs and give me a summary")
66 .await?;
67 println!("Agent: {}\n", response);
68
69 // Update session memory after the task.
70 agent.increment_tasks_completed();
71 agent.set_memory("last_task", "file_read");
72
73 // --- Example 3: Show session summary ---
74 println!("\nExample 3: Session Summary");
75 println!("==========================\n");
76
77 println!("{}", agent.get_session_summary());
78
79 // --- Example 4: Check session memory ---
80 println!("\nExample 4: Checking Session Memory");
81 println!("===================================\n");
82
83 println!(
84 "Working directory: {}",
85 agent
86 .get_memory("working_directory")
87 .unwrap_or(&"unknown".to_string())
88 );
89 println!(
90 "Tasks completed: {}",
91 agent
92 .get_memory("tasks_completed")
93 .unwrap_or(&"0".to_string())
94 );
95 println!(
96 "Last task: {}",
97 agent.get_memory("last_task").unwrap_or(&"none".to_string())
98 );
99
100 println!("\n✅ Example completed successfully!");
101 println!("\n💡 Key Features Demonstrated:");
102 println!(" • File search with pattern matching and content search");
103 println!(" • File reading with line range support");
104 println!(" • File editing with find/replace functionality");
105 println!(" • Session memory for tracking agent state");
106 println!(" • Streaming responses (works with both local and remote models)");
107
108 Ok(())
109}More examples
12async fn main() -> helios_engine::Result<()> {
13 println!("🚀 Helios Engine - Complete Feature Demo");
14 println!("=========================================\n");
15
16 // Load configuration from `config.toml` or use default.
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 an agent named "SmartAssistant" and equip it 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 with some starting values.
42 println!("🧠 Initializing session memory...");
43 agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
44 agent.set_memory(
45 "working_directory",
46 std::env::current_dir()?.display().to_string(),
47 );
48 agent.set_memory("files_accessed", "0");
49 agent.set_memory("edits_made", "0");
50 println!("✓ Session memory initialized\n");
51
52 // --- Demo 1: Search for files with streaming response ---
53 println!("Demo 1: File Search with Streaming");
54 println!("===================================");
55 println!("User: Find all Rust example files\n");
56
57 print!("Agent: ");
58 io::stdout().flush()?;
59
60 let response1 = agent
61 .chat("Find all Rust example files in the examples directory")
62 .await?;
63 println!("{}\n", response1);
64
65 // Update session memory after the task.
66 agent.increment_counter("files_accessed");
67 agent.set_memory("last_action", "file_search");
68
69 // --- Demo 2: Read a file ---
70 println!("\nDemo 2: Reading File Contents");
71 println!("==============================");
72 println!("User: Read the NEW_FEATURES.md file and summarize the key points\n");
73
74 print!("Agent: ");
75 io::stdout().flush()?;
76
77 let response2 = agent
78 .chat("Read the NEW_FEATURES.md file and give me a brief summary of what's new")
79 .await?;
80 println!("{}\n", response2);
81
82 // Update session memory after the task.
83 agent.increment_counter("files_accessed");
84 agent.set_memory("last_action", "file_read");
85
86 // --- Demo 3: Show session summary ---
87 println!("\nDemo 3: Session Summary");
88 println!("=======================\n");
89 println!("{}", agent.get_session_summary());
90
91 // --- Demo 4: Interactive mode ---
92 println!("\n\nDemo 4: Interactive Mode");
93 println!("========================");
94 println!("You can now interact with the agent. Type 'exit' to quit.\n");
95
96 loop {
97 print!("\nYou: ");
98 io::stdout().flush()?;
99
100 let mut input = String::new();
101 io::stdin().read_line(&mut input)?;
102 let input = input.trim();
103
104 if input.is_empty() {
105 continue;
106 }
107
108 match input.to_lowercase().as_str() {
109 "exit" | "quit" => {
110 println!("\n👋 Goodbye!");
111 break;
112 }
113 "summary" => {
114 println!("\n📊 Session Summary:");
115 println!("{}", agent.get_session_summary());
116 continue;
117 }
118 "memory" => {
119 println!("\n🧠 Session Memory:");
120 if let Some(start) = agent.get_memory("session_start") {
121 println!(" Session started: {}", start);
122 }
123 if let Some(dir) = agent.get_memory("working_directory") {
124 println!(" Working directory: {}", dir);
125 }
126 if let Some(files) = agent.get_memory("files_accessed") {
127 println!(" Files accessed: {}", files);
128 }
129 if let Some(edits) = agent.get_memory("edits_made") {
130 println!(" Edits made: {}", edits);
131 }
132 if let Some(action) = agent.get_memory("last_action") {
133 println!(" Last action: {}", action);
134 }
135 continue;
136 }
137 "help" => {
138 println!("\n📖 Available Commands:");
139 println!(" exit, quit - Exit the demo");
140 println!(" summary - Show session summary");
141 println!(" memory - Show session memory");
142 println!(" help - Show this help");
143 println!("\n💡 Try asking the agent to:");
144 println!(" • Search for specific files");
145 println!(" • Read file contents");
146 println!(" • Summarize what it has done");
147 continue;
148 }
149 _ => {}
150 }
151
152 // Send message to agent with streaming.
153 print!("\nAgent: ");
154 io::stdout().flush()?;
155
156 match agent.chat(input).await {
157 Ok(response) => {
158 println!("{}", response);
159
160 // Update memory after each interaction.
161 agent.increment_counter("files_accessed");
162 }
163 Err(e) => {
164 eprintln!("\n❌ Error: {}", e);
165 }
166 }
167 }
168
169 // --- Final summary ---
170 println!("\n📊 Final Session Summary:");
171 println!("{}", agent.get_session_summary());
172
173 println!("\n✅ Demo completed successfully!");
174 println!("\n💡 Features Demonstrated:");
175 println!(" ✓ Streaming responses (local/remote models)");
176 println!(" ✓ File search with pattern matching");
177 println!(" ✓ File reading with summaries");
178 println!(" ✓ Session memory tracking");
179 println!(" ✓ Interactive conversation");
180 println!(" ✓ Real-time progress updates");
181
182 Ok(())
183}Sourcepub fn clear_memory(&mut self)
pub fn clear_memory(&mut self)
Clears the agent’s memory (agent-scoped metadata).
Sourcepub fn set_memory(&mut self, key: impl Into<String>, value: impl Into<String>)
pub fn set_memory(&mut self, key: impl Into<String>, value: impl Into<String>)
Sets a value in the agent’s memory.
Examples found in repository?
10async fn main() -> helios_engine::Result<()> {
11 println!("🚀 Helios Engine - Agent with File Tools Example");
12 println!("=================================================\n");
13
14 // Load configuration
15 let config = Config::from_file("config.toml").unwrap_or_else(|_| {
16 println!("⚠ No config.toml found, using default configuration");
17 Config::new_default()
18 });
19
20 // Create an agent named "FileAssistant" and equip it with file tools.
21 let mut agent = Agent::builder("FileAssistant")
22 .config(config)
23 .system_prompt(
24 "You are a helpful file management assistant. You can search for files, \
25 read file contents, and edit files. Always confirm with the user before \
26 making changes to files. Keep track of important session information.",
27 )
28 .tool(Box::new(FileSearchTool))
29 .tool(Box::new(FileReadTool))
30 .tool(Box::new(FileEditTool))
31 .tool(Box::new(FileWriteTool))
32 .max_iterations(10)
33 .build()
34 .await?;
35
36 println!("✓ Agent created with file tools");
37 println!("✓ Available tools: file_search, file_read, file_edit, file_write\n");
38
39 // Set initial session memory for the agent.
40 agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
41 agent.set_memory(
42 "working_directory",
43 std::env::current_dir()?.display().to_string(),
44 );
45 agent.set_memory("tasks_completed", "0");
46
47 // --- Example 1: Search for Rust files ---
48 println!("Example 1: Searching for Rust files");
49 println!("====================================\n");
50
51 let response = agent
52 .chat("Find all Rust source files in the src directory")
53 .await?;
54 println!("Agent: {}\n", response);
55
56 // Update session memory after the task.
57 agent.increment_tasks_completed();
58 agent.set_memory("last_task", "file_search");
59
60 // --- Example 2: Read a specific file ---
61 println!("\nExample 2: Reading file contents");
62 println!("==================================\n");
63
64 let response = agent
65 .chat("Read the contents of src/lib.rs and give me a summary")
66 .await?;
67 println!("Agent: {}\n", response);
68
69 // Update session memory after the task.
70 agent.increment_tasks_completed();
71 agent.set_memory("last_task", "file_read");
72
73 // --- Example 3: Show session summary ---
74 println!("\nExample 3: Session Summary");
75 println!("==========================\n");
76
77 println!("{}", agent.get_session_summary());
78
79 // --- Example 4: Check session memory ---
80 println!("\nExample 4: Checking Session Memory");
81 println!("===================================\n");
82
83 println!(
84 "Working directory: {}",
85 agent
86 .get_memory("working_directory")
87 .unwrap_or(&"unknown".to_string())
88 );
89 println!(
90 "Tasks completed: {}",
91 agent
92 .get_memory("tasks_completed")
93 .unwrap_or(&"0".to_string())
94 );
95 println!(
96 "Last task: {}",
97 agent.get_memory("last_task").unwrap_or(&"none".to_string())
98 );
99
100 println!("\n✅ Example completed successfully!");
101 println!("\n💡 Key Features Demonstrated:");
102 println!(" • File search with pattern matching and content search");
103 println!(" • File reading with line range support");
104 println!(" • File editing with find/replace functionality");
105 println!(" • Session memory for tracking agent state");
106 println!(" • Streaming responses (works with both local and remote models)");
107
108 Ok(())
109}More examples
12async fn main() -> helios_engine::Result<()> {
13 println!("🚀 Helios Engine - Complete Feature Demo");
14 println!("=========================================\n");
15
16 // Load configuration from `config.toml` or use default.
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 an agent named "SmartAssistant" and equip it 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 with some starting values.
42 println!("🧠 Initializing session memory...");
43 agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
44 agent.set_memory(
45 "working_directory",
46 std::env::current_dir()?.display().to_string(),
47 );
48 agent.set_memory("files_accessed", "0");
49 agent.set_memory("edits_made", "0");
50 println!("✓ Session memory initialized\n");
51
52 // --- Demo 1: Search for files with streaming response ---
53 println!("Demo 1: File Search with Streaming");
54 println!("===================================");
55 println!("User: Find all Rust example files\n");
56
57 print!("Agent: ");
58 io::stdout().flush()?;
59
60 let response1 = agent
61 .chat("Find all Rust example files in the examples directory")
62 .await?;
63 println!("{}\n", response1);
64
65 // Update session memory after the task.
66 agent.increment_counter("files_accessed");
67 agent.set_memory("last_action", "file_search");
68
69 // --- Demo 2: Read a file ---
70 println!("\nDemo 2: Reading File Contents");
71 println!("==============================");
72 println!("User: Read the NEW_FEATURES.md file and summarize the key points\n");
73
74 print!("Agent: ");
75 io::stdout().flush()?;
76
77 let response2 = agent
78 .chat("Read the NEW_FEATURES.md file and give me a brief summary of what's new")
79 .await?;
80 println!("{}\n", response2);
81
82 // Update session memory after the task.
83 agent.increment_counter("files_accessed");
84 agent.set_memory("last_action", "file_read");
85
86 // --- Demo 3: Show session summary ---
87 println!("\nDemo 3: Session Summary");
88 println!("=======================\n");
89 println!("{}", agent.get_session_summary());
90
91 // --- Demo 4: Interactive mode ---
92 println!("\n\nDemo 4: Interactive Mode");
93 println!("========================");
94 println!("You can now interact with the agent. Type 'exit' to quit.\n");
95
96 loop {
97 print!("\nYou: ");
98 io::stdout().flush()?;
99
100 let mut input = String::new();
101 io::stdin().read_line(&mut input)?;
102 let input = input.trim();
103
104 if input.is_empty() {
105 continue;
106 }
107
108 match input.to_lowercase().as_str() {
109 "exit" | "quit" => {
110 println!("\n👋 Goodbye!");
111 break;
112 }
113 "summary" => {
114 println!("\n📊 Session Summary:");
115 println!("{}", agent.get_session_summary());
116 continue;
117 }
118 "memory" => {
119 println!("\n🧠 Session Memory:");
120 if let Some(start) = agent.get_memory("session_start") {
121 println!(" Session started: {}", start);
122 }
123 if let Some(dir) = agent.get_memory("working_directory") {
124 println!(" Working directory: {}", dir);
125 }
126 if let Some(files) = agent.get_memory("files_accessed") {
127 println!(" Files accessed: {}", files);
128 }
129 if let Some(edits) = agent.get_memory("edits_made") {
130 println!(" Edits made: {}", edits);
131 }
132 if let Some(action) = agent.get_memory("last_action") {
133 println!(" Last action: {}", action);
134 }
135 continue;
136 }
137 "help" => {
138 println!("\n📖 Available Commands:");
139 println!(" exit, quit - Exit the demo");
140 println!(" summary - Show session summary");
141 println!(" memory - Show session memory");
142 println!(" help - Show this help");
143 println!("\n💡 Try asking the agent to:");
144 println!(" • Search for specific files");
145 println!(" • Read file contents");
146 println!(" • Summarize what it has done");
147 continue;
148 }
149 _ => {}
150 }
151
152 // Send message to agent with streaming.
153 print!("\nAgent: ");
154 io::stdout().flush()?;
155
156 match agent.chat(input).await {
157 Ok(response) => {
158 println!("{}", response);
159
160 // Update memory after each interaction.
161 agent.increment_counter("files_accessed");
162 }
163 Err(e) => {
164 eprintln!("\n❌ Error: {}", e);
165 }
166 }
167 }
168
169 // --- Final summary ---
170 println!("\n📊 Final Session Summary:");
171 println!("{}", agent.get_session_summary());
172
173 println!("\n✅ Demo completed successfully!");
174 println!("\n💡 Features Demonstrated:");
175 println!(" ✓ Streaming responses (local/remote models)");
176 println!(" ✓ File search with pattern matching");
177 println!(" ✓ File reading with summaries");
178 println!(" ✓ Session memory tracking");
179 println!(" ✓ Interactive conversation");
180 println!(" ✓ Real-time progress updates");
181
182 Ok(())
183}Sourcepub fn get_memory(&self, key: &str) -> Option<&String>
pub fn get_memory(&self, key: &str) -> Option<&String>
Gets a value from the agent’s memory.
Examples found in repository?
10async fn main() -> helios_engine::Result<()> {
11 println!("🚀 Helios Engine - Agent with File Tools Example");
12 println!("=================================================\n");
13
14 // Load configuration
15 let config = Config::from_file("config.toml").unwrap_or_else(|_| {
16 println!("⚠ No config.toml found, using default configuration");
17 Config::new_default()
18 });
19
20 // Create an agent named "FileAssistant" and equip it with file tools.
21 let mut agent = Agent::builder("FileAssistant")
22 .config(config)
23 .system_prompt(
24 "You are a helpful file management assistant. You can search for files, \
25 read file contents, and edit files. Always confirm with the user before \
26 making changes to files. Keep track of important session information.",
27 )
28 .tool(Box::new(FileSearchTool))
29 .tool(Box::new(FileReadTool))
30 .tool(Box::new(FileEditTool))
31 .tool(Box::new(FileWriteTool))
32 .max_iterations(10)
33 .build()
34 .await?;
35
36 println!("✓ Agent created with file tools");
37 println!("✓ Available tools: file_search, file_read, file_edit, file_write\n");
38
39 // Set initial session memory for the agent.
40 agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
41 agent.set_memory(
42 "working_directory",
43 std::env::current_dir()?.display().to_string(),
44 );
45 agent.set_memory("tasks_completed", "0");
46
47 // --- Example 1: Search for Rust files ---
48 println!("Example 1: Searching for Rust files");
49 println!("====================================\n");
50
51 let response = agent
52 .chat("Find all Rust source files in the src directory")
53 .await?;
54 println!("Agent: {}\n", response);
55
56 // Update session memory after the task.
57 agent.increment_tasks_completed();
58 agent.set_memory("last_task", "file_search");
59
60 // --- Example 2: Read a specific file ---
61 println!("\nExample 2: Reading file contents");
62 println!("==================================\n");
63
64 let response = agent
65 .chat("Read the contents of src/lib.rs and give me a summary")
66 .await?;
67 println!("Agent: {}\n", response);
68
69 // Update session memory after the task.
70 agent.increment_tasks_completed();
71 agent.set_memory("last_task", "file_read");
72
73 // --- Example 3: Show session summary ---
74 println!("\nExample 3: Session Summary");
75 println!("==========================\n");
76
77 println!("{}", agent.get_session_summary());
78
79 // --- Example 4: Check session memory ---
80 println!("\nExample 4: Checking Session Memory");
81 println!("===================================\n");
82
83 println!(
84 "Working directory: {}",
85 agent
86 .get_memory("working_directory")
87 .unwrap_or(&"unknown".to_string())
88 );
89 println!(
90 "Tasks completed: {}",
91 agent
92 .get_memory("tasks_completed")
93 .unwrap_or(&"0".to_string())
94 );
95 println!(
96 "Last task: {}",
97 agent.get_memory("last_task").unwrap_or(&"none".to_string())
98 );
99
100 println!("\n✅ Example completed successfully!");
101 println!("\n💡 Key Features Demonstrated:");
102 println!(" • File search with pattern matching and content search");
103 println!(" • File reading with line range support");
104 println!(" • File editing with find/replace functionality");
105 println!(" • Session memory for tracking agent state");
106 println!(" • Streaming responses (works with both local and remote models)");
107
108 Ok(())
109}More examples
12async fn main() -> helios_engine::Result<()> {
13 println!("🚀 Helios Engine - Complete Feature Demo");
14 println!("=========================================\n");
15
16 // Load configuration from `config.toml` or use default.
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 an agent named "SmartAssistant" and equip it 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 with some starting values.
42 println!("🧠 Initializing session memory...");
43 agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
44 agent.set_memory(
45 "working_directory",
46 std::env::current_dir()?.display().to_string(),
47 );
48 agent.set_memory("files_accessed", "0");
49 agent.set_memory("edits_made", "0");
50 println!("✓ Session memory initialized\n");
51
52 // --- Demo 1: Search for files with streaming response ---
53 println!("Demo 1: File Search with Streaming");
54 println!("===================================");
55 println!("User: Find all Rust example files\n");
56
57 print!("Agent: ");
58 io::stdout().flush()?;
59
60 let response1 = agent
61 .chat("Find all Rust example files in the examples directory")
62 .await?;
63 println!("{}\n", response1);
64
65 // Update session memory after the task.
66 agent.increment_counter("files_accessed");
67 agent.set_memory("last_action", "file_search");
68
69 // --- Demo 2: Read a file ---
70 println!("\nDemo 2: Reading File Contents");
71 println!("==============================");
72 println!("User: Read the NEW_FEATURES.md file and summarize the key points\n");
73
74 print!("Agent: ");
75 io::stdout().flush()?;
76
77 let response2 = agent
78 .chat("Read the NEW_FEATURES.md file and give me a brief summary of what's new")
79 .await?;
80 println!("{}\n", response2);
81
82 // Update session memory after the task.
83 agent.increment_counter("files_accessed");
84 agent.set_memory("last_action", "file_read");
85
86 // --- Demo 3: Show session summary ---
87 println!("\nDemo 3: Session Summary");
88 println!("=======================\n");
89 println!("{}", agent.get_session_summary());
90
91 // --- Demo 4: Interactive mode ---
92 println!("\n\nDemo 4: Interactive Mode");
93 println!("========================");
94 println!("You can now interact with the agent. Type 'exit' to quit.\n");
95
96 loop {
97 print!("\nYou: ");
98 io::stdout().flush()?;
99
100 let mut input = String::new();
101 io::stdin().read_line(&mut input)?;
102 let input = input.trim();
103
104 if input.is_empty() {
105 continue;
106 }
107
108 match input.to_lowercase().as_str() {
109 "exit" | "quit" => {
110 println!("\n👋 Goodbye!");
111 break;
112 }
113 "summary" => {
114 println!("\n📊 Session Summary:");
115 println!("{}", agent.get_session_summary());
116 continue;
117 }
118 "memory" => {
119 println!("\n🧠 Session Memory:");
120 if let Some(start) = agent.get_memory("session_start") {
121 println!(" Session started: {}", start);
122 }
123 if let Some(dir) = agent.get_memory("working_directory") {
124 println!(" Working directory: {}", dir);
125 }
126 if let Some(files) = agent.get_memory("files_accessed") {
127 println!(" Files accessed: {}", files);
128 }
129 if let Some(edits) = agent.get_memory("edits_made") {
130 println!(" Edits made: {}", edits);
131 }
132 if let Some(action) = agent.get_memory("last_action") {
133 println!(" Last action: {}", action);
134 }
135 continue;
136 }
137 "help" => {
138 println!("\n📖 Available Commands:");
139 println!(" exit, quit - Exit the demo");
140 println!(" summary - Show session summary");
141 println!(" memory - Show session memory");
142 println!(" help - Show this help");
143 println!("\n💡 Try asking the agent to:");
144 println!(" • Search for specific files");
145 println!(" • Read file contents");
146 println!(" • Summarize what it has done");
147 continue;
148 }
149 _ => {}
150 }
151
152 // Send message to agent with streaming.
153 print!("\nAgent: ");
154 io::stdout().flush()?;
155
156 match agent.chat(input).await {
157 Ok(response) => {
158 println!("{}", response);
159
160 // Update memory after each interaction.
161 agent.increment_counter("files_accessed");
162 }
163 Err(e) => {
164 eprintln!("\n❌ Error: {}", e);
165 }
166 }
167 }
168
169 // --- Final summary ---
170 println!("\n📊 Final Session Summary:");
171 println!("{}", agent.get_session_summary());
172
173 println!("\n✅ Demo completed successfully!");
174 println!("\n💡 Features Demonstrated:");
175 println!(" ✓ Streaming responses (local/remote models)");
176 println!(" ✓ File search with pattern matching");
177 println!(" ✓ File reading with summaries");
178 println!(" ✓ Session memory tracking");
179 println!(" ✓ Interactive conversation");
180 println!(" ✓ Real-time progress updates");
181
182 Ok(())
183}Sourcepub fn remove_memory(&mut self, key: &str) -> Option<String>
pub fn remove_memory(&mut self, key: &str) -> Option<String>
Removes a value from the agent’s memory.
Sourcepub fn increment_counter(&mut self, key: &str) -> u32
pub fn increment_counter(&mut self, key: &str) -> u32
Increments a counter in the agent’s memory.
Examples found in repository?
12async fn main() -> helios_engine::Result<()> {
13 println!("🚀 Helios Engine - Complete Feature Demo");
14 println!("=========================================\n");
15
16 // Load configuration from `config.toml` or use default.
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 an agent named "SmartAssistant" and equip it 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 with some starting values.
42 println!("🧠 Initializing session memory...");
43 agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
44 agent.set_memory(
45 "working_directory",
46 std::env::current_dir()?.display().to_string(),
47 );
48 agent.set_memory("files_accessed", "0");
49 agent.set_memory("edits_made", "0");
50 println!("✓ Session memory initialized\n");
51
52 // --- Demo 1: Search for files with streaming response ---
53 println!("Demo 1: File Search with Streaming");
54 println!("===================================");
55 println!("User: Find all Rust example files\n");
56
57 print!("Agent: ");
58 io::stdout().flush()?;
59
60 let response1 = agent
61 .chat("Find all Rust example files in the examples directory")
62 .await?;
63 println!("{}\n", response1);
64
65 // Update session memory after the task.
66 agent.increment_counter("files_accessed");
67 agent.set_memory("last_action", "file_search");
68
69 // --- Demo 2: Read a file ---
70 println!("\nDemo 2: Reading File Contents");
71 println!("==============================");
72 println!("User: Read the NEW_FEATURES.md file and summarize the key points\n");
73
74 print!("Agent: ");
75 io::stdout().flush()?;
76
77 let response2 = agent
78 .chat("Read the NEW_FEATURES.md file and give me a brief summary of what's new")
79 .await?;
80 println!("{}\n", response2);
81
82 // Update session memory after the task.
83 agent.increment_counter("files_accessed");
84 agent.set_memory("last_action", "file_read");
85
86 // --- Demo 3: Show session summary ---
87 println!("\nDemo 3: Session Summary");
88 println!("=======================\n");
89 println!("{}", agent.get_session_summary());
90
91 // --- Demo 4: Interactive mode ---
92 println!("\n\nDemo 4: Interactive Mode");
93 println!("========================");
94 println!("You can now interact with the agent. Type 'exit' to quit.\n");
95
96 loop {
97 print!("\nYou: ");
98 io::stdout().flush()?;
99
100 let mut input = String::new();
101 io::stdin().read_line(&mut input)?;
102 let input = input.trim();
103
104 if input.is_empty() {
105 continue;
106 }
107
108 match input.to_lowercase().as_str() {
109 "exit" | "quit" => {
110 println!("\n👋 Goodbye!");
111 break;
112 }
113 "summary" => {
114 println!("\n📊 Session Summary:");
115 println!("{}", agent.get_session_summary());
116 continue;
117 }
118 "memory" => {
119 println!("\n🧠 Session Memory:");
120 if let Some(start) = agent.get_memory("session_start") {
121 println!(" Session started: {}", start);
122 }
123 if let Some(dir) = agent.get_memory("working_directory") {
124 println!(" Working directory: {}", dir);
125 }
126 if let Some(files) = agent.get_memory("files_accessed") {
127 println!(" Files accessed: {}", files);
128 }
129 if let Some(edits) = agent.get_memory("edits_made") {
130 println!(" Edits made: {}", edits);
131 }
132 if let Some(action) = agent.get_memory("last_action") {
133 println!(" Last action: {}", action);
134 }
135 continue;
136 }
137 "help" => {
138 println!("\n📖 Available Commands:");
139 println!(" exit, quit - Exit the demo");
140 println!(" summary - Show session summary");
141 println!(" memory - Show session memory");
142 println!(" help - Show this help");
143 println!("\n💡 Try asking the agent to:");
144 println!(" • Search for specific files");
145 println!(" • Read file contents");
146 println!(" • Summarize what it has done");
147 continue;
148 }
149 _ => {}
150 }
151
152 // Send message to agent with streaming.
153 print!("\nAgent: ");
154 io::stdout().flush()?;
155
156 match agent.chat(input).await {
157 Ok(response) => {
158 println!("{}", response);
159
160 // Update memory after each interaction.
161 agent.increment_counter("files_accessed");
162 }
163 Err(e) => {
164 eprintln!("\n❌ Error: {}", e);
165 }
166 }
167 }
168
169 // --- Final summary ---
170 println!("\n📊 Final Session Summary:");
171 println!("{}", agent.get_session_summary());
172
173 println!("\n✅ Demo completed successfully!");
174 println!("\n💡 Features Demonstrated:");
175 println!(" ✓ Streaming responses (local/remote models)");
176 println!(" ✓ File search with pattern matching");
177 println!(" ✓ File reading with summaries");
178 println!(" ✓ Session memory tracking");
179 println!(" ✓ Interactive conversation");
180 println!(" ✓ Real-time progress updates");
181
182 Ok(())
183}Sourcepub fn increment_tasks_completed(&mut self) -> u32
pub fn increment_tasks_completed(&mut self) -> u32
Increments the “tasks_completed” counter in the agent’s memory.
Examples found in repository?
10async fn main() -> helios_engine::Result<()> {
11 println!("🚀 Helios Engine - Agent with File Tools Example");
12 println!("=================================================\n");
13
14 // Load configuration
15 let config = Config::from_file("config.toml").unwrap_or_else(|_| {
16 println!("⚠ No config.toml found, using default configuration");
17 Config::new_default()
18 });
19
20 // Create an agent named "FileAssistant" and equip it with file tools.
21 let mut agent = Agent::builder("FileAssistant")
22 .config(config)
23 .system_prompt(
24 "You are a helpful file management assistant. You can search for files, \
25 read file contents, and edit files. Always confirm with the user before \
26 making changes to files. Keep track of important session information.",
27 )
28 .tool(Box::new(FileSearchTool))
29 .tool(Box::new(FileReadTool))
30 .tool(Box::new(FileEditTool))
31 .tool(Box::new(FileWriteTool))
32 .max_iterations(10)
33 .build()
34 .await?;
35
36 println!("✓ Agent created with file tools");
37 println!("✓ Available tools: file_search, file_read, file_edit, file_write\n");
38
39 // Set initial session memory for the agent.
40 agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
41 agent.set_memory(
42 "working_directory",
43 std::env::current_dir()?.display().to_string(),
44 );
45 agent.set_memory("tasks_completed", "0");
46
47 // --- Example 1: Search for Rust files ---
48 println!("Example 1: Searching for Rust files");
49 println!("====================================\n");
50
51 let response = agent
52 .chat("Find all Rust source files in the src directory")
53 .await?;
54 println!("Agent: {}\n", response);
55
56 // Update session memory after the task.
57 agent.increment_tasks_completed();
58 agent.set_memory("last_task", "file_search");
59
60 // --- Example 2: Read a specific file ---
61 println!("\nExample 2: Reading file contents");
62 println!("==================================\n");
63
64 let response = agent
65 .chat("Read the contents of src/lib.rs and give me a summary")
66 .await?;
67 println!("Agent: {}\n", response);
68
69 // Update session memory after the task.
70 agent.increment_tasks_completed();
71 agent.set_memory("last_task", "file_read");
72
73 // --- Example 3: Show session summary ---
74 println!("\nExample 3: Session Summary");
75 println!("==========================\n");
76
77 println!("{}", agent.get_session_summary());
78
79 // --- Example 4: Check session memory ---
80 println!("\nExample 4: Checking Session Memory");
81 println!("===================================\n");
82
83 println!(
84 "Working directory: {}",
85 agent
86 .get_memory("working_directory")
87 .unwrap_or(&"unknown".to_string())
88 );
89 println!(
90 "Tasks completed: {}",
91 agent
92 .get_memory("tasks_completed")
93 .unwrap_or(&"0".to_string())
94 );
95 println!(
96 "Last task: {}",
97 agent.get_memory("last_task").unwrap_or(&"none".to_string())
98 );
99
100 println!("\n✅ Example completed successfully!");
101 println!("\n💡 Key Features Demonstrated:");
102 println!(" • File search with pattern matching and content search");
103 println!(" • File reading with line range support");
104 println!(" • File editing with find/replace functionality");
105 println!(" • Session memory for tracking agent state");
106 println!(" • Streaming responses (works with both local and remote models)");
107
108 Ok(())
109}Sourcepub async fn chat_with_history(
&mut self,
messages: Vec<ChatMessage>,
temperature: Option<f32>,
max_tokens: Option<u32>,
stop: Option<Vec<String>>,
) -> Result<String>
pub async fn chat_with_history( &mut self, messages: Vec<ChatMessage>, temperature: Option<f32>, max_tokens: Option<u32>, stop: Option<Vec<String>>, ) -> Result<String>
Executes a stateless conversation with the provided message history.
This method creates a temporary chat session with the provided messages and executes the agent logic without modifying the agent’s persistent session. This is useful for OpenAI API compatibility where each request contains the full conversation history.
§Arguments
messages- The complete conversation history for this requesttemperature- Optional temperature parameter for generationmax_tokens- Optional maximum tokens parameter for generationstop- Optional stop sequences for generation
§Returns
A Result containing the assistant’s response content.
Sourcepub async fn chat_stream_with_history<F>(
&mut self,
messages: Vec<ChatMessage>,
temperature: Option<f32>,
max_tokens: Option<u32>,
stop: Option<Vec<String>>,
on_chunk: F,
) -> Result<ChatMessage>
pub async fn chat_stream_with_history<F>( &mut self, messages: Vec<ChatMessage>, temperature: Option<f32>, max_tokens: Option<u32>, stop: Option<Vec<String>>, on_chunk: F, ) -> Result<ChatMessage>
Executes a stateless conversation with the provided message history and streams the response.
This method creates a temporary chat session with the provided messages and streams the agent’s response in real-time as tokens are generated. Note: Tool calls are not supported in streaming mode yet - they will be executed after the initial response is complete.
§Arguments
messages- The complete conversation history for this requesttemperature- Optional temperature parameter for generationmax_tokens- Optional maximum tokens parameter for generationstop- Optional stop sequences for generationon_chunk- Callback function called for each chunk of generated text
§Returns
A Result containing the final assistant message after streaming is complete.