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