massgen 0.1.4__py3-none-any.whl → 0.1.5__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.
Potentially problematic release.
This version of massgen might be problematic. Click here for more details.
- massgen/__init__.py +1 -1
- massgen/chat_agent.py +340 -20
- massgen/cli.py +326 -19
- massgen/configs/README.md +52 -10
- massgen/configs/memory/gpt5mini_gemini_baseline_research_to_implementation.yaml +94 -0
- massgen/configs/memory/gpt5mini_gemini_context_window_management.yaml +187 -0
- massgen/configs/memory/gpt5mini_gemini_research_to_implementation.yaml +127 -0
- massgen/configs/memory/gpt5mini_high_reasoning_gemini.yaml +107 -0
- massgen/configs/memory/single_agent_compression_test.yaml +64 -0
- massgen/configs/tools/custom_tools/multimodal_tools/playwright_with_img_understanding.yaml +98 -0
- massgen/configs/tools/custom_tools/multimodal_tools/understand_video_example.yaml +54 -0
- massgen/memory/README.md +277 -0
- massgen/memory/__init__.py +26 -0
- massgen/memory/_base.py +193 -0
- massgen/memory/_compression.py +237 -0
- massgen/memory/_context_monitor.py +211 -0
- massgen/memory/_conversation.py +255 -0
- massgen/memory/_fact_extraction_prompts.py +333 -0
- massgen/memory/_mem0_adapters.py +257 -0
- massgen/memory/_persistent.py +687 -0
- massgen/memory/docker-compose.qdrant.yml +36 -0
- massgen/memory/docs/DESIGN.md +388 -0
- massgen/memory/docs/QUICKSTART.md +409 -0
- massgen/memory/docs/SUMMARY.md +319 -0
- massgen/memory/docs/agent_use_memory.md +408 -0
- massgen/memory/docs/orchestrator_use_memory.md +586 -0
- massgen/memory/examples.py +237 -0
- massgen/orchestrator.py +207 -7
- massgen/tests/memory/test_agent_compression.py +174 -0
- massgen/tests/memory/test_context_window_management.py +286 -0
- massgen/tests/memory/test_force_compression.py +154 -0
- massgen/tests/memory/test_simple_compression.py +147 -0
- massgen/tests/test_agent_memory.py +534 -0
- massgen/tests/test_conversation_memory.py +382 -0
- massgen/tests/test_orchestrator_memory.py +620 -0
- massgen/tests/test_persistent_memory.py +435 -0
- massgen/token_manager/token_manager.py +6 -0
- massgen/tools/__init__.py +8 -0
- massgen/tools/_planning_mcp_server.py +520 -0
- massgen/tools/planning_dataclasses.py +434 -0
- {massgen-0.1.4.dist-info → massgen-0.1.5.dist-info}/METADATA +109 -76
- {massgen-0.1.4.dist-info → massgen-0.1.5.dist-info}/RECORD +46 -12
- {massgen-0.1.4.dist-info → massgen-0.1.5.dist-info}/WHEEL +0 -0
- {massgen-0.1.4.dist-info → massgen-0.1.5.dist-info}/entry_points.txt +0 -0
- {massgen-0.1.4.dist-info → massgen-0.1.5.dist-info}/licenses/LICENSE +0 -0
- {massgen-0.1.4.dist-info → massgen-0.1.5.dist-info}/top_level.txt +0 -0
massgen/memory/README.md
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
# MassGen Memory System
|
|
2
|
+
|
|
3
|
+
The MassGen memory system provides agents with the ability to store and recall information across conversations, enabling more contextual and intelligent interactions.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
The memory system consists of three main components:
|
|
8
|
+
|
|
9
|
+
### 1. **ConversationMemory** - Short-term Memory
|
|
10
|
+
Fast in-memory storage for active conversations.
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
from massgen.memory import ConversationMemory
|
|
14
|
+
|
|
15
|
+
# Initialize
|
|
16
|
+
memory = ConversationMemory()
|
|
17
|
+
|
|
18
|
+
# Add messages
|
|
19
|
+
await memory.add({"role": "user", "content": "Hello!"})
|
|
20
|
+
await memory.add({"role": "assistant", "content": "Hi there!"})
|
|
21
|
+
|
|
22
|
+
# Retrieve messages
|
|
23
|
+
messages = await memory.get_messages()
|
|
24
|
+
print(f"Stored {len(messages)} messages")
|
|
25
|
+
|
|
26
|
+
# Get last 10 messages only
|
|
27
|
+
recent = await memory.get_messages(limit=10)
|
|
28
|
+
|
|
29
|
+
# Filter by role
|
|
30
|
+
user_messages = await memory.get_messages_by_role("user")
|
|
31
|
+
|
|
32
|
+
# Manage memory size
|
|
33
|
+
await memory.truncate_to_size(100) # Keep last 100 messages
|
|
34
|
+
|
|
35
|
+
# Clear all
|
|
36
|
+
await memory.clear()
|
|
37
|
+
|
|
38
|
+
# Save/load state
|
|
39
|
+
state = memory.state_dict()
|
|
40
|
+
# ... later ...
|
|
41
|
+
new_memory = ConversationMemory()
|
|
42
|
+
new_memory.load_state_dict(state)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. **PersistentMemory** - Long-term Memory
|
|
46
|
+
Semantic memory storage using mem0 with vector search capabilities.
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from massgen.memory import PersistentMemory
|
|
50
|
+
from massgen.backend import OpenAIBackend
|
|
51
|
+
|
|
52
|
+
# Initialize with backends
|
|
53
|
+
llm_backend = OpenAIBackend(model="gpt-4")
|
|
54
|
+
embedding_backend = OpenAIBackend(model="text-embedding-3-small")
|
|
55
|
+
|
|
56
|
+
memory = PersistentMemory(
|
|
57
|
+
agent_name="my_agent",
|
|
58
|
+
llm_backend=llm_backend,
|
|
59
|
+
embedding_backend=embedding_backend,
|
|
60
|
+
on_disk=True # Persist to disk
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
# Developer Interface: Record conversation
|
|
64
|
+
await memory.record([
|
|
65
|
+
{"role": "user", "content": "My name is Alice"},
|
|
66
|
+
{"role": "assistant", "content": "Nice to meet you, Alice!"}
|
|
67
|
+
])
|
|
68
|
+
|
|
69
|
+
# Developer Interface: Retrieve relevant memories
|
|
70
|
+
relevant = await memory.retrieve("What's the user's name?")
|
|
71
|
+
print(relevant) # "Alice"
|
|
72
|
+
|
|
73
|
+
# Agent Tool Interface: Agent saves important info
|
|
74
|
+
result = await memory.save_to_memory(
|
|
75
|
+
thinking="User shared personal information",
|
|
76
|
+
content=["User's favorite color is blue", "User works as a teacher"]
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
# Agent Tool Interface: Agent recalls from memory
|
|
80
|
+
result = await memory.recall_from_memory(
|
|
81
|
+
keywords=["favorite color", "job"],
|
|
82
|
+
limit=5
|
|
83
|
+
)
|
|
84
|
+
for mem in result['memories']:
|
|
85
|
+
print(mem)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 3. **Memory Integration Modes**
|
|
89
|
+
|
|
90
|
+
#### Mode 1: Developer-Controlled (Automatic)
|
|
91
|
+
```python
|
|
92
|
+
# Framework automatically manages memory
|
|
93
|
+
|
|
94
|
+
class MyAgent:
|
|
95
|
+
def __init__(self):
|
|
96
|
+
self.conversation_memory = ConversationMemory()
|
|
97
|
+
self.persistent_memory = PersistentMemory(
|
|
98
|
+
agent_name="agent_1",
|
|
99
|
+
llm_backend=llm,
|
|
100
|
+
embedding_backend=embedding
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
async def chat(self, user_message):
|
|
104
|
+
# Auto-add to conversation memory
|
|
105
|
+
await self.conversation_memory.add({
|
|
106
|
+
"role": "user",
|
|
107
|
+
"content": user_message
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
# Auto-retrieve relevant long-term memories
|
|
111
|
+
context = await self.persistent_memory.retrieve(user_message)
|
|
112
|
+
|
|
113
|
+
# Build full context
|
|
114
|
+
messages = await self.conversation_memory.get_messages()
|
|
115
|
+
if context:
|
|
116
|
+
messages.insert(0, {
|
|
117
|
+
"role": "system",
|
|
118
|
+
"content": f"Relevant memories: {context}"
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
# Generate response...
|
|
122
|
+
response = await self.backend.chat(messages)
|
|
123
|
+
|
|
124
|
+
# Auto-record response
|
|
125
|
+
await self.conversation_memory.add({
|
|
126
|
+
"role": "assistant",
|
|
127
|
+
"content": response
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
# Optionally save important conversations to long-term memory
|
|
131
|
+
await self.persistent_memory.record(messages)
|
|
132
|
+
|
|
133
|
+
return response
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### Mode 2: Agent-Controlled (Tools)
|
|
137
|
+
```python
|
|
138
|
+
# Agent actively manages its own memory
|
|
139
|
+
|
|
140
|
+
# Register memory tools
|
|
141
|
+
tools = [
|
|
142
|
+
{
|
|
143
|
+
"name": "save_to_memory",
|
|
144
|
+
"description": "Save important information for future reference",
|
|
145
|
+
"parameters": {
|
|
146
|
+
"thinking": "Why this information is important",
|
|
147
|
+
"content": ["List of things to remember"]
|
|
148
|
+
},
|
|
149
|
+
"function": memory.save_to_memory
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"name": "recall_from_memory",
|
|
153
|
+
"description": "Search long-term memory for information",
|
|
154
|
+
"parameters": {
|
|
155
|
+
"keywords": ["Keywords to search for"]
|
|
156
|
+
},
|
|
157
|
+
"function": memory.recall_from_memory
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
|
|
161
|
+
# Agent can now call these tools during conversation
|
|
162
|
+
# Example agent reasoning:
|
|
163
|
+
# "The user mentioned their birthday. I should save this."
|
|
164
|
+
# -> Calls save_to_memory(thinking="...", content=["Birthday: March 15"])
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Installation
|
|
168
|
+
|
|
169
|
+
The memory system requires the mem0 library for persistent memory:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
pip install mem0ai
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Vector Store Options
|
|
176
|
+
|
|
177
|
+
By default, PersistentMemory uses Qdrant for vector storage. You can configure other backends:
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
from mem0.vector_stores.configs import VectorStoreConfig
|
|
181
|
+
|
|
182
|
+
# Custom vector store
|
|
183
|
+
vector_config = VectorStoreConfig(
|
|
184
|
+
provider="qdrant", # or "chroma", "pinecone", etc.
|
|
185
|
+
config={
|
|
186
|
+
"on_disk": True,
|
|
187
|
+
"path": "./my_memories"
|
|
188
|
+
}
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
memory = PersistentMemory(
|
|
192
|
+
agent_name="agent_1",
|
|
193
|
+
llm_backend=llm,
|
|
194
|
+
embedding_backend=embedding,
|
|
195
|
+
vector_store_config=vector_config
|
|
196
|
+
)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Memory Organization
|
|
200
|
+
|
|
201
|
+
Memories are organized by metadata:
|
|
202
|
+
|
|
203
|
+
- **agent_name**: Isolate memories per agent
|
|
204
|
+
- **user_name**: Track user-specific information
|
|
205
|
+
- **session_name**: Separate different conversation sessions
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
# Agent-specific memory
|
|
209
|
+
agent_memory = PersistentMemory(agent_name="research_agent")
|
|
210
|
+
|
|
211
|
+
# User-specific memory
|
|
212
|
+
user_memory = PersistentMemory(user_name="alice")
|
|
213
|
+
|
|
214
|
+
# Session-specific memory
|
|
215
|
+
session_memory = PersistentMemory(
|
|
216
|
+
agent_name="agent_1",
|
|
217
|
+
session_name="session_123"
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
# Combined filtering
|
|
221
|
+
memory = PersistentMemory(
|
|
222
|
+
agent_name="agent_1",
|
|
223
|
+
user_name="alice",
|
|
224
|
+
session_name="2024-01-15"
|
|
225
|
+
)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Best Practices
|
|
229
|
+
|
|
230
|
+
1. **Short-term for speed**: Use ConversationMemory for current dialogue
|
|
231
|
+
2. **Long-term for knowledge**: Use PersistentMemory for cross-session information
|
|
232
|
+
3. **Truncate regularly**: Keep conversation memory manageable
|
|
233
|
+
4. **Meaningful metadata**: Use descriptive agent/user/session names
|
|
234
|
+
5. **Selective persistence**: Only save important information to long-term memory
|
|
235
|
+
|
|
236
|
+
## Advanced: Custom mem0 Configuration
|
|
237
|
+
|
|
238
|
+
For full control over mem0 behavior:
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
from mem0.configs.base import MemoryConfig
|
|
242
|
+
from mem0.configs.llms.configs import LlmConfig
|
|
243
|
+
from mem0.configs.embeddings.configs import EmbedderConfig
|
|
244
|
+
|
|
245
|
+
custom_mem0_config = MemoryConfig(
|
|
246
|
+
llm=LlmConfig(provider="openai", config={"model": "gpt-4"}),
|
|
247
|
+
embedder=EmbedderConfig(provider="openai", config={"model": "text-embedding-3-large"}),
|
|
248
|
+
# ... other mem0 settings
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
memory = PersistentMemory(
|
|
252
|
+
agent_name="agent_1",
|
|
253
|
+
mem0_config=custom_mem0_config
|
|
254
|
+
)
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Troubleshooting
|
|
258
|
+
|
|
259
|
+
**Issue**: `ImportError: mem0 library is required`
|
|
260
|
+
- **Solution**: `pip install mem0ai`
|
|
261
|
+
|
|
262
|
+
**Issue**: Memories not persisting across restarts
|
|
263
|
+
- **Solution**: Ensure `on_disk=True` in PersistentMemory initialization
|
|
264
|
+
|
|
265
|
+
**Issue**: Out of memory errors
|
|
266
|
+
- **Solution**: Use `truncate_to_size()` on ConversationMemory regularly
|
|
267
|
+
|
|
268
|
+
**Issue**: Slow retrieval
|
|
269
|
+
- **Solution**: Reduce `limit` parameter in retrieve calls, or upgrade vector store
|
|
270
|
+
|
|
271
|
+
## Contributing
|
|
272
|
+
|
|
273
|
+
The memory system is designed to be extensible. To add new memory types:
|
|
274
|
+
|
|
275
|
+
1. Inherit from `MemoryBase` or `PersistentMemoryBase`
|
|
276
|
+
2. Implement required abstract methods
|
|
277
|
+
3. Add to `__init__.py` exports
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
MassGen Memory System
|
|
4
|
+
|
|
5
|
+
This module provides memory capabilities for MassGen agents, supporting both
|
|
6
|
+
short-term conversation memory and long-term persistent memory storage.
|
|
7
|
+
|
|
8
|
+
The memory system is designed to be:
|
|
9
|
+
- Asynchronous: All operations are async for optimal performance
|
|
10
|
+
- Pluggable: Easy to swap different storage backends
|
|
11
|
+
- Serializable: Support for saving and loading agent memory state
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from ._base import MemoryBase, PersistentMemoryBase
|
|
15
|
+
from ._compression import CompressionStats, ContextCompressor
|
|
16
|
+
from ._conversation import ConversationMemory
|
|
17
|
+
from ._persistent import PersistentMemory
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"MemoryBase",
|
|
21
|
+
"PersistentMemoryBase",
|
|
22
|
+
"ConversationMemory",
|
|
23
|
+
"PersistentMemory",
|
|
24
|
+
"ContextCompressor",
|
|
25
|
+
"CompressionStats",
|
|
26
|
+
]
|
massgen/memory/_base.py
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Base classes for MassGen memory system.
|
|
4
|
+
|
|
5
|
+
This module defines the abstract interfaces that all memory implementations
|
|
6
|
+
must follow, ensuring consistency across different storage backends.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from abc import ABC, abstractmethod
|
|
10
|
+
from typing import Any, Dict, List, Union
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class MemoryBase(ABC):
|
|
14
|
+
"""
|
|
15
|
+
Abstract base class for memory storage in MassGen.
|
|
16
|
+
|
|
17
|
+
All memory implementations (conversation, persistent, etc.) should inherit
|
|
18
|
+
from this class and implement the required methods.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
@abstractmethod
|
|
22
|
+
async def add(self, *args: Any, **kwargs: Any) -> None:
|
|
23
|
+
"""
|
|
24
|
+
Add new items to memory.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
*args: Variable positional arguments
|
|
28
|
+
**kwargs: Variable keyword arguments
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
@abstractmethod
|
|
32
|
+
async def delete(self, *args: Any, **kwargs: Any) -> None:
|
|
33
|
+
"""
|
|
34
|
+
Remove items from memory.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
*args: Variable positional arguments
|
|
38
|
+
**kwargs: Variable keyword arguments
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
@abstractmethod
|
|
42
|
+
async def retrieve(self, *args: Any, **kwargs: Any) -> Any:
|
|
43
|
+
"""
|
|
44
|
+
Retrieve items from memory based on query.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
*args: Variable positional arguments
|
|
48
|
+
**kwargs: Variable keyword arguments
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
Retrieved memory content
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
@abstractmethod
|
|
55
|
+
async def size(self) -> int:
|
|
56
|
+
"""
|
|
57
|
+
Get the current size of the memory.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
Number of items in memory
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
@abstractmethod
|
|
64
|
+
async def clear(self) -> None:
|
|
65
|
+
"""Clear all content from memory."""
|
|
66
|
+
|
|
67
|
+
@abstractmethod
|
|
68
|
+
async def get_messages(self, *args: Any, **kwargs: Any) -> List[Dict[str, Any]]:
|
|
69
|
+
"""
|
|
70
|
+
Get the stored messages in a format suitable for LLM consumption.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
List of message dictionaries
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
@abstractmethod
|
|
77
|
+
def state_dict(self) -> Dict[str, Any]:
|
|
78
|
+
"""
|
|
79
|
+
Export memory state for serialization.
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
Dictionary containing the memory state
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
@abstractmethod
|
|
86
|
+
def load_state_dict(self, state_dict: Dict[str, Any], strict: bool = True) -> None:
|
|
87
|
+
"""
|
|
88
|
+
Load memory state from serialized data.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
state_dict: Dictionary containing the memory state
|
|
92
|
+
strict: If True, raise error on missing/extra keys
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class PersistentMemoryBase(ABC):
|
|
97
|
+
"""
|
|
98
|
+
Abstract base class for long-term persistent memory.
|
|
99
|
+
|
|
100
|
+
This type of memory is designed to store information across sessions,
|
|
101
|
+
with support for semantic retrieval and knowledge management.
|
|
102
|
+
|
|
103
|
+
Two modes of operation:
|
|
104
|
+
1. Developer-controlled: Use `record()` and `retrieve()` methods programmatically
|
|
105
|
+
2. Agent-controlled: Agent calls `save_to_memory()` and `recall_from_memory()` tools
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
async def record(
|
|
109
|
+
self,
|
|
110
|
+
messages: List[Dict[str, Any]],
|
|
111
|
+
**kwargs: Any,
|
|
112
|
+
) -> None:
|
|
113
|
+
"""
|
|
114
|
+
Developer interface: Record information to persistent memory.
|
|
115
|
+
|
|
116
|
+
This method is called by the framework to automatically save important
|
|
117
|
+
information from conversations.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
messages: List of message dictionaries to record
|
|
121
|
+
**kwargs: Additional recording options
|
|
122
|
+
"""
|
|
123
|
+
raise NotImplementedError(
|
|
124
|
+
"The `record` method is not implemented in this memory backend.",
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
async def retrieve(
|
|
128
|
+
self,
|
|
129
|
+
query: Union[str, Dict[str, Any], List[Dict[str, Any]]],
|
|
130
|
+
**kwargs: Any,
|
|
131
|
+
) -> str:
|
|
132
|
+
"""
|
|
133
|
+
Developer interface: Retrieve relevant information from persistent memory.
|
|
134
|
+
|
|
135
|
+
This method is called by the framework to automatically inject relevant
|
|
136
|
+
historical knowledge into the current conversation.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
query: Query message(s) or string to search for
|
|
140
|
+
**kwargs: Additional retrieval options
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
Retrieved information as formatted string
|
|
144
|
+
"""
|
|
145
|
+
raise NotImplementedError(
|
|
146
|
+
"The `retrieve` method is not implemented in this memory backend.",
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
async def save_to_memory(
|
|
150
|
+
self,
|
|
151
|
+
thinking: str,
|
|
152
|
+
content: List[str],
|
|
153
|
+
**kwargs: Any,
|
|
154
|
+
) -> Dict[str, Any]:
|
|
155
|
+
"""
|
|
156
|
+
Agent tool interface: Save important information to memory.
|
|
157
|
+
|
|
158
|
+
This is a tool function that agents can call to explicitly save
|
|
159
|
+
information they deem important for future reference.
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
thinking: Agent's reasoning about why this information is important
|
|
163
|
+
content: List of information items to save
|
|
164
|
+
**kwargs: Additional save options
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
Tool response with status and saved memory IDs
|
|
168
|
+
"""
|
|
169
|
+
raise NotImplementedError(
|
|
170
|
+
"The `save_to_memory` tool is not implemented in this memory backend. " "Implement this method to allow agents to actively manage their memory.",
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
async def recall_from_memory(
|
|
174
|
+
self,
|
|
175
|
+
keywords: List[str],
|
|
176
|
+
**kwargs: Any,
|
|
177
|
+
) -> Dict[str, Any]:
|
|
178
|
+
"""
|
|
179
|
+
Agent tool interface: Recall information based on keywords.
|
|
180
|
+
|
|
181
|
+
This is a tool function that agents can call to retrieve relevant
|
|
182
|
+
information from their long-term memory.
|
|
183
|
+
|
|
184
|
+
Args:
|
|
185
|
+
keywords: Keywords to search for (person names, dates, topics, etc.)
|
|
186
|
+
**kwargs: Additional recall options
|
|
187
|
+
|
|
188
|
+
Returns:
|
|
189
|
+
Tool response with retrieved memories
|
|
190
|
+
"""
|
|
191
|
+
raise NotImplementedError(
|
|
192
|
+
"The `recall_from_memory` tool is not implemented in this memory backend. " "Implement this method to allow agents to actively query their memory.",
|
|
193
|
+
)
|