massgen 0.1.4__py3-none-any.whl → 0.1.6__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.

Files changed (84) hide show
  1. massgen/__init__.py +1 -1
  2. massgen/backend/base_with_custom_tool_and_mcp.py +453 -23
  3. massgen/backend/capabilities.py +39 -0
  4. massgen/backend/chat_completions.py +111 -197
  5. massgen/backend/claude.py +210 -181
  6. massgen/backend/gemini.py +1015 -1559
  7. massgen/backend/grok.py +3 -2
  8. massgen/backend/response.py +160 -220
  9. massgen/chat_agent.py +340 -20
  10. massgen/cli.py +399 -25
  11. massgen/config_builder.py +20 -54
  12. massgen/config_validator.py +931 -0
  13. massgen/configs/README.md +95 -10
  14. massgen/configs/memory/gpt5mini_gemini_baseline_research_to_implementation.yaml +94 -0
  15. massgen/configs/memory/gpt5mini_gemini_context_window_management.yaml +187 -0
  16. massgen/configs/memory/gpt5mini_gemini_research_to_implementation.yaml +127 -0
  17. massgen/configs/memory/gpt5mini_high_reasoning_gemini.yaml +107 -0
  18. massgen/configs/memory/single_agent_compression_test.yaml +64 -0
  19. massgen/configs/tools/custom_tools/claude_code_custom_tool_with_mcp_example.yaml +1 -0
  20. massgen/configs/tools/custom_tools/claude_custom_tool_example_no_path.yaml +1 -1
  21. massgen/configs/tools/custom_tools/claude_custom_tool_with_mcp_example.yaml +1 -0
  22. massgen/configs/tools/custom_tools/computer_use_browser_example.yaml +1 -1
  23. massgen/configs/tools/custom_tools/computer_use_docker_example.yaml +1 -1
  24. massgen/configs/tools/custom_tools/gemini_custom_tool_with_mcp_example.yaml +1 -0
  25. massgen/configs/tools/custom_tools/gpt5_nano_custom_tool_with_mcp_example.yaml +1 -0
  26. massgen/configs/tools/custom_tools/gpt_oss_custom_tool_with_mcp_example.yaml +1 -0
  27. massgen/configs/tools/custom_tools/grok3_mini_custom_tool_with_mcp_example.yaml +1 -0
  28. massgen/configs/tools/custom_tools/interop/ag2_and_langgraph_lesson_planner.yaml +65 -0
  29. massgen/configs/tools/custom_tools/interop/ag2_and_openai_assistant_lesson_planner.yaml +65 -0
  30. massgen/configs/tools/custom_tools/interop/ag2_lesson_planner_example.yaml +48 -0
  31. massgen/configs/tools/custom_tools/interop/agentscope_lesson_planner_example.yaml +48 -0
  32. massgen/configs/tools/custom_tools/interop/langgraph_lesson_planner_example.yaml +49 -0
  33. massgen/configs/tools/custom_tools/interop/openai_assistant_lesson_planner_example.yaml +50 -0
  34. massgen/configs/tools/custom_tools/interop/smolagent_lesson_planner_example.yaml +49 -0
  35. massgen/configs/tools/custom_tools/qwen_api_custom_tool_with_mcp_example.yaml +1 -0
  36. massgen/configs/tools/custom_tools/two_models_with_tools_example.yaml +44 -0
  37. massgen/formatter/_gemini_formatter.py +61 -15
  38. massgen/memory/README.md +277 -0
  39. massgen/memory/__init__.py +26 -0
  40. massgen/memory/_base.py +193 -0
  41. massgen/memory/_compression.py +237 -0
  42. massgen/memory/_context_monitor.py +211 -0
  43. massgen/memory/_conversation.py +255 -0
  44. massgen/memory/_fact_extraction_prompts.py +333 -0
  45. massgen/memory/_mem0_adapters.py +257 -0
  46. massgen/memory/_persistent.py +687 -0
  47. massgen/memory/docker-compose.qdrant.yml +36 -0
  48. massgen/memory/docs/DESIGN.md +388 -0
  49. massgen/memory/docs/QUICKSTART.md +409 -0
  50. massgen/memory/docs/SUMMARY.md +319 -0
  51. massgen/memory/docs/agent_use_memory.md +408 -0
  52. massgen/memory/docs/orchestrator_use_memory.md +586 -0
  53. massgen/memory/examples.py +237 -0
  54. massgen/orchestrator.py +207 -7
  55. massgen/tests/memory/test_agent_compression.py +174 -0
  56. massgen/tests/memory/test_context_window_management.py +286 -0
  57. massgen/tests/memory/test_force_compression.py +154 -0
  58. massgen/tests/memory/test_simple_compression.py +147 -0
  59. massgen/tests/test_ag2_lesson_planner.py +223 -0
  60. massgen/tests/test_agent_memory.py +534 -0
  61. massgen/tests/test_config_validator.py +1156 -0
  62. massgen/tests/test_conversation_memory.py +382 -0
  63. massgen/tests/test_langgraph_lesson_planner.py +223 -0
  64. massgen/tests/test_orchestrator_memory.py +620 -0
  65. massgen/tests/test_persistent_memory.py +435 -0
  66. massgen/token_manager/token_manager.py +6 -0
  67. massgen/tool/__init__.py +2 -9
  68. massgen/tool/_decorators.py +52 -0
  69. massgen/tool/_extraframework_agents/ag2_lesson_planner_tool.py +251 -0
  70. massgen/tool/_extraframework_agents/agentscope_lesson_planner_tool.py +303 -0
  71. massgen/tool/_extraframework_agents/langgraph_lesson_planner_tool.py +275 -0
  72. massgen/tool/_extraframework_agents/openai_assistant_lesson_planner_tool.py +247 -0
  73. massgen/tool/_extraframework_agents/smolagent_lesson_planner_tool.py +180 -0
  74. massgen/tool/_manager.py +102 -16
  75. massgen/tool/_registered_tool.py +3 -0
  76. massgen/tool/_result.py +3 -0
  77. {massgen-0.1.4.dist-info → massgen-0.1.6.dist-info}/METADATA +138 -77
  78. {massgen-0.1.4.dist-info → massgen-0.1.6.dist-info}/RECORD +82 -37
  79. massgen/backend/gemini_mcp_manager.py +0 -545
  80. massgen/backend/gemini_trackers.py +0 -344
  81. {massgen-0.1.4.dist-info → massgen-0.1.6.dist-info}/WHEEL +0 -0
  82. {massgen-0.1.4.dist-info → massgen-0.1.6.dist-info}/entry_points.txt +0 -0
  83. {massgen-0.1.4.dist-info → massgen-0.1.6.dist-info}/licenses/LICENSE +0 -0
  84. {massgen-0.1.4.dist-info → massgen-0.1.6.dist-info}/top_level.txt +0 -0
