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
Creates a new MemoryDBTool.
Examples found in repository?
examples/agent_with_memory_db.rs (line 29)
10async fn main() -> helios_engine::Result<()> {
11 println!("🚀 Helios Engine - Agent with Memory DB Example");
12 println!("================================================\n");
13
14 // Load configuration from `config.toml` or use default.
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 "DataAgent" and equip it with the MemoryDBTool.
21 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 // --- Example 1: Store user preferences ---
37 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 // --- Example 2: Retrieve stored data ---
46 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 // --- Example 3: Store calculations ---
53 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 // --- Example 4: List all stored data ---
62 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 // --- Example 5: Check if key exists ---
71 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 // --- Example 6: Delete specific data ---
80 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 // --- Example 7: Final state ---
89 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}Creates a new MemoryDBTool with a shared database.
Trait Implementations§
Source§impl Default for MemoryDBTool
impl Default for MemoryDBTool
Source§impl Tool for MemoryDBTool
impl Tool for MemoryDBTool
Source§fn description(&self) -> &str
fn description(&self) -> &str
A description of the tool.
Source§fn parameters(&self) -> HashMap<String, ToolParameter>
fn parameters(&self) -> HashMap<String, ToolParameter>
The parameters for the tool.
Source§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 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,
Executes the tool with the given arguments.
Source§fn to_definition(&self) -> ToolDefinition
fn to_definition(&self) -> ToolDefinition
Converts the tool to a
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 UnsafeUnpin 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