pub struct MemoryDBTool { /* private fields */ }Expand description
In-Memory Database Tool
Provides a simple key-value store for agents to cache data during conversations. Supports set, get, delete, list keys, and clear operations.
Implementations§
Source§impl MemoryDBTool
impl MemoryDBTool
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/agent_with_memory_db.rs (line 30)
11async fn main() -> helios_engine::Result<()> {
12 println!("🚀 Helios Engine - Agent with Memory DB 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 memory database tool
22 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 // Example 1: Store user preferences
38 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 // Example 2: Retrieve stored data
47 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 // Example 3: Store calculations
56 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 // Example 4: List all stored data
65 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 // Example 5: Check if key exists
74 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 // Example 6: Delete specific data
83 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 // Example 7: Final state
92 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}Trait Implementations§
Source§impl Default for MemoryDBTool
impl Default for MemoryDBTool
Source§impl Tool for MemoryDBTool
impl Tool for MemoryDBTool
fn name(&self) -> &str
fn description(&self) -> &str
fn parameters(&self) -> HashMap<String, ToolParameter>
fn execute<'life0, 'async_trait>(
&'life0 self,
args: Value,
) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn to_definition(&self) -> ToolDefinition
Auto Trait Implementations§
impl Freeze for MemoryDBTool
impl RefUnwindSafe for MemoryDBTool
impl Send for MemoryDBTool
impl Sync for MemoryDBTool
impl Unpin for MemoryDBTool
impl UnwindSafe for MemoryDBTool
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