adk_tool/
simple_context.rs1use adk_core::context::{Artifacts, CallbackContext, MemoryEntry, ReadonlyContext};
18use adk_core::types::Content;
19use adk_core::{EventActions, Result, ToolContext};
20use async_trait::async_trait;
21use std::sync::{Arc, Mutex};
22
23pub struct SimpleToolContext {
29 caller_name: String,
30 invocation_id: String,
31 function_call_id: String,
32 user_content: Content,
33 actions: Mutex<EventActions>,
34}
35
36impl SimpleToolContext {
37 pub fn new(caller_name: impl Into<String>) -> Self {
43 Self {
44 caller_name: caller_name.into(),
45 invocation_id: uuid::Uuid::new_v4().to_string(),
46 function_call_id: uuid::Uuid::new_v4().to_string(),
47 user_content: Content::new("user"),
48 actions: Mutex::new(EventActions::default()),
49 }
50 }
51
52 pub fn with_function_call_id(mut self, id: impl Into<String>) -> Self {
57 self.function_call_id = id.into();
58 self
59 }
60}
61
62#[async_trait]
63impl ReadonlyContext for SimpleToolContext {
64 fn invocation_id(&self) -> &str {
65 &self.invocation_id
66 }
67
68 fn agent_name(&self) -> &str {
69 &self.caller_name
70 }
71
72 fn user_id(&self) -> &str {
73 "anonymous"
74 }
75
76 fn app_name(&self) -> &str {
77 &self.caller_name
78 }
79
80 fn session_id(&self) -> &str {
81 ""
82 }
83
84 fn branch(&self) -> &str {
85 ""
86 }
87
88 fn user_content(&self) -> &Content {
89 &self.user_content
90 }
91}
92
93#[async_trait]
94impl CallbackContext for SimpleToolContext {
95 fn artifacts(&self) -> Option<Arc<dyn Artifacts>> {
96 None
97 }
98}
99
100#[async_trait]
101impl ToolContext for SimpleToolContext {
102 fn function_call_id(&self) -> &str {
103 &self.function_call_id
104 }
105
106 fn actions(&self) -> EventActions {
107 self.actions.lock().unwrap().clone()
108 }
109
110 fn set_actions(&self, actions: EventActions) {
111 *self.actions.lock().unwrap() = actions;
112 }
113
114 async fn search_memory(&self, _query: &str) -> Result<Vec<MemoryEntry>> {
115 Ok(vec![])
116 }
117}