@@ -52,11 +52,57 @@ class GeminiFormatter(FormatterBase):
52
52
  """
53
53
  return tools or []
54
54
 
55
- def format_mcp_tools(self, mcp_functions: Dict[str, Any]) -> List[Dict[str, Any]]:
55
+ def format_mcp_tools(
56
+ self,
57
+ mcp_functions: Dict[str, Any],
58
+ return_sdk_objects: bool = True,
59
+ ) -> List[Any]:
56
60
  """
57
- MCP tools are passed via SDK sessions in stream_with_tools; not function declarations.
61
+ Convert MCP Function objects to Gemini FunctionDeclaration format.
62
+
58
63
  """
59
- return []
64
+ if not mcp_functions:
65
+ return []
66
+
67
+ # Step 1: Convert MCP Function objects to Gemini dictionary format
68
+ gemini_dicts = []
69
+
70
+ for mcp_function in mcp_functions.values():
71
+ try:
72
+ # Extract attributes from Function object
73
+ name = getattr(mcp_function, "name", "")
74
+ description = getattr(mcp_function, "description", "")
75
+ parameters = getattr(mcp_function, "parameters", {})
76
+
77
+ # Build Gemini-compatible dictionary
78
+ gemini_dict = {
79
+ "name": name,
80
+ "description": description,
81
+ "parameters": parameters,
82
+ }
83
+ gemini_dicts.append(gemini_dict)
84
+
85
+ logger.debug(f"[GeminiFormatter] Converted MCP tool '{name}' to dictionary format")
86
+
87
+ except Exception as e:
88
+ logger.error(f"[GeminiFormatter] Failed to convert MCP tool: {e}")
89
+ # Continue processing remaining tools instead of failing completely
90
+ continue
91
+
92
+ if not return_sdk_objects:
93
+ return gemini_dicts
94
+
95
+ # Step 2: Convert dictionaries to SDK FunctionDeclaration objects
96
+ function_declarations = self._convert_to_function_declarations(gemini_dicts)
97
+
98
+ # Log successful conversion
99
+ for func_decl in function_declarations:
100
+ if hasattr(func_decl, "name"):
101
+ logger.debug(
102
+ f"[GeminiFormatter] Converted MCP tool '{func_decl.name}' to FunctionDeclaration",
103
+ )
104
+
105
+ return function_declarations
60
106
 
61
107
  # Coordination helpers
62
108
 
@@ -239,15 +285,14 @@ Make your decision and include the JSON at the very end of your response."""
239
285
  vote_data = structured_response.get("vote_data", {})
240
286
  return [
241
287
  {
242
- "id": f"vote_{abs(hash(str(vote_data))) % 10000 + 1}",
243
- "type": "function",
244
- "function": {
245
- "name": "vote",
246
- "arguments": {
288
+ "call_id": f"vote_{abs(hash(str(vote_data))) % 10000 + 1}",
289
+ "name": "vote",
290
+ "arguments": json.dumps(
291
+ {
247
292
  "agent_id": vote_data.get("agent_id", ""),
248
293
  "reason": vote_data.get("reason", ""),
249
294
  },
250
- },
295
+ ),
251
296
  },
252
297
  ]
253
298
 
@@ -255,12 +300,13 @@ Make your decision and include the JSON at the very end of your response."""
255
300
  answer_data = structured_response.get("answer_data", {})
256
301
  return [
257
302
  {
258
- "id": f"new_answer_{abs(hash(str(answer_data))) % 10000 + 1}",
259
- "type": "function",
260
- "function": {
261
- "name": "new_answer",
262
- "arguments": {"content": answer_data.get("content", "")},
263
- },
303
+ "call_id": f"new_answer_{abs(hash(str(answer_data))) % 10000 + 1}",
304
+ "name": "new_answer",
305
+ "arguments": json.dumps(
306
+ {
307
+ "content": answer_data.get("content", ""),
308
+ },
309
+ ),
264
310
  },
265
311
  ]
266
312
 
@@ -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
+ ]
@@ -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
+ )