Skip to content

Commit c1f5a65

Browse files
authored
Minor fixes in procedural memory (#2469)
1 parent 72bb631 commit c1f5a65

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

mem0/configs/prompts.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,14 @@
220220
Each numbered step must be a self-contained entry that includes all of the following elements:
221221
222222
1. **Agent Action**:
223-
- Precisely describe what the agent did (e.g., "Clicked on the 'Blog' link", "Called API to fetch content", "Scraped page data").
223+
- Precisely describe what the agent did (e.g., "Clicked on the 'Blog' link", "Called API to fetch content", "Scraped page data").
224224
- Include all parameters, target elements, or methods involved.
225-
226-
2. **Action Result (Mandatory, Unmodified)**:
227-
- Immediately follow the agent action with its exact, unaltered output.
225+
226+
2. **Action Result (Mandatory, Unmodified)**:
227+
- Immediately follow the agent action with its exact, unaltered output.
228228
- Record all returned data, responses, HTML snippets, JSON content, or error messages exactly as received. This is critical for constructing the final output later.
229-
230-
3. **Embedded Metadata**:
229+
230+
3. **Embedded Metadata**:
231231
For the same numbered step, include additional context such as:
232232
- **Key Findings**: Any important information discovered (e.g., URLs, data points, search results).
233233
- **Navigation History**: For browser agents, detail which pages were visited, including their URLs and relevance.
@@ -246,6 +246,8 @@
246246
### Example Template:
247247
248248
```
249+
## Summary of the agent's execution history
250+
249251
**Task Objective**: Scrape blog post titles and full content from the OpenAI blog.
250252
**Progress Status**: 10% complete — 5 out of 50 blog posts processed.
251253

mem0/memory/main.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def add(
8989
infer=True,
9090
memory_type=None,
9191
prompt=None,
92+
llm=None,
9293
):
9394
"""
9495
Create a new memory.
@@ -103,6 +104,7 @@ def add(
103104
infer (bool, optional): Whether to infer the memories. Defaults to True.
104105
memory_type (str, optional): Type of memory to create. Defaults to None. By default, it creates the short term memories and long term (semantic and episodic) memories. Pass "procedural_memory" to create procedural memories.
105106
prompt (str, optional): Prompt to use for the memory creation. Defaults to None.
107+
llm (BaseChatModel, optional): LLM class to use for generating procedural memories. Defaults to None. Useful when user is using LangChain ChatModel.
106108
Returns:
107109
dict: A dictionary containing the result of the memory addition operation.
108110
result: dict of affected events with each dict has the following key:
@@ -139,7 +141,7 @@ def add(
139141
messages = [{"role": "user", "content": messages}]
140142

141143
if agent_id is not None and memory_type == MemoryType.PROCEDURAL.value:
142-
results = self._create_procedural_memory(messages, metadata, prompt)
144+
results = self._create_procedural_memory(messages, metadata=metadata, llm=llm, prompt=prompt)
143145
return results
144146

145147
if self.config.llm.config.get("enable_vision"):
@@ -623,9 +625,15 @@ def _create_memory(self, data, existing_embeddings, metadata=None):
623625
capture_event("mem0._create_memory", self, {"memory_id": memory_id})
624626
return memory_id
625627

626-
def _create_procedural_memory(self, messages, metadata, llm=None, prompt=None):
628+
def _create_procedural_memory(self, messages, metadata=None, llm=None, prompt=None):
627629
"""
628630
Create a procedural memory
631+
632+
Args:
633+
messages (list): List of messages to create a procedural memory from.
634+
metadata (dict): Metadata to create a procedural memory from.
635+
llm (BaseChatModel, optional): LLM class to use for generating procedural memories. Defaults to None. Useful when user is using LangChain ChatModel.
636+
prompt (str, optional): Prompt to use for the procedural memory creation. Defaults to None.
629637
"""
630638
try:
631639
from langchain_core.messages.utils import convert_to_messages # type: ignore
@@ -644,7 +652,7 @@ def _create_procedural_memory(self, messages, metadata, llm=None, prompt=None):
644652
try:
645653
if llm is not None:
646654
parsed_messages = convert_to_messages(parsed_messages)
647-
response = llm.invoke(messages=parsed_messages)
655+
response = llm.invoke(input=parsed_messages)
648656
procedural_memory = response.content
649657
else:
650658
procedural_memory = self.llm.generate_response(messages=parsed_messages)

mem0/vector_stores/faiss.py

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ def _save(self):
101101
faiss.write_index(self.index, index_path)
102102
with open(docstore_path, "wb") as f:
103103
pickle.dump((self.docstore, self.index_to_id), f)
104-
logger.info(f"Saved FAISS index to {index_path} with {self.index.ntotal} vectors")
105104
except Exception as e:
106105
logger.warning(f"Failed to save FAISS index: {e}")
107106

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "mem0ai"
3-
version = "0.1.80"
3+
version = "0.1.81"
44
description = "Long-term memory for AI Agents"
55
authors = ["Mem0 <[email protected]>"]
66
exclude = [

0 commit comments

Comments
 (0)