agentrun-mem0ai 0.0.11__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.
- agentrun_mem0/__init__.py +6 -0
- agentrun_mem0/client/__init__.py +0 -0
- agentrun_mem0/client/main.py +1747 -0
- agentrun_mem0/client/project.py +931 -0
- agentrun_mem0/client/utils.py +115 -0
- agentrun_mem0/configs/__init__.py +0 -0
- agentrun_mem0/configs/base.py +90 -0
- agentrun_mem0/configs/embeddings/__init__.py +0 -0
- agentrun_mem0/configs/embeddings/base.py +110 -0
- agentrun_mem0/configs/enums.py +7 -0
- agentrun_mem0/configs/llms/__init__.py +0 -0
- agentrun_mem0/configs/llms/anthropic.py +56 -0
- agentrun_mem0/configs/llms/aws_bedrock.py +192 -0
- agentrun_mem0/configs/llms/azure.py +57 -0
- agentrun_mem0/configs/llms/base.py +62 -0
- agentrun_mem0/configs/llms/deepseek.py +56 -0
- agentrun_mem0/configs/llms/lmstudio.py +59 -0
- agentrun_mem0/configs/llms/ollama.py +56 -0
- agentrun_mem0/configs/llms/openai.py +79 -0
- agentrun_mem0/configs/llms/vllm.py +56 -0
- agentrun_mem0/configs/prompts.py +459 -0
- agentrun_mem0/configs/rerankers/__init__.py +0 -0
- agentrun_mem0/configs/rerankers/base.py +17 -0
- agentrun_mem0/configs/rerankers/cohere.py +15 -0
- agentrun_mem0/configs/rerankers/config.py +12 -0
- agentrun_mem0/configs/rerankers/huggingface.py +17 -0
- agentrun_mem0/configs/rerankers/llm.py +48 -0
- agentrun_mem0/configs/rerankers/sentence_transformer.py +16 -0
- agentrun_mem0/configs/rerankers/zero_entropy.py +28 -0
- agentrun_mem0/configs/vector_stores/__init__.py +0 -0
- agentrun_mem0/configs/vector_stores/alibabacloud_mysql.py +64 -0
- agentrun_mem0/configs/vector_stores/aliyun_tablestore.py +32 -0
- agentrun_mem0/configs/vector_stores/azure_ai_search.py +57 -0
- agentrun_mem0/configs/vector_stores/azure_mysql.py +84 -0
- agentrun_mem0/configs/vector_stores/baidu.py +27 -0
- agentrun_mem0/configs/vector_stores/chroma.py +58 -0
- agentrun_mem0/configs/vector_stores/databricks.py +61 -0
- agentrun_mem0/configs/vector_stores/elasticsearch.py +65 -0
- agentrun_mem0/configs/vector_stores/faiss.py +37 -0
- agentrun_mem0/configs/vector_stores/langchain.py +30 -0
- agentrun_mem0/configs/vector_stores/milvus.py +42 -0
- agentrun_mem0/configs/vector_stores/mongodb.py +25 -0
- agentrun_mem0/configs/vector_stores/neptune.py +27 -0
- agentrun_mem0/configs/vector_stores/opensearch.py +41 -0
- agentrun_mem0/configs/vector_stores/pgvector.py +52 -0
- agentrun_mem0/configs/vector_stores/pinecone.py +55 -0
- agentrun_mem0/configs/vector_stores/qdrant.py +47 -0
- agentrun_mem0/configs/vector_stores/redis.py +24 -0
- agentrun_mem0/configs/vector_stores/s3_vectors.py +28 -0
- agentrun_mem0/configs/vector_stores/supabase.py +44 -0
- agentrun_mem0/configs/vector_stores/upstash_vector.py +34 -0
- agentrun_mem0/configs/vector_stores/valkey.py +15 -0
- agentrun_mem0/configs/vector_stores/vertex_ai_vector_search.py +28 -0
- agentrun_mem0/configs/vector_stores/weaviate.py +41 -0
- agentrun_mem0/embeddings/__init__.py +0 -0
- agentrun_mem0/embeddings/aws_bedrock.py +100 -0
- agentrun_mem0/embeddings/azure_openai.py +55 -0
- agentrun_mem0/embeddings/base.py +31 -0
- agentrun_mem0/embeddings/configs.py +30 -0
- agentrun_mem0/embeddings/gemini.py +39 -0
- agentrun_mem0/embeddings/huggingface.py +44 -0
- agentrun_mem0/embeddings/langchain.py +35 -0
- agentrun_mem0/embeddings/lmstudio.py +29 -0
- agentrun_mem0/embeddings/mock.py +11 -0
- agentrun_mem0/embeddings/ollama.py +53 -0
- agentrun_mem0/embeddings/openai.py +49 -0
- agentrun_mem0/embeddings/together.py +31 -0
- agentrun_mem0/embeddings/vertexai.py +64 -0
- agentrun_mem0/exceptions.py +503 -0
- agentrun_mem0/graphs/__init__.py +0 -0
- agentrun_mem0/graphs/configs.py +105 -0
- agentrun_mem0/graphs/neptune/__init__.py +0 -0
- agentrun_mem0/graphs/neptune/base.py +497 -0
- agentrun_mem0/graphs/neptune/neptunedb.py +511 -0
- agentrun_mem0/graphs/neptune/neptunegraph.py +474 -0
- agentrun_mem0/graphs/tools.py +371 -0
- agentrun_mem0/graphs/utils.py +97 -0
- agentrun_mem0/llms/__init__.py +0 -0
- agentrun_mem0/llms/anthropic.py +87 -0
- agentrun_mem0/llms/aws_bedrock.py +665 -0
- agentrun_mem0/llms/azure_openai.py +141 -0
- agentrun_mem0/llms/azure_openai_structured.py +91 -0
- agentrun_mem0/llms/base.py +131 -0
- agentrun_mem0/llms/configs.py +34 -0
- agentrun_mem0/llms/deepseek.py +107 -0
- agentrun_mem0/llms/gemini.py +201 -0
- agentrun_mem0/llms/groq.py +88 -0
- agentrun_mem0/llms/langchain.py +94 -0
- agentrun_mem0/llms/litellm.py +87 -0
- agentrun_mem0/llms/lmstudio.py +114 -0
- agentrun_mem0/llms/ollama.py +117 -0
- agentrun_mem0/llms/openai.py +147 -0
- agentrun_mem0/llms/openai_structured.py +52 -0
- agentrun_mem0/llms/sarvam.py +89 -0
- agentrun_mem0/llms/together.py +88 -0
- agentrun_mem0/llms/vllm.py +107 -0
- agentrun_mem0/llms/xai.py +52 -0
- agentrun_mem0/memory/__init__.py +0 -0
- agentrun_mem0/memory/base.py +63 -0
- agentrun_mem0/memory/graph_memory.py +698 -0
- agentrun_mem0/memory/kuzu_memory.py +713 -0
- agentrun_mem0/memory/main.py +2229 -0
- agentrun_mem0/memory/memgraph_memory.py +689 -0
- agentrun_mem0/memory/setup.py +56 -0
- agentrun_mem0/memory/storage.py +218 -0
- agentrun_mem0/memory/telemetry.py +90 -0
- agentrun_mem0/memory/utils.py +208 -0
- agentrun_mem0/proxy/__init__.py +0 -0
- agentrun_mem0/proxy/main.py +189 -0
- agentrun_mem0/reranker/__init__.py +9 -0
- agentrun_mem0/reranker/base.py +20 -0
- agentrun_mem0/reranker/cohere_reranker.py +85 -0
- agentrun_mem0/reranker/huggingface_reranker.py +147 -0
- agentrun_mem0/reranker/llm_reranker.py +142 -0
- agentrun_mem0/reranker/sentence_transformer_reranker.py +107 -0
- agentrun_mem0/reranker/zero_entropy_reranker.py +96 -0
- agentrun_mem0/utils/factory.py +283 -0
- agentrun_mem0/utils/gcp_auth.py +167 -0
- agentrun_mem0/vector_stores/__init__.py +0 -0
- agentrun_mem0/vector_stores/alibabacloud_mysql.py +547 -0
- agentrun_mem0/vector_stores/aliyun_tablestore.py +252 -0
- agentrun_mem0/vector_stores/azure_ai_search.py +396 -0
- agentrun_mem0/vector_stores/azure_mysql.py +463 -0
- agentrun_mem0/vector_stores/baidu.py +368 -0
- agentrun_mem0/vector_stores/base.py +58 -0
- agentrun_mem0/vector_stores/chroma.py +332 -0
- agentrun_mem0/vector_stores/configs.py +67 -0
- agentrun_mem0/vector_stores/databricks.py +761 -0
- agentrun_mem0/vector_stores/elasticsearch.py +237 -0
- agentrun_mem0/vector_stores/faiss.py +479 -0
- agentrun_mem0/vector_stores/langchain.py +180 -0
- agentrun_mem0/vector_stores/milvus.py +250 -0
- agentrun_mem0/vector_stores/mongodb.py +310 -0
- agentrun_mem0/vector_stores/neptune_analytics.py +467 -0
- agentrun_mem0/vector_stores/opensearch.py +292 -0
- agentrun_mem0/vector_stores/pgvector.py +404 -0
- agentrun_mem0/vector_stores/pinecone.py +382 -0
- agentrun_mem0/vector_stores/qdrant.py +270 -0
- agentrun_mem0/vector_stores/redis.py +295 -0
- agentrun_mem0/vector_stores/s3_vectors.py +176 -0
- agentrun_mem0/vector_stores/supabase.py +237 -0
- agentrun_mem0/vector_stores/upstash_vector.py +293 -0
- agentrun_mem0/vector_stores/valkey.py +824 -0
- agentrun_mem0/vector_stores/vertex_ai_vector_search.py +635 -0
- agentrun_mem0/vector_stores/weaviate.py +343 -0
- agentrun_mem0ai-0.0.11.data/data/README.md +205 -0
- agentrun_mem0ai-0.0.11.dist-info/METADATA +277 -0
- agentrun_mem0ai-0.0.11.dist-info/RECORD +150 -0
- agentrun_mem0ai-0.0.11.dist-info/WHEEL +4 -0
- agentrun_mem0ai-0.0.11.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
UPDATE_MEMORY_TOOL_GRAPH = {
|
|
2
|
+
"type": "function",
|
|
3
|
+
"function": {
|
|
4
|
+
"name": "update_graph_memory",
|
|
5
|
+
"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.",
|
|
6
|
+
"parameters": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"source": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "The identifier of the source node in the relationship to be updated. This should match an existing node in the graph.",
|
|
12
|
+
},
|
|
13
|
+
"destination": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "The identifier of the destination node in the relationship to be updated. This should match an existing node in the graph.",
|
|
16
|
+
},
|
|
17
|
+
"relationship": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"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.",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
"required": ["source", "destination", "relationship"],
|
|
23
|
+
"additionalProperties": False,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
ADD_MEMORY_TOOL_GRAPH = {
|
|
29
|
+
"type": "function",
|
|
30
|
+
"function": {
|
|
31
|
+
"name": "add_graph_memory",
|
|
32
|
+
"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.",
|
|
33
|
+
"parameters": {
|
|
34
|
+
"type": "object",
|
|
35
|
+
"properties": {
|
|
36
|
+
"source": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"description": "The identifier of the source node in the new relationship. This can be an existing node or a new node to be created.",
|
|
39
|
+
},
|
|
40
|
+
"destination": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"description": "The identifier of the destination node in the new relationship. This can be an existing node or a new node to be created.",
|
|
43
|
+
},
|
|
44
|
+
"relationship": {
|
|
45
|
+
"type": "string",
|
|
46
|
+
"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.",
|
|
47
|
+
},
|
|
48
|
+
"source_type": {
|
|
49
|
+
"type": "string",
|
|
50
|
+
"description": "The type or category of the source node. This helps in classifying and organizing nodes in the graph.",
|
|
51
|
+
},
|
|
52
|
+
"destination_type": {
|
|
53
|
+
"type": "string",
|
|
54
|
+
"description": "The type or category of the destination node. This helps in classifying and organizing nodes in the graph.",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
"required": [
|
|
58
|
+
"source",
|
|
59
|
+
"destination",
|
|
60
|
+
"relationship",
|
|
61
|
+
"source_type",
|
|
62
|
+
"destination_type",
|
|
63
|
+
],
|
|
64
|
+
"additionalProperties": False,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
NOOP_TOOL = {
|
|
71
|
+
"type": "function",
|
|
72
|
+
"function": {
|
|
73
|
+
"name": "noop",
|
|
74
|
+
"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.",
|
|
75
|
+
"parameters": {
|
|
76
|
+
"type": "object",
|
|
77
|
+
"properties": {},
|
|
78
|
+
"required": [],
|
|
79
|
+
"additionalProperties": False,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
RELATIONS_TOOL = {
|
|
86
|
+
"type": "function",
|
|
87
|
+
"function": {
|
|
88
|
+
"name": "establish_relationships",
|
|
89
|
+
"description": "Establish relationships among the entities based on the provided text.",
|
|
90
|
+
"parameters": {
|
|
91
|
+
"type": "object",
|
|
92
|
+
"properties": {
|
|
93
|
+
"entities": {
|
|
94
|
+
"type": "array",
|
|
95
|
+
"items": {
|
|
96
|
+
"type": "object",
|
|
97
|
+
"properties": {
|
|
98
|
+
"source": {"type": "string", "description": "The source entity of the relationship."},
|
|
99
|
+
"relationship": {
|
|
100
|
+
"type": "string",
|
|
101
|
+
"description": "The relationship between the source and destination entities.",
|
|
102
|
+
},
|
|
103
|
+
"destination": {
|
|
104
|
+
"type": "string",
|
|
105
|
+
"description": "The destination entity of the relationship.",
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
"required": [
|
|
109
|
+
"source",
|
|
110
|
+
"relationship",
|
|
111
|
+
"destination",
|
|
112
|
+
],
|
|
113
|
+
"additionalProperties": False,
|
|
114
|
+
},
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"required": ["entities"],
|
|
118
|
+
"additionalProperties": False,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
EXTRACT_ENTITIES_TOOL = {
|
|
125
|
+
"type": "function",
|
|
126
|
+
"function": {
|
|
127
|
+
"name": "extract_entities",
|
|
128
|
+
"description": "Extract entities and their types from the text.",
|
|
129
|
+
"parameters": {
|
|
130
|
+
"type": "object",
|
|
131
|
+
"properties": {
|
|
132
|
+
"entities": {
|
|
133
|
+
"type": "array",
|
|
134
|
+
"items": {
|
|
135
|
+
"type": "object",
|
|
136
|
+
"properties": {
|
|
137
|
+
"entity": {"type": "string", "description": "The name or identifier of the entity."},
|
|
138
|
+
"entity_type": {"type": "string", "description": "The type or category of the entity."},
|
|
139
|
+
},
|
|
140
|
+
"required": ["entity", "entity_type"],
|
|
141
|
+
"additionalProperties": False,
|
|
142
|
+
},
|
|
143
|
+
"description": "An array of entities with their types.",
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
"required": ["entities"],
|
|
147
|
+
"additionalProperties": False,
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
UPDATE_MEMORY_STRUCT_TOOL_GRAPH = {
|
|
153
|
+
"type": "function",
|
|
154
|
+
"function": {
|
|
155
|
+
"name": "update_graph_memory",
|
|
156
|
+
"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.",
|
|
157
|
+
"strict": True,
|
|
158
|
+
"parameters": {
|
|
159
|
+
"type": "object",
|
|
160
|
+
"properties": {
|
|
161
|
+
"source": {
|
|
162
|
+
"type": "string",
|
|
163
|
+
"description": "The identifier of the source node in the relationship to be updated. This should match an existing node in the graph.",
|
|
164
|
+
},
|
|
165
|
+
"destination": {
|
|
166
|
+
"type": "string",
|
|
167
|
+
"description": "The identifier of the destination node in the relationship to be updated. This should match an existing node in the graph.",
|
|
168
|
+
},
|
|
169
|
+
"relationship": {
|
|
170
|
+
"type": "string",
|
|
171
|
+
"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.",
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
"required": ["source", "destination", "relationship"],
|
|
175
|
+
"additionalProperties": False,
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
ADD_MEMORY_STRUCT_TOOL_GRAPH = {
|
|
181
|
+
"type": "function",
|
|
182
|
+
"function": {
|
|
183
|
+
"name": "add_graph_memory",
|
|
184
|
+
"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.",
|
|
185
|
+
"strict": True,
|
|
186
|
+
"parameters": {
|
|
187
|
+
"type": "object",
|
|
188
|
+
"properties": {
|
|
189
|
+
"source": {
|
|
190
|
+
"type": "string",
|
|
191
|
+
"description": "The identifier of the source node in the new relationship. This can be an existing node or a new node to be created.",
|
|
192
|
+
},
|
|
193
|
+
"destination": {
|
|
194
|
+
"type": "string",
|
|
195
|
+
"description": "The identifier of the destination node in the new relationship. This can be an existing node or a new node to be created.",
|
|
196
|
+
},
|
|
197
|
+
"relationship": {
|
|
198
|
+
"type": "string",
|
|
199
|
+
"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.",
|
|
200
|
+
},
|
|
201
|
+
"source_type": {
|
|
202
|
+
"type": "string",
|
|
203
|
+
"description": "The type or category of the source node. This helps in classifying and organizing nodes in the graph.",
|
|
204
|
+
},
|
|
205
|
+
"destination_type": {
|
|
206
|
+
"type": "string",
|
|
207
|
+
"description": "The type or category of the destination node. This helps in classifying and organizing nodes in the graph.",
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
"required": [
|
|
211
|
+
"source",
|
|
212
|
+
"destination",
|
|
213
|
+
"relationship",
|
|
214
|
+
"source_type",
|
|
215
|
+
"destination_type",
|
|
216
|
+
],
|
|
217
|
+
"additionalProperties": False,
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
NOOP_STRUCT_TOOL = {
|
|
224
|
+
"type": "function",
|
|
225
|
+
"function": {
|
|
226
|
+
"name": "noop",
|
|
227
|
+
"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.",
|
|
228
|
+
"strict": True,
|
|
229
|
+
"parameters": {
|
|
230
|
+
"type": "object",
|
|
231
|
+
"properties": {},
|
|
232
|
+
"required": [],
|
|
233
|
+
"additionalProperties": False,
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
RELATIONS_STRUCT_TOOL = {
|
|
239
|
+
"type": "function",
|
|
240
|
+
"function": {
|
|
241
|
+
"name": "establish_relations",
|
|
242
|
+
"description": "Establish relationships among the entities based on the provided text.",
|
|
243
|
+
"strict": True,
|
|
244
|
+
"parameters": {
|
|
245
|
+
"type": "object",
|
|
246
|
+
"properties": {
|
|
247
|
+
"entities": {
|
|
248
|
+
"type": "array",
|
|
249
|
+
"items": {
|
|
250
|
+
"type": "object",
|
|
251
|
+
"properties": {
|
|
252
|
+
"source": {
|
|
253
|
+
"type": "string",
|
|
254
|
+
"description": "The source entity of the relationship.",
|
|
255
|
+
},
|
|
256
|
+
"relationship": {
|
|
257
|
+
"type": "string",
|
|
258
|
+
"description": "The relationship between the source and destination entities.",
|
|
259
|
+
},
|
|
260
|
+
"destination": {
|
|
261
|
+
"type": "string",
|
|
262
|
+
"description": "The destination entity of the relationship.",
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
"required": [
|
|
266
|
+
"source",
|
|
267
|
+
"relationship",
|
|
268
|
+
"destination",
|
|
269
|
+
],
|
|
270
|
+
"additionalProperties": False,
|
|
271
|
+
},
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
"required": ["entities"],
|
|
275
|
+
"additionalProperties": False,
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
EXTRACT_ENTITIES_STRUCT_TOOL = {
|
|
282
|
+
"type": "function",
|
|
283
|
+
"function": {
|
|
284
|
+
"name": "extract_entities",
|
|
285
|
+
"description": "Extract entities and their types from the text.",
|
|
286
|
+
"strict": True,
|
|
287
|
+
"parameters": {
|
|
288
|
+
"type": "object",
|
|
289
|
+
"properties": {
|
|
290
|
+
"entities": {
|
|
291
|
+
"type": "array",
|
|
292
|
+
"items": {
|
|
293
|
+
"type": "object",
|
|
294
|
+
"properties": {
|
|
295
|
+
"entity": {"type": "string", "description": "The name or identifier of the entity."},
|
|
296
|
+
"entity_type": {"type": "string", "description": "The type or category of the entity."},
|
|
297
|
+
},
|
|
298
|
+
"required": ["entity", "entity_type"],
|
|
299
|
+
"additionalProperties": False,
|
|
300
|
+
},
|
|
301
|
+
"description": "An array of entities with their types.",
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
"required": ["entities"],
|
|
305
|
+
"additionalProperties": False,
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
DELETE_MEMORY_STRUCT_TOOL_GRAPH = {
|
|
311
|
+
"type": "function",
|
|
312
|
+
"function": {
|
|
313
|
+
"name": "delete_graph_memory",
|
|
314
|
+
"description": "Delete the relationship between two nodes. This function deletes the existing relationship.",
|
|
315
|
+
"strict": True,
|
|
316
|
+
"parameters": {
|
|
317
|
+
"type": "object",
|
|
318
|
+
"properties": {
|
|
319
|
+
"source": {
|
|
320
|
+
"type": "string",
|
|
321
|
+
"description": "The identifier of the source node in the relationship.",
|
|
322
|
+
},
|
|
323
|
+
"relationship": {
|
|
324
|
+
"type": "string",
|
|
325
|
+
"description": "The existing relationship between the source and destination nodes that needs to be deleted.",
|
|
326
|
+
},
|
|
327
|
+
"destination": {
|
|
328
|
+
"type": "string",
|
|
329
|
+
"description": "The identifier of the destination node in the relationship.",
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
"required": [
|
|
333
|
+
"source",
|
|
334
|
+
"relationship",
|
|
335
|
+
"destination",
|
|
336
|
+
],
|
|
337
|
+
"additionalProperties": False,
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
DELETE_MEMORY_TOOL_GRAPH = {
|
|
343
|
+
"type": "function",
|
|
344
|
+
"function": {
|
|
345
|
+
"name": "delete_graph_memory",
|
|
346
|
+
"description": "Delete the relationship between two nodes. This function deletes the existing relationship.",
|
|
347
|
+
"parameters": {
|
|
348
|
+
"type": "object",
|
|
349
|
+
"properties": {
|
|
350
|
+
"source": {
|
|
351
|
+
"type": "string",
|
|
352
|
+
"description": "The identifier of the source node in the relationship.",
|
|
353
|
+
},
|
|
354
|
+
"relationship": {
|
|
355
|
+
"type": "string",
|
|
356
|
+
"description": "The existing relationship between the source and destination nodes that needs to be deleted.",
|
|
357
|
+
},
|
|
358
|
+
"destination": {
|
|
359
|
+
"type": "string",
|
|
360
|
+
"description": "The identifier of the destination node in the relationship.",
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
"required": [
|
|
364
|
+
"source",
|
|
365
|
+
"relationship",
|
|
366
|
+
"destination",
|
|
367
|
+
],
|
|
368
|
+
"additionalProperties": False,
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
UPDATE_GRAPH_PROMPT = """
|
|
2
|
+
You are an AI expert specializing in graph memory management and optimization. Your task is to analyze existing graph memories alongside new information, and update the relationships in the memory list to ensure the most accurate, current, and coherent representation of knowledge.
|
|
3
|
+
|
|
4
|
+
Input:
|
|
5
|
+
1. Existing Graph Memories: A list of current graph memories, each containing source, target, and relationship information.
|
|
6
|
+
2. New Graph Memory: Fresh information to be integrated into the existing graph structure.
|
|
7
|
+
|
|
8
|
+
Guidelines:
|
|
9
|
+
1. Identification: Use the source and target as primary identifiers when matching existing memories with new information.
|
|
10
|
+
2. Conflict Resolution:
|
|
11
|
+
- If new information contradicts an existing memory:
|
|
12
|
+
a) For matching source and target but differing content, update the relationship of the existing memory.
|
|
13
|
+
b) If the new memory provides more recent or accurate information, update the existing memory accordingly.
|
|
14
|
+
3. Comprehensive Review: Thoroughly examine each existing graph memory against the new information, updating relationships as necessary. Multiple updates may be required.
|
|
15
|
+
4. Consistency: Maintain a uniform and clear style across all memories. Each entry should be concise yet comprehensive.
|
|
16
|
+
5. Semantic Coherence: Ensure that updates maintain or improve the overall semantic structure of the graph.
|
|
17
|
+
6. Temporal Awareness: If timestamps are available, consider the recency of information when making updates.
|
|
18
|
+
7. Relationship Refinement: Look for opportunities to refine relationship descriptions for greater precision or clarity.
|
|
19
|
+
8. Redundancy Elimination: Identify and merge any redundant or highly similar relationships that may result from the update.
|
|
20
|
+
|
|
21
|
+
Memory Format:
|
|
22
|
+
source -- RELATIONSHIP -- destination
|
|
23
|
+
|
|
24
|
+
Task Details:
|
|
25
|
+
======= Existing Graph Memories:=======
|
|
26
|
+
{existing_memories}
|
|
27
|
+
|
|
28
|
+
======= New Graph Memory:=======
|
|
29
|
+
{new_memories}
|
|
30
|
+
|
|
31
|
+
Output:
|
|
32
|
+
Provide a list of update instructions, each specifying the source, target, and the new relationship to be set. Only include memories that require updates.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
EXTRACT_RELATIONS_PROMPT = """
|
|
36
|
+
|
|
37
|
+
You are an advanced algorithm designed to extract structured information from text to construct knowledge graphs. Your goal is to capture comprehensive and accurate information. Follow these key principles:
|
|
38
|
+
|
|
39
|
+
1. Extract only explicitly stated information from the text.
|
|
40
|
+
2. Establish relationships among the entities provided.
|
|
41
|
+
3. Use "USER_ID" as the source entity for any self-references (e.g., "I," "me," "my," etc.) in user messages.
|
|
42
|
+
CUSTOM_PROMPT
|
|
43
|
+
|
|
44
|
+
Relationships:
|
|
45
|
+
- Use consistent, general, and timeless relationship types.
|
|
46
|
+
- Example: Prefer "professor" over "became_professor."
|
|
47
|
+
- Relationships should only be established among the entities explicitly mentioned in the user message.
|
|
48
|
+
|
|
49
|
+
Entity Consistency:
|
|
50
|
+
- Ensure that relationships are coherent and logically align with the context of the message.
|
|
51
|
+
- Maintain consistent naming for entities across the extracted data.
|
|
52
|
+
|
|
53
|
+
Strive to construct a coherent and easily understandable knowledge graph by establishing all the relationships among the entities and adherence to the user’s context.
|
|
54
|
+
|
|
55
|
+
Adhere strictly to these guidelines to ensure high-quality knowledge graph extraction."""
|
|
56
|
+
|
|
57
|
+
DELETE_RELATIONS_SYSTEM_PROMPT = """
|
|
58
|
+
You are a graph memory manager specializing in identifying, managing, and optimizing relationships within graph-based memories. Your primary task is to analyze a list of existing relationships and determine which ones should be deleted based on the new information provided.
|
|
59
|
+
Input:
|
|
60
|
+
1. Existing Graph Memories: A list of current graph memories, each containing source, relationship, and destination information.
|
|
61
|
+
2. New Text: The new information to be integrated into the existing graph structure.
|
|
62
|
+
3. Use "USER_ID" as node for any self-references (e.g., "I," "me," "my," etc.) in user messages.
|
|
63
|
+
|
|
64
|
+
Guidelines:
|
|
65
|
+
1. Identification: Use the new information to evaluate existing relationships in the memory graph.
|
|
66
|
+
2. Deletion Criteria: Delete a relationship only if it meets at least one of these conditions:
|
|
67
|
+
- Outdated or Inaccurate: The new information is more recent or accurate.
|
|
68
|
+
- Contradictory: The new information conflicts with or negates the existing information.
|
|
69
|
+
3. DO NOT DELETE if their is a possibility of same type of relationship but different destination nodes.
|
|
70
|
+
4. Comprehensive Analysis:
|
|
71
|
+
- Thoroughly examine each existing relationship against the new information and delete as necessary.
|
|
72
|
+
- Multiple deletions may be required based on the new information.
|
|
73
|
+
5. Semantic Integrity:
|
|
74
|
+
- Ensure that deletions maintain or improve the overall semantic structure of the graph.
|
|
75
|
+
- Avoid deleting relationships that are NOT contradictory/outdated to the new information.
|
|
76
|
+
6. Temporal Awareness: Prioritize recency when timestamps are available.
|
|
77
|
+
7. Necessity Principle: Only DELETE relationships that must be deleted and are contradictory/outdated to the new information to maintain an accurate and coherent memory graph.
|
|
78
|
+
|
|
79
|
+
Note: DO NOT DELETE if their is a possibility of same type of relationship but different destination nodes.
|
|
80
|
+
|
|
81
|
+
For example:
|
|
82
|
+
Existing Memory: alice -- loves_to_eat -- pizza
|
|
83
|
+
New Information: Alice also loves to eat burger.
|
|
84
|
+
|
|
85
|
+
Do not delete in the above example because there is a possibility that Alice loves to eat both pizza and burger.
|
|
86
|
+
|
|
87
|
+
Memory Format:
|
|
88
|
+
source -- relationship -- destination
|
|
89
|
+
|
|
90
|
+
Provide a list of deletion instructions, each specifying the relationship to be deleted.
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def get_delete_messages(existing_memories_string, data, user_id):
|
|
95
|
+
return DELETE_RELATIONS_SYSTEM_PROMPT.replace(
|
|
96
|
+
"USER_ID", user_id
|
|
97
|
+
), f"Here are the existing memories: {existing_memories_string} \n\n New Information: {data}"
|
|
File without changes
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Dict, List, Optional, Union
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
import anthropic
|
|
6
|
+
except ImportError:
|
|
7
|
+
raise ImportError("The 'anthropic' library is required. Please install it using 'pip install anthropic'.")
|
|
8
|
+
|
|
9
|
+
from agentrun_mem0.configs.llms.anthropic import AnthropicConfig
|
|
10
|
+
from agentrun_mem0.configs.llms.base import BaseLlmConfig
|
|
11
|
+
from agentrun_mem0.llms.base import LLMBase
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class AnthropicLLM(LLMBase):
|
|
15
|
+
def __init__(self, config: Optional[Union[BaseLlmConfig, AnthropicConfig, Dict]] = None):
|
|
16
|
+
# Convert to AnthropicConfig if needed
|
|
17
|
+
if config is None:
|
|
18
|
+
config = AnthropicConfig()
|
|
19
|
+
elif isinstance(config, dict):
|
|
20
|
+
config = AnthropicConfig(**config)
|
|
21
|
+
elif isinstance(config, BaseLlmConfig) and not isinstance(config, AnthropicConfig):
|
|
22
|
+
# Convert BaseLlmConfig to AnthropicConfig
|
|
23
|
+
config = AnthropicConfig(
|
|
24
|
+
model=config.model,
|
|
25
|
+
temperature=config.temperature,
|
|
26
|
+
api_key=config.api_key,
|
|
27
|
+
max_tokens=config.max_tokens,
|
|
28
|
+
top_p=config.top_p,
|
|
29
|
+
top_k=config.top_k,
|
|
30
|
+
enable_vision=config.enable_vision,
|
|
31
|
+
vision_details=config.vision_details,
|
|
32
|
+
http_client_proxies=config.http_client,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
super().__init__(config)
|
|
36
|
+
|
|
37
|
+
if not self.config.model:
|
|
38
|
+
self.config.model = "claude-3-5-sonnet-20240620"
|
|
39
|
+
|
|
40
|
+
api_key = self.config.api_key or os.getenv("ANTHROPIC_API_KEY")
|
|
41
|
+
self.client = anthropic.Anthropic(api_key=api_key)
|
|
42
|
+
|
|
43
|
+
def generate_response(
|
|
44
|
+
self,
|
|
45
|
+
messages: List[Dict[str, str]],
|
|
46
|
+
response_format=None,
|
|
47
|
+
tools: Optional[List[Dict]] = None,
|
|
48
|
+
tool_choice: str = "auto",
|
|
49
|
+
**kwargs,
|
|
50
|
+
):
|
|
51
|
+
"""
|
|
52
|
+
Generate a response based on the given messages using Anthropic.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
messages (list): List of message dicts containing 'role' and 'content'.
|
|
56
|
+
response_format (str or object, optional): Format of the response. Defaults to "text".
|
|
57
|
+
tools (list, optional): List of tools that the model can call. Defaults to None.
|
|
58
|
+
tool_choice (str, optional): Tool choice method. Defaults to "auto".
|
|
59
|
+
**kwargs: Additional Anthropic-specific parameters.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
str: The generated response.
|
|
63
|
+
"""
|
|
64
|
+
# Separate system message from other messages
|
|
65
|
+
system_message = ""
|
|
66
|
+
filtered_messages = []
|
|
67
|
+
for message in messages:
|
|
68
|
+
if message["role"] == "system":
|
|
69
|
+
system_message = message["content"]
|
|
70
|
+
else:
|
|
71
|
+
filtered_messages.append(message)
|
|
72
|
+
|
|
73
|
+
params = self._get_supported_params(messages=messages, **kwargs)
|
|
74
|
+
params.update(
|
|
75
|
+
{
|
|
76
|
+
"model": self.config.model,
|
|
77
|
+
"messages": filtered_messages,
|
|
78
|
+
"system": system_message,
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if tools: # TODO: Remove tools if no issues found with new memory addition logic
|
|
83
|
+
params["tools"] = tools
|
|
84
|
+
params["tool_choice"] = tool_choice
|
|
85
|
+
|
|
86
|
+
response = self.client.messages.create(**params)
|
|
87
|
+
return response.content[0].text
|