helloparthshah commited on
Commit
b3d741d
·
1 Parent(s): bf8a152

Memory actions work

Browse files
src/models/system3.prompt CHANGED
@@ -34,7 +34,7 @@ If you're over this budget, you can no longer create new tools. In case this hap
34
  </Info>
35
 
36
  <Info>
37
- If user shares something important or sensitive, you should usee the UpdateMemory tool to store this information. Include details such as the user's preferences, how you solved errors, and any other relevant context that could help in future interactions. This will help you provide better assistance in the future.
38
  </Info>
39
 
40
  Here's a set of rules you must follow:
@@ -123,25 +123,42 @@ When you go over the resource budget, you must carefully evaluate which agent is
123
  </Rule>
124
 
125
  <Rule>
126
- Whenever you encounter an error — in logic, execution, tool invocation, or agent behaviorand resolve it, you must invoke the UpdateMemory tool immediately. The stored memory must include:
127
- (1) the nature of the error,
128
- (2) how it was identified,
129
- (3) the correction applied, and
130
- (4) the conversational or technical context in which it occurred.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  </Rule>
132
 
133
  <Rule>
134
- Whenever the user provides corrections, preferences, or feedback whether direct or implied — you must invoke the UpdateMemory tool to store this information. The stored memory must include:
135
- (1) the user’s exact correction or feedback,
136
- (2) the assistant's original output that was corrected or improved,
137
- (3) any inferred preferences, communication style, tone, or priorities the user reveals.
 
138
  </Rule>
139
 
140
  <Rule>
141
- If the user shares any information that is relevant to their identity, values, goals, recurring interests, working style, emotional state, or long-term projects, you must store it using the UpdateMemory tool. Ensure this includes:
142
- - Important biographical or academic details
143
- - Technical preferences or frequently used frameworks/tools
144
- - Emotional patterns or motivational triggers
145
- - Career objectives, research themes, or ongoing concerns
146
- - Personal principles, values, or recurring philosophical stances
147
  </Rule>
 
 
34
  </Info>
35
 
36
  <Info>
37
+ If user shares something important or sensitive, you should usee the MemoryManager tool to store this information. Include details such as the user's preferences, how you solved errors, and any other relevant context that could help in future interactions. This will help you provide better assistance in the future.
38
  </Info>
39
 
40
  Here's a set of rules you must follow:
 
123
  </Rule>
124
 
125
  <Rule>
126
+ When you encounter and successfully fix an error — including logic flaws, failed tool invocations, or agent misbehavior — you must invoke the MemoryManager tool with:
127
+ - action: "add_memory"
128
+ - memory: A detailed string describing:
129
+ The original error,
130
+ How it was detected,
131
+ • The applied fix,
132
+ • And the context of the issue.
133
+
134
+ This ensures persistent tracking of learning and system evolution.
135
+ </Rule>
136
+
137
+ <Rule>
138
+ Whenever the user provides feedback, corrections, or clarification — whether explicitly or implicitly — you must invoke the MemoryManager tool with:
139
+ - action: "add_memory"
140
+ - memory: A string summarizing:
141
+ • The user’s input verbatim,
142
+ • The assistant’s original behavior that was corrected,
143
+ • The updated behavior or lesson learned,
144
+ • And any inferred user preferences or tone adjustments.
145
+
146
+ This enables personalized, adaptive responses over time.
147
  </Rule>
148
 
149
  <Rule>
150
+ If the user shares enduring personal context — such as biographical facts, technical expertise, long-term goals, emotional tendencies, or preferred interaction style — you must invoke the MemoryManager tool with:
151
+ - action: "add_memory"
152
+ - memory: A string encoding this information for future reference.
153
+
154
+ This ensures continuity and personalization across sessions.
155
  </Rule>
156
 
157
  <Rule>
158
+ When the user explicitly requests deletion of a memory, or when a previously stored memory becomes obsolete, invalid, or counterproductive, you must invoke the MemoryManager tool with:
159
+ - action: "delete_memory"
160
+ - index: The index of the memory to remove (as returned from a prior "get_memory" action).
161
+
162
+ Always confirm that the index is valid before deletion. If uncertain, retrieve the memory list first.
 
163
  </Rule>
