Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the path where all memories are saved #542

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

arnaudgelas
Copy link

No description provided.

src/crewai/memory/memory.py Outdated Show resolved Hide resolved
src/crewai/memory/memory.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@gvieira gvieira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we have default values in storage classes, like LTMSQLiteStorage. We should probably adjust the pipeline to move defaults up then, otherwise we'll have multiple places with default values.

@arnaudgelas
Copy link
Author

Currently we have default values in storage classes, like LTMSQLiteStorage. We should probably adjust the pipeline to move defaults up then, otherwise we'll have multiple places with default values.

I agree with you. Do you want me to do this as part of this PR ?

@gvieira
Copy link
Collaborator

gvieira commented Jun 7, 2024

@arnaudgelas that would be awesome! Happy to streamline the review process.

@arnaudgelas arnaudgelas force-pushed the memory_path branch 2 times, most recently from 042d3a7 to 39ecfbb Compare June 8, 2024 13:41
@arnaudgelas
Copy link
Author

@gvieira Consider merging first #743, then you can review this one

Copy link

This PR is stale because it has been open for 45 days with no activity.

@pythonbyte
Copy link
Collaborator

Hey @arnaudgelas, thanks for the Pull Request.

Can you take a moment to check if this is still relevant, I'm saying because there were a lot of changes in regards to the Memory part of the project. Also, there are a lot of conflicts across the PR so maybe would be good to start a new branch from the main or resolve them. Let us know if you need any help and we’ll sort it out together.

Thanks!

@joaomdmoura
Copy link
Collaborator

Disclaimer: This review was made by a crew of AI Agents.

Code Review Comment for PR #542

Overview

This pull request introduces significant improvements to the crewAI project by addressing code quality issues and updating memory storage path configurations. The changes enhance maintainability and promote best practices.

Code Quality Findings

1. Pre-commit Error Fixes

  • Unused Imports: It's great to see the cleanup of unused imports across different modules. This helps in reducing the overall memory footprint and improves code readability.
  • __all__ Declarations: The introduction of __all__ in __init__.py files is a commendable move. It clearly defines the public API of the modules:
    # src/crewai/__init__.py
    __all__ = ["Agent", "Crew", "Process", "Task"]
  • Code Formatting: The formatting of the with statement in fileHandler.py is improved for consistency:
    # Improved formatting
    with open(self._path, "a", encoding="utf-8") as file:
  • Logger Improvements: Adding the missing datetime import in logger.py enhances logging accuracy.

2. Memory Storage Path Configuration

  • Centralized Configuration: Centralizing memory path management boosts flexibility in handling storage paths. The function get_memory_paths is a solid addition:
    def get_memory_paths(memory_path: Path | None = None) -> tuple[Path, Path, Path]:
  • Memory Initialization: The updated memory initialization in the Crew class enhances the encapsulation and management of memory usage.

Historical Context from Related PRs

It would be beneficial to refer to related PRs that may have previously addressed memory management or module structure since these changes build upon those foundations. Referencing those decisions can provide insights into the design choices made. However, due to technical constraints, I couldn't fetch that data directly.

Implications for Related Files

A notable impact of these changes will likely be felt in files directly interacting with the Crew, memory management, and logging:

  • Memory Management Files: Files like entity_memory.py, long_term_memory.py, and short_term_memory.py all relate closely to the changes made. Ensure that they align with the new configurations and utilize the updated memory management functions effectively.
  • Logger Module: Increased accuracy in logging will help in tracking memory states and errors, so it's critical to test thoroughly.

Specific Improvement Suggestions

  1. Type Hints: Adding type hints enhances code clarity:

    def log(self, level: str, message: str, color: str = "bold_green") -> None:
  2. Docstrings: Consider implementing comprehensive docstrings for all new functions and classes:

    def get_memory_paths(memory_path: Path | None = None) -> tuple[Path, Path, Path]:
        """
        Get the paths for different types of memory storage.
        Args:
            memory_path: Optional custom path for memory storage
        Returns:
            Tuple containing paths for long-term, short-term, and entity memory
        """
  3. Error Handling: Implement error handling for memory path creation to guard against filesystem issues:

    try:
        memory_path.mkdir(parents=True, exist_ok=True)
    except Exception as e:
        raise RuntimeError(f"Failed to initialize memory paths: {str(e)}")
  4. Validation of Memory Path Permissions: Adding additional validation checks for memory path accessibility will further solidify the reliability of this system:

    def validate_memory_path(path: Path) -> None:
        """ 
        Validate that the memory path is writable and accessible.
        """
        if not os.access(path.parent, os.W_OK):
            raise PermissionError(f"No write permission for memory path: {path}")

Conclusion

The modifications proposed in this pull request significantly improve both code quality and memory management functionality. The suggested improvements will further enhance robustness and clarity. Overall, excellent work on navigating these critical areas of the codebase!

Let's continue to build on this momentum toward cleaner and more modular code.

@arnaudgelas
Copy link
Author

I will work on it next week

- Initialize contextual_memory in src/crewai/agent.py and src/crewai/crew.py
- Make UserMemory optional and add checks in src/crewai/memory/contextual/contextual_memory.py
- Add crew checks in src/crewai/memory/entity/entity_memory.py and
  src/crewai/memory/short_term/short_term_memory.py
- Allow optional storage_path in src/crewai/memory/storage/base_rag_storage.py
- Update storage classes to accept optional db_path in:
  src/crewai/memory/storage/kickoff_task_outputs_storage.py,
  src/crewai/memory/storage/ltm_sqlite_storage.py, and
  src/crewai/memory/storage/mem0_storage.py
- Modify src/crewai/memory/storage/rag_storage.py to use storage_path
- Enhance src/crewai/utilities/embedding_configurator.py to handle missing providers
@arnaudgelas
Copy link
Author

@gvieira @joaomdmoura I am looking forward to reading your reviews/comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants