powermem 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- powermem/__init__.py +103 -0
- powermem/agent/__init__.py +35 -0
- powermem/agent/abstract/__init__.py +22 -0
- powermem/agent/abstract/collaboration.py +259 -0
- powermem/agent/abstract/context.py +187 -0
- powermem/agent/abstract/manager.py +232 -0
- powermem/agent/abstract/permission.py +217 -0
- powermem/agent/abstract/privacy.py +267 -0
- powermem/agent/abstract/scope.py +199 -0
- powermem/agent/agent.py +791 -0
- powermem/agent/components/__init__.py +18 -0
- powermem/agent/components/collaboration_coordinator.py +645 -0
- powermem/agent/components/permission_controller.py +586 -0
- powermem/agent/components/privacy_protector.py +767 -0
- powermem/agent/components/scope_controller.py +685 -0
- powermem/agent/factories/__init__.py +16 -0
- powermem/agent/factories/agent_factory.py +266 -0
- powermem/agent/factories/config_factory.py +308 -0
- powermem/agent/factories/memory_factory.py +229 -0
- powermem/agent/implementations/__init__.py +16 -0
- powermem/agent/implementations/hybrid.py +728 -0
- powermem/agent/implementations/multi_agent.py +1040 -0
- powermem/agent/implementations/multi_user.py +1020 -0
- powermem/agent/types.py +53 -0
- powermem/agent/wrappers/__init__.py +14 -0
- powermem/agent/wrappers/agent_memory_wrapper.py +427 -0
- powermem/agent/wrappers/compatibility_wrapper.py +520 -0
- powermem/config_loader.py +318 -0
- powermem/configs.py +249 -0
- powermem/core/__init__.py +19 -0
- powermem/core/async_memory.py +1493 -0
- powermem/core/audit.py +258 -0
- powermem/core/base.py +165 -0
- powermem/core/memory.py +1567 -0
- powermem/core/setup.py +162 -0
- powermem/core/telemetry.py +215 -0
- powermem/integrations/__init__.py +17 -0
- powermem/integrations/embeddings/__init__.py +13 -0
- powermem/integrations/embeddings/aws_bedrock.py +100 -0
- powermem/integrations/embeddings/azure_openai.py +55 -0
- powermem/integrations/embeddings/base.py +31 -0
- powermem/integrations/embeddings/config/base.py +132 -0
- powermem/integrations/embeddings/configs.py +31 -0
- powermem/integrations/embeddings/factory.py +48 -0
- powermem/integrations/embeddings/gemini.py +39 -0
- powermem/integrations/embeddings/huggingface.py +41 -0
- powermem/integrations/embeddings/langchain.py +35 -0
- powermem/integrations/embeddings/lmstudio.py +29 -0
- powermem/integrations/embeddings/mock.py +11 -0
- powermem/integrations/embeddings/ollama.py +53 -0
- powermem/integrations/embeddings/openai.py +49 -0
- powermem/integrations/embeddings/qwen.py +102 -0
- powermem/integrations/embeddings/together.py +31 -0
- powermem/integrations/embeddings/vertexai.py +54 -0
- powermem/integrations/llm/__init__.py +18 -0
- powermem/integrations/llm/anthropic.py +87 -0
- powermem/integrations/llm/base.py +132 -0
- powermem/integrations/llm/config/anthropic.py +56 -0
- powermem/integrations/llm/config/azure.py +56 -0
- powermem/integrations/llm/config/base.py +62 -0
- powermem/integrations/llm/config/deepseek.py +56 -0
- powermem/integrations/llm/config/ollama.py +56 -0
- powermem/integrations/llm/config/openai.py +79 -0
- powermem/integrations/llm/config/qwen.py +68 -0
- powermem/integrations/llm/config/qwen_asr.py +46 -0
- powermem/integrations/llm/config/vllm.py +56 -0
- powermem/integrations/llm/configs.py +26 -0
- powermem/integrations/llm/deepseek.py +106 -0
- powermem/integrations/llm/factory.py +118 -0
- powermem/integrations/llm/gemini.py +201 -0
- powermem/integrations/llm/langchain.py +65 -0
- powermem/integrations/llm/ollama.py +106 -0
- powermem/integrations/llm/openai.py +166 -0
- powermem/integrations/llm/openai_structured.py +80 -0
- powermem/integrations/llm/qwen.py +207 -0
- powermem/integrations/llm/qwen_asr.py +171 -0
- powermem/integrations/llm/vllm.py +106 -0
- powermem/integrations/rerank/__init__.py +20 -0
- powermem/integrations/rerank/base.py +43 -0
- powermem/integrations/rerank/config/__init__.py +7 -0
- powermem/integrations/rerank/config/base.py +27 -0
- powermem/integrations/rerank/configs.py +23 -0
- powermem/integrations/rerank/factory.py +68 -0
- powermem/integrations/rerank/qwen.py +159 -0
- powermem/intelligence/__init__.py +17 -0
- powermem/intelligence/ebbinghaus_algorithm.py +354 -0
- powermem/intelligence/importance_evaluator.py +361 -0
- powermem/intelligence/intelligent_memory_manager.py +284 -0
- powermem/intelligence/manager.py +148 -0
- powermem/intelligence/plugin.py +229 -0
- powermem/prompts/__init__.py +29 -0
- powermem/prompts/graph/graph_prompts.py +217 -0
- powermem/prompts/graph/graph_tools_prompts.py +469 -0
- powermem/prompts/importance_evaluation.py +246 -0
- powermem/prompts/intelligent_memory_prompts.py +163 -0
- powermem/prompts/templates.py +193 -0
- powermem/storage/__init__.py +14 -0
- powermem/storage/adapter.py +896 -0
- powermem/storage/base.py +109 -0
- powermem/storage/config/base.py +13 -0
- powermem/storage/config/oceanbase.py +58 -0
- powermem/storage/config/pgvector.py +52 -0
- powermem/storage/config/sqlite.py +27 -0
- powermem/storage/configs.py +159 -0
- powermem/storage/factory.py +59 -0
- powermem/storage/migration_manager.py +438 -0
- powermem/storage/oceanbase/__init__.py +8 -0
- powermem/storage/oceanbase/constants.py +162 -0
- powermem/storage/oceanbase/oceanbase.py +1384 -0
- powermem/storage/oceanbase/oceanbase_graph.py +1441 -0
- powermem/storage/pgvector/__init__.py +7 -0
- powermem/storage/pgvector/pgvector.py +420 -0
- powermem/storage/sqlite/__init__.py +0 -0
- powermem/storage/sqlite/sqlite.py +218 -0
- powermem/storage/sqlite/sqlite_vector_store.py +311 -0
- powermem/utils/__init__.py +35 -0
- powermem/utils/utils.py +605 -0
- powermem/version.py +23 -0
- powermem-0.1.0.dist-info/METADATA +187 -0
- powermem-0.1.0.dist-info/RECORD +123 -0
- powermem-0.1.0.dist-info/WHEEL +5 -0
- powermem-0.1.0.dist-info/licenses/LICENSE +206 -0
- powermem-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Graph tools prompts for memory operations
|
|
3
|
+
|
|
4
|
+
This module provides tool definitions for graph-based memory operations.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
from typing import Dict, Any, Optional, List
|
|
9
|
+
from ..templates import PromptTemplates
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
# Tool definitions constants
|
|
14
|
+
UPDATE_MEMORY_TOOL_GRAPH = {
|
|
15
|
+
"type": "function",
|
|
16
|
+
"function": {
|
|
17
|
+
"name": "update_graph_memory",
|
|
18
|
+
"description": "Update the relationship key of an existing graph memory based on new information. This function should be called when there's a need to modify an existing relationship in the knowledge graph. The update should only be performed if the new information is more recent, more accurate, or provides additional context compared to the existing information. The source and destination nodes of the relationship must remain the same as in the existing graph memory; only the relationship itself can be updated.",
|
|
19
|
+
"parameters": {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"properties": {
|
|
22
|
+
"source": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"description": "The identifier of the source node in the relationship to be updated. This should match an existing node in the graph.",
|
|
25
|
+
},
|
|
26
|
+
"destination": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"description": "The identifier of the destination node in the relationship to be updated. This should match an existing node in the graph.",
|
|
29
|
+
},
|
|
30
|
+
"relationship": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"description": "The new or updated relationship between the source and destination nodes. This should be a concise, clear description of how the two nodes are connected.",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
"required": ["source", "destination", "relationship"],
|
|
36
|
+
"additionalProperties": False,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
ADD_MEMORY_TOOL_GRAPH = {
|
|
42
|
+
"type": "function",
|
|
43
|
+
"function": {
|
|
44
|
+
"name": "add_graph_memory",
|
|
45
|
+
"description": "Add a new graph memory to the knowledge graph. This function creates a new relationship between two nodes, potentially creating new nodes if they don't exist.",
|
|
46
|
+
"parameters": {
|
|
47
|
+
"type": "object",
|
|
48
|
+
"properties": {
|
|
49
|
+
"source": {
|
|
50
|
+
"type": "string",
|
|
51
|
+
"description": "The identifier of the source node in the new relationship. This can be an existing node or a new node to be created.",
|
|
52
|
+
},
|
|
53
|
+
"destination": {
|
|
54
|
+
"type": "string",
|
|
55
|
+
"description": "The identifier of the destination node in the new relationship. This can be an existing node or a new node to be created.",
|
|
56
|
+
},
|
|
57
|
+
"relationship": {
|
|
58
|
+
"type": "string",
|
|
59
|
+
"description": "The type of relationship between the source and destination nodes. This should be a concise, clear description of how the two nodes are connected.",
|
|
60
|
+
},
|
|
61
|
+
"source_type": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"description": "The type or category of the source node. This helps in classifying and organizing nodes in the graph.",
|
|
64
|
+
},
|
|
65
|
+
"destination_type": {
|
|
66
|
+
"type": "string",
|
|
67
|
+
"description": "The type or category of the destination node. This helps in classifying and organizing nodes in the graph.",
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
"required": [
|
|
71
|
+
"source",
|
|
72
|
+
"destination",
|
|
73
|
+
"relationship",
|
|
74
|
+
"source_type",
|
|
75
|
+
"destination_type",
|
|
76
|
+
],
|
|
77
|
+
"additionalProperties": False,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
DELETE_MEMORY_TOOL_GRAPH = {
|
|
83
|
+
"type": "function",
|
|
84
|
+
"function": {
|
|
85
|
+
"name": "delete_graph_memory",
|
|
86
|
+
"description": "Delete the relationship between two nodes. This function deletes the existing relationship.",
|
|
87
|
+
"parameters": {
|
|
88
|
+
"type": "object",
|
|
89
|
+
"properties": {
|
|
90
|
+
"source": {
|
|
91
|
+
"type": "string",
|
|
92
|
+
"description": "The identifier of the source node in the relationship.",
|
|
93
|
+
},
|
|
94
|
+
"relationship": {
|
|
95
|
+
"type": "string",
|
|
96
|
+
"description": "The existing relationship between the source and destination nodes that needs to be deleted.",
|
|
97
|
+
},
|
|
98
|
+
"destination": {
|
|
99
|
+
"type": "string",
|
|
100
|
+
"description": "The identifier of the destination node in the relationship.",
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
"required": [
|
|
104
|
+
"source",
|
|
105
|
+
"relationship",
|
|
106
|
+
"destination",
|
|
107
|
+
],
|
|
108
|
+
"additionalProperties": False,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
NOOP_TOOL = {
|
|
114
|
+
"type": "function",
|
|
115
|
+
"function": {
|
|
116
|
+
"name": "noop",
|
|
117
|
+
"description": "No operation should be performed to the graph entities. This function is called when the system determines that no changes or additions are necessary based on the current input or context. It serves as a placeholder action when no other actions are required, ensuring that the system can explicitly acknowledge situations where no modifications to the graph are needed.",
|
|
118
|
+
"parameters": {
|
|
119
|
+
"type": "object",
|
|
120
|
+
"properties": {},
|
|
121
|
+
"required": [],
|
|
122
|
+
"additionalProperties": False,
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
RELATIONS_TOOL = {
|
|
129
|
+
"type": "function",
|
|
130
|
+
"function": {
|
|
131
|
+
"name": "establish_relationships",
|
|
132
|
+
"description": "Establish relationships among the entities based on the provided text.",
|
|
133
|
+
"parameters": {
|
|
134
|
+
"type": "object",
|
|
135
|
+
"properties": {
|
|
136
|
+
"entities": {
|
|
137
|
+
"type": "array",
|
|
138
|
+
"items": {
|
|
139
|
+
"type": "object",
|
|
140
|
+
"properties": {
|
|
141
|
+
"source": {"type": "string", "description": "The source entity of the relationship."},
|
|
142
|
+
"relationship": {
|
|
143
|
+
"type": "string",
|
|
144
|
+
"description": "The relationship between the source and destination entities.",
|
|
145
|
+
},
|
|
146
|
+
"destination": {
|
|
147
|
+
"type": "string",
|
|
148
|
+
"description": "The destination entity of the relationship.",
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
"required": [
|
|
152
|
+
"source",
|
|
153
|
+
"relationship",
|
|
154
|
+
"destination",
|
|
155
|
+
],
|
|
156
|
+
"additionalProperties": False,
|
|
157
|
+
},
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
"required": ["entities"],
|
|
161
|
+
"additionalProperties": False,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
EXTRACT_ENTITIES_TOOL = {
|
|
168
|
+
"type": "function",
|
|
169
|
+
"function": {
|
|
170
|
+
"name": "extract_entities",
|
|
171
|
+
"description": "Extract entities and their types from the text.",
|
|
172
|
+
"parameters": {
|
|
173
|
+
"type": "object",
|
|
174
|
+
"properties": {
|
|
175
|
+
"entities": {
|
|
176
|
+
"type": "array",
|
|
177
|
+
"items": {
|
|
178
|
+
"type": "object",
|
|
179
|
+
"properties": {
|
|
180
|
+
"entity": {"type": "string", "description": "The name or identifier of the entity."},
|
|
181
|
+
"entity_type": {"type": "string", "description": "The type or category of the entity."},
|
|
182
|
+
},
|
|
183
|
+
"required": ["entity", "entity_type"],
|
|
184
|
+
"additionalProperties": False,
|
|
185
|
+
},
|
|
186
|
+
"description": "An array of entities with their types.",
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
"required": ["entities"],
|
|
190
|
+
"additionalProperties": False,
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
# Structured versions (with strict=True)
|
|
196
|
+
UPDATE_MEMORY_STRUCT_TOOL_GRAPH = {
|
|
197
|
+
"type": "function",
|
|
198
|
+
"function": {
|
|
199
|
+
"name": "update_graph_memory",
|
|
200
|
+
"description": "Update the relationship key of an existing graph memory based on new information. This function should be called when there's a need to modify an existing relationship in the knowledge graph. The update should only be performed if the new information is more recent, more accurate, or provides additional context compared to the existing information. The source and destination nodes of the relationship must remain the same as in the existing graph memory; only the relationship itself can be updated.",
|
|
201
|
+
"strict": True,
|
|
202
|
+
"parameters": {
|
|
203
|
+
"type": "object",
|
|
204
|
+
"properties": {
|
|
205
|
+
"source": {
|
|
206
|
+
"type": "string",
|
|
207
|
+
"description": "The identifier of the source node in the relationship to be updated. This should match an existing node in the graph.",
|
|
208
|
+
},
|
|
209
|
+
"destination": {
|
|
210
|
+
"type": "string",
|
|
211
|
+
"description": "The identifier of the destination node in the relationship to be updated. This should match an existing node in the graph.",
|
|
212
|
+
},
|
|
213
|
+
"relationship": {
|
|
214
|
+
"type": "string",
|
|
215
|
+
"description": "The new or updated relationship between the source and destination nodes. This should be a concise, clear description of how the two nodes are connected.",
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
"required": ["source", "destination", "relationship"],
|
|
219
|
+
"additionalProperties": False,
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
ADD_MEMORY_STRUCT_TOOL_GRAPH = {
|
|
225
|
+
"type": "function",
|
|
226
|
+
"function": {
|
|
227
|
+
"name": "add_graph_memory",
|
|
228
|
+
"description": "Add a new graph memory to the knowledge graph. This function creates a new relationship between two nodes, potentially creating new nodes if they don't exist.",
|
|
229
|
+
"strict": True,
|
|
230
|
+
"parameters": {
|
|
231
|
+
"type": "object",
|
|
232
|
+
"properties": {
|
|
233
|
+
"source": {
|
|
234
|
+
"type": "string",
|
|
235
|
+
"description": "The identifier of the source node in the new relationship. This can be an existing node or a new node to be created.",
|
|
236
|
+
},
|
|
237
|
+
"destination": {
|
|
238
|
+
"type": "string",
|
|
239
|
+
"description": "The identifier of the destination node in the new relationship. This can be an existing node or a new node to be created.",
|
|
240
|
+
},
|
|
241
|
+
"relationship": {
|
|
242
|
+
"type": "string",
|
|
243
|
+
"description": "The type of relationship between the source and destination nodes. This should be a concise, clear description of how the two nodes are connected.",
|
|
244
|
+
},
|
|
245
|
+
"source_type": {
|
|
246
|
+
"type": "string",
|
|
247
|
+
"description": "The type or category of the source node. This helps in classifying and organizing nodes in the graph.",
|
|
248
|
+
},
|
|
249
|
+
"destination_type": {
|
|
250
|
+
"type": "string",
|
|
251
|
+
"description": "The type or category of the destination node. This helps in classifying and organizing nodes in the graph.",
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
"required": [
|
|
255
|
+
"source",
|
|
256
|
+
"destination",
|
|
257
|
+
"relationship",
|
|
258
|
+
"source_type",
|
|
259
|
+
"destination_type",
|
|
260
|
+
],
|
|
261
|
+
"additionalProperties": False,
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
DELETE_MEMORY_STRUCT_TOOL_GRAPH = {
|
|
267
|
+
"type": "function",
|
|
268
|
+
"function": {
|
|
269
|
+
"name": "delete_graph_memory",
|
|
270
|
+
"description": "Delete the relationship between two nodes. This function deletes the existing relationship.",
|
|
271
|
+
"strict": True,
|
|
272
|
+
"parameters": {
|
|
273
|
+
"type": "object",
|
|
274
|
+
"properties": {
|
|
275
|
+
"source": {
|
|
276
|
+
"type": "string",
|
|
277
|
+
"description": "The identifier of the source node in the relationship.",
|
|
278
|
+
},
|
|
279
|
+
"relationship": {
|
|
280
|
+
"type": "string",
|
|
281
|
+
"description": "The existing relationship between the source and destination nodes that needs to be deleted.",
|
|
282
|
+
},
|
|
283
|
+
"destination": {
|
|
284
|
+
"type": "string",
|
|
285
|
+
"description": "The identifier of the destination node in the relationship.",
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
"required": [
|
|
289
|
+
"source",
|
|
290
|
+
"relationship",
|
|
291
|
+
"destination",
|
|
292
|
+
],
|
|
293
|
+
"additionalProperties": False,
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
NOOP_STRUCT_TOOL = {
|
|
299
|
+
"type": "function",
|
|
300
|
+
"function": {
|
|
301
|
+
"name": "noop",
|
|
302
|
+
"description": "No operation should be performed to the graph entities. This function is called when the system determines that no changes or additions are necessary based on the current input or context. It serves as a placeholder action when no other actions are required, ensuring that the system can explicitly acknowledge situations where no modifications to the graph are needed.",
|
|
303
|
+
"strict": True,
|
|
304
|
+
"parameters": {
|
|
305
|
+
"type": "object",
|
|
306
|
+
"properties": {},
|
|
307
|
+
"required": [],
|
|
308
|
+
"additionalProperties": False,
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
RELATIONS_STRUCT_TOOL = {
|
|
314
|
+
"type": "function",
|
|
315
|
+
"function": {
|
|
316
|
+
"name": "establish_relations",
|
|
317
|
+
"description": "Establish relationships among the entities based on the provided text.",
|
|
318
|
+
"strict": True,
|
|
319
|
+
"parameters": {
|
|
320
|
+
"type": "object",
|
|
321
|
+
"properties": {
|
|
322
|
+
"entities": {
|
|
323
|
+
"type": "array",
|
|
324
|
+
"items": {
|
|
325
|
+
"type": "object",
|
|
326
|
+
"properties": {
|
|
327
|
+
"source": {
|
|
328
|
+
"type": "string",
|
|
329
|
+
"description": "The source entity of the relationship.",
|
|
330
|
+
},
|
|
331
|
+
"relationship": {
|
|
332
|
+
"type": "string",
|
|
333
|
+
"description": "The relationship between the source and destination entities.",
|
|
334
|
+
},
|
|
335
|
+
"destination": {
|
|
336
|
+
"type": "string",
|
|
337
|
+
"description": "The destination entity of the relationship.",
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
"required": [
|
|
341
|
+
"source",
|
|
342
|
+
"relationship",
|
|
343
|
+
"destination",
|
|
344
|
+
],
|
|
345
|
+
"additionalProperties": False,
|
|
346
|
+
},
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
"required": ["entities"],
|
|
350
|
+
"additionalProperties": False,
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
EXTRACT_ENTITIES_STRUCT_TOOL = {
|
|
357
|
+
"type": "function",
|
|
358
|
+
"function": {
|
|
359
|
+
"name": "extract_entities",
|
|
360
|
+
"description": "Extract entities and their types from the text.",
|
|
361
|
+
"strict": True,
|
|
362
|
+
"parameters": {
|
|
363
|
+
"type": "object",
|
|
364
|
+
"properties": {
|
|
365
|
+
"entities": {
|
|
366
|
+
"type": "array",
|
|
367
|
+
"items": {
|
|
368
|
+
"type": "object",
|
|
369
|
+
"properties": {
|
|
370
|
+
"entity": {"type": "string", "description": "The name or identifier of the entity."},
|
|
371
|
+
"entity_type": {"type": "string", "description": "The type or category of the entity."},
|
|
372
|
+
},
|
|
373
|
+
"required": ["entity", "entity_type"],
|
|
374
|
+
"additionalProperties": False,
|
|
375
|
+
},
|
|
376
|
+
"description": "An array of entities with their types.",
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
"required": ["entities"],
|
|
380
|
+
"additionalProperties": False,
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
class GraphToolsPrompts(PromptTemplates):
|
|
387
|
+
"""
|
|
388
|
+
Tool definitions for graph-based memory operations.
|
|
389
|
+
"""
|
|
390
|
+
|
|
391
|
+
def __init__(self, config: Optional[Dict[str, Any]] = None):
|
|
392
|
+
"""
|
|
393
|
+
Initialize graph tools prompts.
|
|
394
|
+
|
|
395
|
+
Args:
|
|
396
|
+
config: Configuration dictionary
|
|
397
|
+
"""
|
|
398
|
+
super().__init__(config)
|
|
399
|
+
|
|
400
|
+
def get_tool(self, tool_name: str, structured: bool = False) -> Dict[str, Any]:
|
|
401
|
+
"""
|
|
402
|
+
Get a specific tool definition.
|
|
403
|
+
|
|
404
|
+
Args:
|
|
405
|
+
tool_name: Name of the tool
|
|
406
|
+
structured: Whether to return structured version (with strict=True)
|
|
407
|
+
|
|
408
|
+
Returns:
|
|
409
|
+
Tool definition dictionary
|
|
410
|
+
"""
|
|
411
|
+
tool_map = {
|
|
412
|
+
"update_memory": UPDATE_MEMORY_STRUCT_TOOL_GRAPH if structured else UPDATE_MEMORY_TOOL_GRAPH,
|
|
413
|
+
"add_memory": ADD_MEMORY_STRUCT_TOOL_GRAPH if structured else ADD_MEMORY_TOOL_GRAPH,
|
|
414
|
+
"delete_memory": DELETE_MEMORY_STRUCT_TOOL_GRAPH if structured else DELETE_MEMORY_TOOL_GRAPH,
|
|
415
|
+
"noop": NOOP_STRUCT_TOOL if structured else NOOP_TOOL,
|
|
416
|
+
"establish_relationships": RELATIONS_STRUCT_TOOL if structured else RELATIONS_TOOL,
|
|
417
|
+
"extract_entities": EXTRACT_ENTITIES_STRUCT_TOOL if structured else EXTRACT_ENTITIES_TOOL,
|
|
418
|
+
}
|
|
419
|
+
return tool_map.get(tool_name, {})
|
|
420
|
+
|
|
421
|
+
def get_tools(self, tool_names: List[str], structured: bool = False) -> List[Dict[str, Any]]:
|
|
422
|
+
"""
|
|
423
|
+
Get multiple tool definitions.
|
|
424
|
+
|
|
425
|
+
Args:
|
|
426
|
+
tool_names: List of tool names
|
|
427
|
+
structured: Whether to return structured versions
|
|
428
|
+
|
|
429
|
+
Returns:
|
|
430
|
+
List of tool definition dictionaries
|
|
431
|
+
"""
|
|
432
|
+
return [self.get_tool(name, structured) for name in tool_names if self.get_tool(name, structured)]
|
|
433
|
+
|
|
434
|
+
def get_all_tools(self, structured: bool = False) -> List[Dict[str, Any]]:
|
|
435
|
+
"""
|
|
436
|
+
Get all tool definitions.
|
|
437
|
+
|
|
438
|
+
Args:
|
|
439
|
+
structured: Whether to return structured versions
|
|
440
|
+
|
|
441
|
+
Returns:
|
|
442
|
+
List of all tool definition dictionaries
|
|
443
|
+
"""
|
|
444
|
+
tool_names = ["update_memory", "add_memory", "delete_memory", "noop", "establish_relationships", "extract_entities"]
|
|
445
|
+
return self.get_tools(tool_names, structured)
|
|
446
|
+
|
|
447
|
+
def get_update_tool(self, structured: bool = False) -> Dict[str, Any]:
|
|
448
|
+
"""Get update memory tool."""
|
|
449
|
+
return UPDATE_MEMORY_STRUCT_TOOL_GRAPH if structured else UPDATE_MEMORY_TOOL_GRAPH
|
|
450
|
+
|
|
451
|
+
def get_add_tool(self, structured: bool = False) -> Dict[str, Any]:
|
|
452
|
+
"""Get add memory tool."""
|
|
453
|
+
return ADD_MEMORY_STRUCT_TOOL_GRAPH if structured else ADD_MEMORY_TOOL_GRAPH
|
|
454
|
+
|
|
455
|
+
def get_delete_tool(self, structured: bool = False) -> Dict[str, Any]:
|
|
456
|
+
"""Get delete memory tool."""
|
|
457
|
+
return DELETE_MEMORY_STRUCT_TOOL_GRAPH if structured else DELETE_MEMORY_TOOL_GRAPH
|
|
458
|
+
|
|
459
|
+
def get_noop_tool(self, structured: bool = False) -> Dict[str, Any]:
|
|
460
|
+
"""Get noop tool."""
|
|
461
|
+
return NOOP_STRUCT_TOOL if structured else NOOP_TOOL
|
|
462
|
+
|
|
463
|
+
def get_relations_tool(self, structured: bool = False) -> Dict[str, Any]:
|
|
464
|
+
"""Get establish relationships tool."""
|
|
465
|
+
return RELATIONS_STRUCT_TOOL if structured else RELATIONS_TOOL
|
|
466
|
+
|
|
467
|
+
def get_extract_entities_tool(self, structured: bool = False) -> Dict[str, Any]:
|
|
468
|
+
"""Get extract entities tool."""
|
|
469
|
+
return EXTRACT_ENTITIES_STRUCT_TOOL if structured else EXTRACT_ENTITIES_TOOL
|