From c58701c44afba41bb8fa2936b0f7bf9031ad404a Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 6 Feb 2025 19:48:16 +0000 Subject: [PATCH 1/4] docs: fix long term memory class name in examples - Replace EnhanceLongTermMemory with LongTermMemory to match actual implementation - Update code examples to show correct usage - Fixes #2026 Co-Authored-By: Joe Moura --- docs/concepts/memory.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/concepts/memory.mdx b/docs/concepts/memory.mdx index 6eaf8553ed..828c165f32 100644 --- a/docs/concepts/memory.mdx +++ b/docs/concepts/memory.mdx @@ -66,12 +66,12 @@ my_crew = Crew( tasks=[...], process="Process.sequential", memory=True, - long_term_memory=EnhanceLongTermMemory( + long_term_memory=LongTermMemory( storage=LTMSQLiteStorage( db_path="/my_data_dir/my_crew1/long_term_memory_storage.db" ) ), - short_term_memory=EnhanceShortTermMemory( + short_term_memory=ShortTermMemory( storage=CustomRAGStorage( crew_name="my_crew", storage_type="short_term", @@ -80,7 +80,7 @@ my_crew = Crew( dimension=embedder["dimension"], ), ), - entity_memory=EnhanceEntityMemory( + entity_memory=EntityMemory( storage=CustomRAGStorage( crew_name="my_crew", storage_type="entities", From af541127886aec67f058029c21551ae8681a9fb6 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 6 Feb 2025 19:54:59 +0000 Subject: [PATCH 2/4] docs: improve memory examples with imports, types and security - Add proper import statements - Add type hints for better readability - Add descriptive comments for each memory type - Add security considerations section - Add configuration examples section - Use environment variables for storage paths Co-Authored-By: Joe Moura --- docs/concepts/memory.mdx | 110 ++++++++++++++++++++++++++++++++++----- 1 file changed, 98 insertions(+), 12 deletions(-) diff --git a/docs/concepts/memory.mdx b/docs/concepts/memory.mdx index 828c165f32..00e9f9c42c 100644 --- a/docs/concepts/memory.mdx +++ b/docs/concepts/memory.mdx @@ -58,33 +58,39 @@ my_crew = Crew( ### Example: Use Custom Memory Instances e.g FAISS as the VectorDB ```python Code -from crewai import Crew, Agent, Task, Process +from crewai import Crew, Process +from crewai.memory import LongTermMemory, ShortTermMemory, EntityMemory +from crewai.memory.storage import LTMSQLiteStorage, CustomRAGStorage +from typing import List, Optional # Assemble your crew with memory capabilities -my_crew = Crew( - agents=[...], - tasks=[...], - process="Process.sequential", - memory=True, - long_term_memory=LongTermMemory( +my_crew: Crew = Crew( + agents: List = [...], + tasks: List = [...], + process: str = Process.sequential, + memory: bool = True, + # Long-term memory for persistent storage across sessions + long_term_memory: Optional[LongTermMemory] = LongTermMemory( storage=LTMSQLiteStorage( - db_path="/my_data_dir/my_crew1/long_term_memory_storage.db" + db_path="${CREWAI_STORAGE_DIR}/my_crew1/long_term_memory_storage.db" ) ), - short_term_memory=ShortTermMemory( + # Short-term memory for current context using RAG + short_term_memory: Optional[ShortTermMemory] = ShortTermMemory( storage=CustomRAGStorage( crew_name="my_crew", storage_type="short_term", - data_dir="//my_data_dir", + data_dir="${CREWAI_STORAGE_DIR}", model=embedder["model"], dimension=embedder["dimension"], ), ), - entity_memory=EntityMemory( + # Entity memory for tracking key information about entities + entity_memory: Optional[EntityMemory] = EntityMemory( storage=CustomRAGStorage( crew_name="my_crew", storage_type="entities", - data_dir="//my_data_dir", + data_dir="${CREWAI_STORAGE_DIR}", model=embedder["model"], dimension=embedder["dimension"], ), @@ -93,6 +99,86 @@ my_crew = Crew( ) ``` +## Security Considerations + +When configuring memory storage: +- Use environment variables for storage paths (e.g., `CREWAI_STORAGE_DIR`) +- Never hardcode sensitive information like database credentials +- Consider access permissions for storage directories +- Use relative paths when possible to maintain portability + +Example using environment variables: +```python +import os +from crewai import Crew +from crewai.memory import LongTermMemory +from crewai.memory.storage import LTMSQLiteStorage + +# Configure storage path using environment variable +storage_path = os.getenv("CREWAI_STORAGE_DIR", "./storage") +crew = Crew( + memory=True, + long_term_memory=LongTermMemory( + storage=LTMSQLiteStorage( + db_path="{storage_path}/memory.db".format(storage_path=storage_path) + ) + ) +) +``` + +## Configuration Examples + +### Basic Memory Configuration +```python +from crewai import Crew +from crewai.memory import LongTermMemory + +# Simple memory configuration +crew = Crew(memory=True) # Uses default storage locations +``` + +### Custom Storage Configuration +```python +from crewai import Crew +from crewai.memory import LongTermMemory +from crewai.memory.storage import LTMSQLiteStorage + +# Configure custom storage paths +crew = Crew( + memory=True, + long_term_memory=LongTermMemory( + storage=LTMSQLiteStorage(db_path="./memory.db") + ) +) +``` + +### Full Memory Configuration +```python +from crewai import Crew +from crewai.memory import LongTermMemory, ShortTermMemory, EntityMemory +from crewai.memory.storage import LTMSQLiteStorage, CustomRAGStorage + +# Configure all memory types with custom storage +crew = Crew( + memory=True, + long_term_memory=LongTermMemory( + storage=LTMSQLiteStorage(db_path="./ltm.db") + ), + short_term_memory=ShortTermMemory( + storage=CustomRAGStorage( + crew_name="my_crew", + storage_type="short_term" + ) + ), + entity_memory=EntityMemory( + storage=CustomRAGStorage( + crew_name="my_crew", + storage_type="entities" + ) + ) +) +``` + ## Integrating Mem0 for Enhanced User Memory [Mem0](https://mem0.ai/) is a self-improving memory layer for LLM applications, enabling personalized AI experiences. From d092da068741d8d36c9e35bbc4d33a98405505b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Sun, 9 Feb 2025 16:45:35 -0300 Subject: [PATCH 3/4] Update memory.mdx --- docs/concepts/memory.mdx | 51 +++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/docs/concepts/memory.mdx b/docs/concepts/memory.mdx index 00e9f9c42c..7d4a391cfb 100644 --- a/docs/concepts/memory.mdx +++ b/docs/concepts/memory.mdx @@ -60,40 +60,47 @@ my_crew = Crew( ```python Code from crewai import Crew, Process from crewai.memory import LongTermMemory, ShortTermMemory, EntityMemory -from crewai.memory.storage import LTMSQLiteStorage, CustomRAGStorage +from crewai.memory.storage import LTMSQLiteStorage, RAGStorage from typing import List, Optional # Assemble your crew with memory capabilities my_crew: Crew = Crew( - agents: List = [...], - tasks: List = [...], - process: str = Process.sequential, - memory: bool = True, + agents = [...], + tasks = [...], + process = Process.sequential, + memory = True, # Long-term memory for persistent storage across sessions - long_term_memory: Optional[LongTermMemory] = LongTermMemory( + long_term_memory = LongTermMemory( storage=LTMSQLiteStorage( - db_path="${CREWAI_STORAGE_DIR}/my_crew1/long_term_memory_storage.db" + db_path="/my_crew1/long_term_memory_storage.db" ) ), # Short-term memory for current context using RAG - short_term_memory: Optional[ShortTermMemory] = ShortTermMemory( - storage=CustomRAGStorage( - crew_name="my_crew", - storage_type="short_term", - data_dir="${CREWAI_STORAGE_DIR}", - model=embedder["model"], - dimension=embedder["dimension"], + short_term_memory = ShortTermMemory( + storage = RAGStorage( + embedder_config={ + "provider": "openai", + "config": { + "model": 'text-embedding-3-small' + } + }, + type="short_term", + path="/my_crew1/" + ) ), ), # Entity memory for tracking key information about entities - entity_memory: Optional[EntityMemory] = EntityMemory( - storage=CustomRAGStorage( - crew_name="my_crew", - storage_type="entities", - data_dir="${CREWAI_STORAGE_DIR}", - model=embedder["model"], - dimension=embedder["dimension"], - ), + entity_memory = EntityMemory( + storage=RAGStorage( + embedder_config={ + "provider": "openai", + "config": { + "model": 'text-embedding-3-small' + } + }, + type="short_term", + path="/my_crew1/" + ) ), verbose=True, ) From f0d773da795145cfabd80fe5e290cc2c6cc21bce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moura?= Date: Sun, 9 Feb 2025 16:47:05 -0300 Subject: [PATCH 4/4] Update memory.mdx --- docs/concepts/memory.mdx | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/docs/concepts/memory.mdx b/docs/concepts/memory.mdx index 7d4a391cfb..1f4c077577 100644 --- a/docs/concepts/memory.mdx +++ b/docs/concepts/memory.mdx @@ -159,33 +159,6 @@ crew = Crew( ) ``` -### Full Memory Configuration -```python -from crewai import Crew -from crewai.memory import LongTermMemory, ShortTermMemory, EntityMemory -from crewai.memory.storage import LTMSQLiteStorage, CustomRAGStorage - -# Configure all memory types with custom storage -crew = Crew( - memory=True, - long_term_memory=LongTermMemory( - storage=LTMSQLiteStorage(db_path="./ltm.db") - ), - short_term_memory=ShortTermMemory( - storage=CustomRAGStorage( - crew_name="my_crew", - storage_type="short_term" - ) - ), - entity_memory=EntityMemory( - storage=CustomRAGStorage( - crew_name="my_crew", - storage_type="entities" - ) - ) -) -``` - ## Integrating Mem0 for Enhanced User Memory [Mem0](https://mem0.ai/) is a self-improving memory layer for LLM applications, enabling personalized AI experiences.