Minor fixes in procedural memory (#2469)
This commit is contained in:
@@ -220,14 +220,14 @@ You are a memory summarization system that records and preserves the complete in
|
|||||||
Each numbered step must be a self-contained entry that includes all of the following elements:
|
Each numbered step must be a self-contained entry that includes all of the following elements:
|
||||||
|
|
||||||
1. **Agent Action**:
|
1. **Agent Action**:
|
||||||
- Precisely describe what the agent did (e.g., "Clicked on the 'Blog' link", "Called API to fetch content", "Scraped page data").
|
- Precisely describe what the agent did (e.g., "Clicked on the 'Blog' link", "Called API to fetch content", "Scraped page data").
|
||||||
- Include all parameters, target elements, or methods involved.
|
- Include all parameters, target elements, or methods involved.
|
||||||
|
|
||||||
2. **Action Result (Mandatory, Unmodified)**:
|
2. **Action Result (Mandatory, Unmodified)**:
|
||||||
- Immediately follow the agent action with its exact, unaltered output.
|
- Immediately follow the agent action with its exact, unaltered output.
|
||||||
- Record all returned data, responses, HTML snippets, JSON content, or error messages exactly as received. This is critical for constructing the final output later.
|
- Record all returned data, responses, HTML snippets, JSON content, or error messages exactly as received. This is critical for constructing the final output later.
|
||||||
|
|
||||||
3. **Embedded Metadata**:
|
3. **Embedded Metadata**:
|
||||||
For the same numbered step, include additional context such as:
|
For the same numbered step, include additional context such as:
|
||||||
- **Key Findings**: Any important information discovered (e.g., URLs, data points, search results).
|
- **Key Findings**: Any important information discovered (e.g., URLs, data points, search results).
|
||||||
- **Navigation History**: For browser agents, detail which pages were visited, including their URLs and relevance.
|
- **Navigation History**: For browser agents, detail which pages were visited, including their URLs and relevance.
|
||||||
@@ -246,6 +246,8 @@ You are a memory summarization system that records and preserves the complete in
|
|||||||
### Example Template:
|
### Example Template:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
## Summary of the agent's execution history
|
||||||
|
|
||||||
**Task Objective**: Scrape blog post titles and full content from the OpenAI blog.
|
**Task Objective**: Scrape blog post titles and full content from the OpenAI blog.
|
||||||
**Progress Status**: 10% complete — 5 out of 50 blog posts processed.
|
**Progress Status**: 10% complete — 5 out of 50 blog posts processed.
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ class Memory(MemoryBase):
|
|||||||
infer=True,
|
infer=True,
|
||||||
memory_type=None,
|
memory_type=None,
|
||||||
prompt=None,
|
prompt=None,
|
||||||
|
llm=None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Create a new memory.
|
Create a new memory.
|
||||||
@@ -103,6 +104,7 @@ class Memory(MemoryBase):
|
|||||||
infer (bool, optional): Whether to infer the memories. Defaults to True.
|
infer (bool, optional): Whether to infer the memories. Defaults to True.
|
||||||
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.
|
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.
|
||||||
prompt (str, optional): Prompt to use for the memory creation. Defaults to None.
|
prompt (str, optional): Prompt to use for the memory creation. Defaults to None.
|
||||||
|
llm (BaseChatModel, optional): LLM class to use for generating procedural memories. Defaults to None. Useful when user is using LangChain ChatModel.
|
||||||
Returns:
|
Returns:
|
||||||
dict: A dictionary containing the result of the memory addition operation.
|
dict: A dictionary containing the result of the memory addition operation.
|
||||||
result: dict of affected events with each dict has the following key:
|
result: dict of affected events with each dict has the following key:
|
||||||
@@ -139,7 +141,7 @@ class Memory(MemoryBase):
|
|||||||
messages = [{"role": "user", "content": messages}]
|
messages = [{"role": "user", "content": messages}]
|
||||||
|
|
||||||
if agent_id is not None and memory_type == MemoryType.PROCEDURAL.value:
|
if agent_id is not None and memory_type == MemoryType.PROCEDURAL.value:
|
||||||
results = self._create_procedural_memory(messages, metadata, prompt)
|
results = self._create_procedural_memory(messages, metadata=metadata, llm=llm, prompt=prompt)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
if self.config.llm.config.get("enable_vision"):
|
if self.config.llm.config.get("enable_vision"):
|
||||||
@@ -623,9 +625,15 @@ class Memory(MemoryBase):
|
|||||||
capture_event("mem0._create_memory", self, {"memory_id": memory_id})
|
capture_event("mem0._create_memory", self, {"memory_id": memory_id})
|
||||||
return memory_id
|
return memory_id
|
||||||
|
|
||||||
def _create_procedural_memory(self, messages, metadata, llm=None, prompt=None):
|
def _create_procedural_memory(self, messages, metadata=None, llm=None, prompt=None):
|
||||||
"""
|
"""
|
||||||
Create a procedural memory
|
Create a procedural memory
|
||||||
|
|
||||||
|
Args:
|
||||||
|
messages (list): List of messages to create a procedural memory from.
|
||||||
|
metadata (dict): Metadata to create a procedural memory from.
|
||||||
|
llm (BaseChatModel, optional): LLM class to use for generating procedural memories. Defaults to None. Useful when user is using LangChain ChatModel.
|
||||||
|
prompt (str, optional): Prompt to use for the procedural memory creation. Defaults to None.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from langchain_core.messages.utils import convert_to_messages # type: ignore
|
from langchain_core.messages.utils import convert_to_messages # type: ignore
|
||||||
@@ -644,7 +652,7 @@ class Memory(MemoryBase):
|
|||||||
try:
|
try:
|
||||||
if llm is not None:
|
if llm is not None:
|
||||||
parsed_messages = convert_to_messages(parsed_messages)
|
parsed_messages = convert_to_messages(parsed_messages)
|
||||||
response = llm.invoke(messages=parsed_messages)
|
response = llm.invoke(input=parsed_messages)
|
||||||
procedural_memory = response.content
|
procedural_memory = response.content
|
||||||
else:
|
else:
|
||||||
procedural_memory = self.llm.generate_response(messages=parsed_messages)
|
procedural_memory = self.llm.generate_response(messages=parsed_messages)
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ class FAISS(VectorStoreBase):
|
|||||||
faiss.write_index(self.index, index_path)
|
faiss.write_index(self.index, index_path)
|
||||||
with open(docstore_path, "wb") as f:
|
with open(docstore_path, "wb") as f:
|
||||||
pickle.dump((self.docstore, self.index_to_id), f)
|
pickle.dump((self.docstore, self.index_to_id), f)
|
||||||
logger.info(f"Saved FAISS index to {index_path} with {self.index.ntotal} vectors")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to save FAISS index: {e}")
|
logger.warning(f"Failed to save FAISS index: {e}")
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "mem0ai"
|
name = "mem0ai"
|
||||||
version = "0.1.80"
|
version = "0.1.81"
|
||||||
description = "Long-term memory for AI Agents"
|
description = "Long-term memory for AI Agents"
|
||||||
authors = ["Mem0 <founders@mem0.ai>"]
|
authors = ["Mem0 <founders@mem0.ai>"]
|
||||||
exclude = [
|
exclude = [
|
||||||
|
|||||||
Reference in New Issue
Block a user