Skip to main content
from praisonaiagents import Agent

agent = Agent(
    name="Memory Assistant",
    instructions="Remember user preferences across turns.",
    memory=True,
)
agent.start("Remember that I prefer concise bullet answers")
The user shares a preference; the agent stores it with Mem0-backed memory for later sessions.

Mem0 and PaisonAI Integration

pip install "praisonaiagents[memory]"
Mem0 is a tools to store, updated, delete and retrieve memories. https://github.com/mem0ai/mem0
Vector store backend choice matters. mem0’s MongoDB vector store has an upstream bug (mem0ai/mem0#3185) that causes searches to silently return empty. PraisonAI catches this specific TypeError and logs a warning, but recovery requires switching to Qdrant or Chroma as mem0’s vector store backend. If you need MongoDB itself, use PraisonAI’s built-in MongoDB Memory adapter instead — it is separate from mem0 and unaffected by this bug. See Memory Troubleshooting for the fix.

Quick Start

1

Install

pip install praisonaiagents[memory]
2

Create a memory-enabled agent

from praisonaiagents import Agent

agent = Agent(
    name="MemoryAgent",
    instructions="Remember user preferences across conversations.",
    memory=True,
)

agent.start("My favorite color is blue")
agent.start("What is my favorite color?")

Mem0 previously called EmbedChain

from mem0 import Memory
from praisonai_tools import BaseTool

class AddMemoryTool(BaseTool):
    name: str = "Add Memory Tool"
    description: str = ("This tool allows storing a new memory with user ID and optional metadata.\n"
                        "Example:\n"
                        "   - Input: text='I am working on improving my tennis skills. Suggest some online courses.', user_id='alice', metadata={'category': 'hobbies'}\n"
                        "   - Output: Memory added with summary 'Improving her tennis skills. Looking for online suggestions.'")

    def _run(self, text: str, user_id: str, metadata: dict = None):
        m = Memory()
        result = m.add(text, user_id=user_id, metadata=metadata)
        return result

class GetAllMemoriesTool(BaseTool):
    name: str = "Get All Memories Tool"
    description: str = ("This tool retrieves all stored memories.\n"
                        "Example:\n"
                        "   - Input: action='get_all'\n"
                        "   - Output: List of all stored memories.")

    def _run(self):
        m = Memory()
        result = m.get_all()
        return result

class SearchMemoryTool(BaseTool):
    name: str = "Search Memory Tool"
    description: str = ("This tool searches for specific memories based on a query and user ID.\n"
                        "Example:\n"
                        "   - Input: query='What are Alice's hobbies?', user_id='alice'\n"
                        "   - Output: Search results related to Alice's hobbies.")

    def _run(self, query: str, user_id: str):
        m = Memory()
        result = m.search(query=query, user_id=user_id)
        return result

class UpdateMemoryTool(BaseTool):
    name: str = "Update Memory Tool"
    description: str = ("This tool updates an existing memory by memory ID and new data.\n"
                        "Example:\n"
                        "   - Input: memory_id='cb032b42-0703-4b9c-954d-77c36abdd660', data='Likes to play tennis on weekends'\n"
                        "   - Output: Memory updated to 'Likes to play tennis on weekends.'")

    def _run(self, memory_id: str, data: str):
        m = Memory()
        result = m.update(memory_id=memory_id, data=data)
        return result

class MemoryHistoryTool(BaseTool):
    name: str = "Memory History Tool"
    description: str = ("This tool gets the history of changes made to a specific memory by memory ID.\n"
                        "Example:\n"
                        "   - Input: memory_id='cb032b42-0703-4b9c-954d-77c36abdd660'\n"
                        "   - Output: History of the specified memory.")

    def _run(self, memory_id: str):
        m = Memory()
        result = m.history(memory_id=memory_id)
        return result

Best Practices

Always pass the same user_id for the same user across sessions to retrieve their memories correctly.
Store memories at the end of a session to avoid storing intermediate or incorrect information.
Search existing memories before adding new ones to avoid duplicates.
Clean up outdated memories periodically to keep retrieval accurate over time.

Custom Tools

Build your own agent tools

Tools Overview

Browse PraisonAI tool documentation