Unlocking CrewAI 6: Enhancing AI Intelligence with 5 Memory Modes

Types of Memory in CrewAI

Unlocking CrewAI 6: Enhancing AI Intelligence with 5 Memory Modes

In CrewAI, the memory system enhances the capabilities of AI agents by enabling them to remember, reason, and learn from past interactions.

Previous Chapter:

The system consists of several key components:

  • Short-Term Memory: This component temporarily stores recent interactions and outcomes, allowing the agent to recall relevant information during ongoing tasks. For example, it helps maintain conversational consistency by recalling what has just been discussed. Using RAG.
  • Long-Term Memory: This serves as a repository for valuable insights and learnings from past interactions. It enables the agent to build and refine its knowledge over time, improving decision-making processes based on historical data.
  • Entity Memory: This type captures and organizes information about entities encountered in tasks (such as people, places, and concepts). It facilitates a deeper understanding and relationship mapping between these entities. Using RAG.
  • Context Memory: It integrates short-term memory, long-term memory, and entity memory to maintain the context of interactions. This ensures that the agent can provide consistent and relevant responses throughout a conversation or task sequence.
  • User Memory: It stores user-specific information and preferences, enhancing personalization and user experience.

By leveraging these memory components, CrewAI agents achieve:

  • Context Awareness: Maintaining context during conversations or task sequences leads to more consistent and relevant responses.
  • Experience Accumulation: Learning from past actions improves future decision-making and problem-solving capabilities.
  • Entity Understanding: Identifying and remembering key entities enhances the ability to process and interact with complex information.

The memory is set to<span>False</span>. We need to set<span>memory=True</span> in the<span>crew</span> function.

## crew.py

@crew
def crew(self) -> Crew:
    return Crew(
        agents=self.agents,
        tasks=self.tasks,
        process=Process.sequential,
        verbose=True,
        memory=True,
    )

We can also customize the types of memory to be used.

## crew.py

from crewai.memory.short_term.short_term_memory import ShortTermMemory
from crewai.memory.long_term.long_term_memory import LongTermMemory
from crewai.memory.entity.entity_memory import EntityMemory
from crewai.memory.storage.rag_storage import RAGStorage
from crewai.memory.storage.ltm_sqlite_storage import LTMSQLiteStorage


@crew
def crew(self) -> Crew:
    return Crew(
        agents=self.agents,
        tasks=self.tasks,
        process=Process.sequential,
        verbose=True,
        memory=True,
        long_term_memory=LongTermMemory(
            storage=LTMSQLiteStorage(
                db_path="long_term_memory_storage.db"
            )
        ),
        short_term_memory=ShortTermMemory(
            storage=RAGStorage(
                type="short_term",
                allow_reset=True,
                embedder_config={
                    "provider": "openai",  # Specify the provider explicitly
                    "config":{
                        "model": "text-embedding-ada-002",  # Specify the model
                        "api_key": "",
                    }
                },
                crew=self,  # Pass crew agents if needed
                path="short_term",
            ),
        ),
        entity_memory=EntityMemory(
            storage=RAGStorage(
                type="entities",
                allow_reset=True,
                embedder_config={
                    "provider": "openai",  # Specify the provider explicitly
                    "config":{
                        "model": "text-embedding-ada-002",  # Specify the model
                        "api_key": "sk-",
                    }
                },
                crew=self,  # Pass crew agents if needed
                path="entity",
            ),
        ),
    )

These components make up the memory system in Crew AI. Each component serves its specific purpose. To understand how they work and distinguish their roles, we should conduct case studies and projects to observe their internal operations. Their roles will be better understood later in this series.

Resources

https://docs.crewai.com/concepts/memory

https://www.youtube.com/watch?v=-hHplC_gcSE

https://www.youtube.com/watch?v=HGYrOxkLDnY

Unlocking CrewAI 6: Enhancing AI Intelligence with 5 Memory Modes
Visit 200+ LLM aggregation platforms: https://rifx.online
!!! Note: Please click the original link to view the links in the article

Leave a Comment