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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
from personal_agent.memory.models import WorkingMemory
from personal_agent.tools.base import Tool, ToolError, ToolResult
class TaskStartTool(Tool):
def __init__(self, memory: WorkingMemory) -> None:
self.memory = memory
@property
def name(self) -> str:
return "task_start"
@property
def description(self) -> str:
return (
"Record the user's ongoing project or goal as the current task. "
"Use this when the user intends to work on something across multiple "
"turns or over a period of time. Do not use it for one-off requests "
"or temporary side conversations."
)
@property
def schema(self) -> dict[str, object]:
return {
"type": "object",
"properties": {
"objective": {
"type": "string",
"description": (
"A concise description of the durable goal the user wants to pursue. "
"Describe what they are trying to accomplish, not mutable implementation "
"details, preferences, or constraints. For example: "
"'Build an image tagging API' or "
"'Design and implement a Rust CLI that converts directory trees into "
"static HTML.'"
),
},
},
"required": ["objective"],
}
def execute(self, arguments: dict[str, object]) -> ToolResult:
objective = arguments.get("objective")
if not isinstance(objective, str):
raise ToolError("objective must be a string")
if not objective.strip():
raise ToolError("objective must not be empty")
self.memory.start_task(objective)
return ToolResult(content=f"Started task: {objective}")
class MemoryAddFactTool(Tool):
def __init__(self, memory: WorkingMemory) -> None:
self.memory = memory
@property
def name(self) -> str:
return "memory_add_fact"
@property
def description(self) -> str:
return "Add a useful fact to the current working memory."
@property
def schema(self) -> dict[str, object]:
return {
"type": "object",
"properties": {
"fact": {
"type": "string",
"description": "A fact worth remembering during the current task.",
},
},
"required": ["fact"],
}
def execute(self, arguments: dict[str, object]) -> ToolResult:
fact = arguments.get("fact")
if not isinstance(fact, str):
raise ToolError("fact must be a string")
self.memory.add_fact(fact)
return ToolResult(content=f"Added working-memory fact: {fact}")
class MemoryAddNoteTool(Tool):
def __init__(self, memory: WorkingMemory) -> None:
self.memory = memory
@property
def name(self) -> str:
return "memory_add_note"
@property
def description(self) -> str:
return "Add a useful note to the current working memory."
@property
def schema(self) -> dict[str, object]:
return {
"type": "object",
"properties": {
"note": {
"type": "string",
"description": "A useful observation, reminder, or note for the current task.",
},
},
"required": ["note"],
}
def execute(self, arguments: dict[str, object]) -> ToolResult:
note = arguments.get("note")
if not isinstance(note, str):
raise ToolError("note must be a string")
self.memory.add_note(note)
return ToolResult(content=f"Added working-memory note: {note}")
class MemoryRemoveFactTool(Tool):
def __init__(self, memory: WorkingMemory) -> None:
self.memory = memory
@property
def name(self) -> str:
return "memory_remove_fact"
@property
def description(self) -> str:
return "Remove a fact from the working memory when it is no longer true or relevant."
@property
def schema(self) -> dict[str, object]:
return {
"type": "object",
"properties": {
"fact": {
"type": "string",
"description": "The exact fact to remove from working memory.",
},
},
"required": ["fact"],
}
def execute(self, arguments: dict[str, object]) -> ToolResult:
fact = arguments.get("fact")
if not isinstance(fact, str):
raise ToolError("fact must be a string")
self.memory.remove_fact(fact)
return ToolResult(content=f"Removed fact: {fact}")
class MemoryRemoveNoteTool(Tool):
def __init__(self, memory: WorkingMemory) -> None:
self.memory = memory
@property
def name(self) -> str:
return "memory_remove_note"
@property
def description(self) -> str:
return "Remove a note from the working memory when it is no longer true or relevant."
@property
def schema(self) -> dict[str, object]:
return {
"type": "object",
"properties": {
"note": {
"type": "string",
"description": "The exact note to remove from working memory.",
},
},
"required": ["note"],
}
def execute(self, arguments: dict[str, object]) -> ToolResult:
note = arguments.get("note")
if not isinstance(note, str):
raise ToolError("note must be a string")
self.memory.remove_note(note)
return ToolResult(content=f"Removed note: {note}")
|