Type something to search...
Mastering CrewAI: Chapter 6 — Memory Basics | by Okan Yenigün | Jan, 2025 | Medium

Mastering CrewAI: Chapter 6 — Memory Basics | by Okan Yenigün | Jan, 2025 | Medium

Memory Types in CrewAI

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

Previous Chapter:

This system comprises several key components:

  • Short-Term Memory: This component temporarily stores recent interactions and outcomes, allowing agents to recall relevant information during ongoing tasks. For instance, it helps maintain coherence in conversations by recalling what has just been discussed. Uses RAG.
  • Long-Term Memory: It serves as a repository for valuable insights and learnings from past interactions. It enables agents to build and refine their knowledge over time, improving decision-making processes based on historical data
  • Entity Memory: This type captures and organizes information about entities (such as people, places, and concepts) encountered during tasks. It facilitates a deeper understanding and relationship mapping among these entities. Uses RAG.
  • Contextual Memory: It integrates Short-Term, Long-Term, and Entity Memory to maintain the context of interactions. This ensures that agents can provide coherent 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:

  • Contextual Awareness: Maintaining context over a conversation or task sequence leads to more coherent and relevant responses.
  • Experience Accumulation: Learning from past actions improves future decision-making and problem-solving.
  • Entity Understanding: Recognizing and remembering key entities enhances the ability to process and interact with complex information.

Memory is set to False by default. We need to set memory=True in the crew 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 which memory that we will use.

## 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 form the memory system in the Crew AI. Each serves a specific purpose. To understand how they work and distinguish their roles, we should conduct example cases and projects to observe what happens under the hood. Later in this series, their roles will be better understood.

Read More

Sources

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

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

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

Related Posts

10 Creative Ways to Use ChatGPT Search The Web Feature

10 Creative Ways to Use ChatGPT Search The Web Feature

For example, prompts and outputs Did you know you can use the “search the web” feature of ChatGPT for many tasks other than your basic web search? For those who don't know, ChatGPT’s new

Read More
📚 10 Must-Learn Skills to Stay Ahead in AI and Tech 🚀

📚 10 Must-Learn Skills to Stay Ahead in AI and Tech 🚀

In an industry as dynamic as AI and tech, staying ahead means constantly upgrading your skills. Whether you’re aiming to dive deep into AI model performance, master data analysis, or transform trad

Read More
10 Powerful Perplexity AI Prompts to Automate Your Marketing Tasks

10 Powerful Perplexity AI Prompts to Automate Your Marketing Tasks

In today’s fast-paced digital world, marketers are always looking for smarter ways to streamline their efforts. Imagine having a personal assistant who can create audience profiles, suggest mar

Read More
10+ Top ChatGPT Prompts for UI/UX Designers

10+ Top ChatGPT Prompts for UI/UX Designers

AI technologies, such as machine learning, natural language processing, and data analytics, are redefining traditional design methodologies. From automating repetitive tasks to enabling personal

Read More
100 AI Tools to Finish Months of Work in Minutes

100 AI Tools to Finish Months of Work in Minutes

The rapid advancements in artificial intelligence (AI) have transformed how businesses operate, allowing people to complete tasks that once took weeks or months in mere minutes. From content creat

Read More
17 Mindblowing GitHub Repositories You Never Knew Existed

17 Mindblowing GitHub Repositories You Never Knew Existed

Github Hidden Gems!! Repositories To Bookmark Right Away Learning to code is relatively easy, but mastering the art of writing better code is much tougher. GitHub serves as a treasur

Read More