rs_adk/tools/
load_memory.rs1use async_trait::async_trait;
7
8use crate::error::ToolError;
9use crate::tool::ToolFunction;
10
11#[derive(Debug, Clone, Default)]
16pub struct LoadMemoryTool;
17
18impl LoadMemoryTool {
19 pub fn new() -> Self {
21 Self
22 }
23}
24
25#[async_trait]
26impl ToolFunction for LoadMemoryTool {
27 fn name(&self) -> &str {
28 "load_memory"
29 }
30
31 fn description(&self) -> &str {
32 "Search and load relevant information from the agent's memory. \
33 Call this function with a query to retrieve previously stored memories."
34 }
35
36 fn parameters(&self) -> Option<serde_json::Value> {
37 Some(serde_json::json!({
38 "type": "object",
39 "properties": {
40 "query": {
41 "type": "string",
42 "description": "The search query to find relevant memories."
43 }
44 },
45 "required": ["query"]
46 }))
47 }
48
49 async fn call(&self, args: serde_json::Value) -> Result<serde_json::Value, ToolError> {
50 let query = args.get("query").and_then(|v| v.as_str()).unwrap_or("");
51
52 Ok(serde_json::json!({
57 "status": "memory_search_requested",
58 "query": query,
59 "results": []
60 }))
61 }
62}
63
64#[cfg(test)]
65mod tests {
66 use super::*;
67 use serde_json::json;
68
69 #[test]
70 fn tool_metadata() {
71 let tool = LoadMemoryTool::new();
72 assert_eq!(tool.name(), "load_memory");
73 assert!(tool.description().contains("memory"));
74 assert!(tool.parameters().is_some());
75 }
76
77 #[tokio::test]
78 async fn call_with_query() {
79 let tool = LoadMemoryTool::new();
80 let result = tool
81 .call(json!({"query": "user preferences"}))
82 .await
83 .unwrap();
84 assert_eq!(result["query"], "user preferences");
85 }
86}