164
+
src/tools/default_tools/memory_manager.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ __all__ = ['MemoryManager']
3
+
4
+ import json
5
+
6
+
7
+ class MemoryManager():
8
+ dependencies = []
9
+
10
+ inputSchema = {
11
+ "name": "MemoryManager",
12
+ "description": "Updates, retrieves, or deletes the memory of an AI agent. The memory is stored in a JSON file.",
13
+ "parameters": {
14
+ "type": "object",
15
+ "properties":{
16
+ "action": {
17
+ "type": "string",
18
+ "enum": ["add_memory", "get_memory", "delete_memory"],
19
+ "description": "The action to perform: add_memory, get_memory, or delete_memory.",
20
+ },
21
+ "memory": {
22
+ "type": "string",
23
+ "description": "The memory to add. Required for 'add_memory' action.",
24
+ },
25
+ "index": {
26
+ "type": "integer",
27
+ "description": "The index of the memory to delete. Required for 'delete_memory' action.",
28
+ },
29
+ },
30
+ "required": ["action"],
31
+ },
32
+ }
33
+
34
+ def get_memories(self):
35
+ # load the memory from src/data/memory.json
36
+ try:
37
+ with open("src/data/memory.json", "r") as f:
38
+ memory_list = json.load(f)
39
+ except FileNotFoundError:
40
+ memory_list = []
41
+ except json.JSONDecodeError:
42
+ memory_list = []
43
+ return memory_list
44
+
45
+ def update_memories(self, memories):
46
+ # save the memory to src/data/memory.json
47
+ with open("src/data/memory.json", "w") as f:
48
+ json.dump(memories, f)
49
+
50
+
51
+ def run(self, **kwargs):
52
+ # save it to src/data/memory.json
53
+ action = kwargs.get("action")
54
+ memory = kwargs.get("memory")
55
+ index = kwargs.get("index")
56
+ memories = self.get_memories()
57
+ if action == "get_memory":
58
+ return {
59
+ "status": "success",
60
+ "message": "Memory retrieved successfully",
61
+ "output": memories
62
+ }
63
+ if action == "add_memory":
64
+ if memory is None:
65
+ return {
66
+ "status": "error",
67
+ "message": "Memory is required for add_memory action",
68
+ "output": None
69
+ }
70
+ memories.append(memory)
71
+ self.update_memories(memories)
72
+ return {
73
+ "status": "success",
74
+ "message": "Memory created successfully",
75
+ "output": None
76
+ }
77
+ if action == "delete_memory":
78
+ if index is None:
79
+ return {
80
+ "status": "error",
81
+ "message": "Index is required for delete_memory action",
82
+ "output": None
83
+ }
84
+ if index < 0 or index >= len(memories):
85
+ return {
86
+ "status": "error",
87
+ "message": "Index out of range",
88
+ "output": None
89
+ }
90
+ memories.pop(index)
91
+ self.update_memories(memories)
92
+ return {
93
+ "status": "success",
94
+ "message": "Memory deleted successfully",
95
+ "output": None
96
+ }
src/tools/default_tools/update_memory.py DELETED
@@ -1,55 +0,0 @@
1
-
2
- __all__ = ['UpdateMemory']
3
-
4
- import json
5
-
6
-
7
- class UpdateMemory():
8
- dependencies = []
9
-
10
- inputSchema = {
11
- "name": "UpdateMemory",
12
- "description": "Updates the memory of the AI agent. This tool is used to update the memory of the AI agent with new information.",
13
- "parameters": {
14
- "type": "object",
15
- "properties":{
16
- "memory": {
17
- "type": "string",
18
- "description": "The new memory to be added to the AI agent's memory.",
19
- }
20
- },
21
- "required": ["memory"],
22
- },
23
- }
24
-
25
-
26
- def run(self, **kwargs):
27
- # save it to src/data/memory.json
28
- memory = kwargs.get("memory")
29
- if not memory:
30
- return {
31
- "status": "error",
32
- "message": "Memory is required",
33
- "output": None
34
- }
35
- # add the memory to the memory.json file which is list of strings
36
- # create the file if it does not exist
37
- try:
38
- with open("src/data/memory.json", "r") as f:
39
- memory_list = json.load(f)
40
- except FileNotFoundError:
41
- memory_list = []
42
- except json.JSONDecodeError:
43
- memory_list = []
44
-
45
- # add the new memory to the list
46
- memory_list.append(memory)
47
- # save the list to the file
48
- with open("src/data/memory.json", "w") as f:
49
- json.dump(memory_list, f)
50
- # return the list of memories
51
- return {
52
- "status": "success",
53
- "message": "Memory updated successfully",
54
- "output": memory_list
55
- }