-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.py
More file actions
29 lines (23 loc) · 1.25 KB
/
Copy pathmemory.py
File metadata and controls
29 lines (23 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Note that this is not needed as the agents have built in memory.But for long run / long memory , this is a good approach.
"""The 'memorize' tool for agents to affect session states."""
from google.adk.tools import ToolContext
# Note: This function will be registered as a tool in the agent definition.
def memorize(key: str, value: str, tool_context: ToolContext):
"""
Memorize pieces of information, one key-value pair at a time.
Use this to store results or context for later agents in the sequence.
Args:
key: the label (string) indexing the memory to store the value.
Use descriptive keys like 'research_findings' or 'verification_report'.
value: the information (string) to be stored.
tool_context: The ADK tool context, providing access to session state.
Returns:
A status message confirming the storage.
"""
# Access the session state dictionary via tool_context
mem_dict = tool_context.state
mem_dict[key] = value
print(f"[Memory Tool] Stored key='{key}'") # Added print for debugging
return {"status": f'Successfully stored information under key "{key}".'}
# If needed later, other functions like memorize_list or forget can be added here
# following the same pattern.