agent_with_memory_db/
agent_with_memory_db.rs1use helios_engine::{Agent, Config, MemoryDBTool};
9
10#[tokio::main]
11async fn main() -> helios_engine::Result<()> {
12 println!("š Helios Engine - Agent with Memory DB Example");
13 println!("================================================\n");
14
15 let config = Config::from_file("config.toml").unwrap_or_else(|_| {
17 println!("ā No config.toml found, using default configuration");
18 Config::new_default()
19 });
20
21 let mut agent = Agent::builder("DataAgent")
23 .config(config)
24 .system_prompt(
25 "You are a helpful assistant with access to an in-memory database. \
26 You can store and retrieve information using the memory_db tool. \
27 Operations available: set, get, delete, list, clear, exists. \
28 Use this to remember important information across our conversation."
29 )
30 .tool(Box::new(MemoryDBTool::new()))
31 .max_iterations(10)
32 .build()
33 .await?;
34
35 println!("ā Agent created with memory database tool\n");
36
37 println!("Example 1: Storing User Preferences");
39 println!("====================================\n");
40
41 let response = agent
42 .chat("Store my name as 'Alice' and my favorite color as 'blue' in the database")
43 .await?;
44 println!("Agent: {}\n", response);
45
46 println!("\nExample 2: Retrieving Stored Data");
48 println!("==================================\n");
49
50 let response = agent
51 .chat("What's my name and favorite color?")
52 .await?;
53 println!("Agent: {}\n", response);
54
55 println!("\nExample 3: Caching Calculations");
57 println!("================================\n");
58
59 let response = agent
60 .chat("Calculate 123 * 456 and store the result in the database with key 'calculation_result'")
61 .await?;
62 println!("Agent: {}\n", response);
63
64 println!("\nExample 4: Listing All Data");
66 println!("===========================\n");
67
68 let response = agent
69 .chat("Show me everything stored in the database")
70 .await?;
71 println!("Agent: {}\n", response);
72
73 println!("\nExample 5: Checking Key Existence");
75 println!("==================================\n");
76
77 let response = agent
78 .chat("Check if 'name' and 'age' exist in the database")
79 .await?;
80 println!("Agent: {}\n", response);
81
82 println!("\nExample 6: Deleting Data");
84 println!("========================\n");
85
86 let response = agent
87 .chat("Delete the 'calculation_result' from the database")
88 .await?;
89 println!("Agent: {}\n", response);
90
91 println!("\nExample 7: Final Database State");
93 println!("================================\n");
94
95 let response = agent
96 .chat("List all remaining items in the database")
97 .await?;
98 println!("Agent: {}\n", response);
99
100 println!("\nā
Example completed successfully!");
101 println!("\nš” Key Features Demonstrated:");
102 println!(" ⢠Setting key-value pairs in memory database");
103 println!(" ⢠Retrieving stored values");
104 println!(" ⢠Listing all database contents");
105 println!(" ⢠Checking key existence");
106 println!(" ⢠Deleting specific entries");
107 println!(" ⢠Persistent data across multiple agent interactions");
108 println!("\nš Use Cases:");
109 println!(" ⢠Caching expensive computations");
110 println!(" ⢠Storing user preferences during conversation");
111 println!(" ⢠Maintaining context across multiple queries");
112 println!(" ⢠Temporary data storage for complex workflows");
113
114 Ok(())
115}