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

[BUG] Save method not working for Memories #1453

Open
Dev-Khant opened this issue Oct 16, 2024 · 2 comments
Open

[BUG] Save method not working for Memories #1453

Dev-Khant opened this issue Oct 16, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@Dev-Khant
Copy link
Contributor

Description

I was trying to use memory but found out that save function is not being called.

Steps to Reproduce

import os
from crewai import Agent, Task, Crew, Process

os.environ["OPENAI_API_KEY"] = "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"

# Define your agents
researcher = Agent(
    role="Researcher",
    goal="Conduct thorough research and analysis on AI and AI agents",
    backstory="You're an expert researcher, specialized in technology, software engineering, AI, and startups. You work as a freelancer and are currently researching for a new client.",
    allow_delegation=False,
    memory=True,
)

writer = Agent(
    role="Senior Writer",
    goal="Create compelling content about AI and AI agents",
    backstory="You're a senior writer, specialized in technology, software engineering, AI, and startups. You work as a freelancer and are currently writing content for a new client.",
    allow_delegation=False,
    memory=True,
)

# Define your task
task = Task(
    description="Generate a list of 5 interesting ideas for an article, then write one captivating paragraph for each idea that showcases the potential of a full article on this topic. Return the list of ideas with their paragraphs and your notes.",
    expected_output="5 bullet points, each with a paragraph and accompanying notes.",
)

# Define the manager agent
manager = Agent(
    role="Project Manager",
    goal="Efficiently manage the crew and ensure high-quality task completion",
    backstory="You're an experienced project manager, skilled in overseeing complex projects and guiding teams to success. Your role is to coordinate the efforts of the crew members, ensuring that each task is completed on time and to the highest standard.",
    allow_delegation=True,
    memory=True,
)

# Instantiate your crew with a custom manager
crew = Crew(
    agents=[researcher, writer],
    tasks=[task],
    manager_agent=manager,
    process=Process.hierarchical,
    memory=True,
)

# Start the crew's work
result = crew.kickoff()

Expected behavior

Here the save function of each memory i.e ShortTermMemory, LongTermMemory, EntityMemory should be called.

Screenshots/Code snippets

I tried printing every function of the memory class but it can be seen that no save call is being made. Only search is done and it empty results and nothing is being added.

Screenshot 2024-10-16 at 12 44 42 PM

Operating System

macOS Sonoma

Python Version

3.10

crewAI Version

0.51.1

crewAI Tools Version

0.8.3

Virtual Environment

Venv

Evidence

Screenshot 2024-10-16 at 12 50 14 PM

Possible Solution

Save function needs to be called properly.

Additional context

Nothing much

@Dev-Khant Dev-Khant added the bug Something isn't working label Oct 16, 2024
@theCyberTech
Copy link
Collaborator

Please upgrade to latest version 0.70.1 and see if it still occurs as your versions are quite far behind now

@Dev-Khant
Copy link
Contributor Author

Hey @theCyberTech I tried with latest version and I'm facing with chromadb now.

ValueError                                Traceback (most recent call last)
File ~/Desktop/crewAI/src/crewai/memory/storage/rag_storage.py:59, in RAGStorage._initialize_app(self)
     [58](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/src/crewai/memory/storage/rag_storage.py:58) try:
---> [59](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/src/crewai/memory/storage/rag_storage.py:59)     self.collection = self.app.get_collection(
     [60](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/src/crewai/memory/storage/rag_storage.py:60)         name=self.type, embedding_function=self.embedder_config
     [61](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/src/crewai/memory/storage/rag_storage.py:61)     )
     [62](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/src/crewai/memory/storage/rag_storage.py:62) except Exception:

File ~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/api/client.py:218, in Client.get_collection(self, name, id, embedding_function, data_loader)
    [208](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/api/client.py:208) @override
    [209](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/api/client.py:209) def get_collection(
    [210](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/api/client.py:210)     self,
   (...)
    [216](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/api/client.py:216)     data_loader: Optional[DataLoader[Loadable]] = None,
    [217](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/api/client.py:217) ) -> Collection:
--> [218](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/api/client.py:218)     return self._server.get_collection(
    [219](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/api/client.py:219)         id=id,
    [220](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/api/client.py:220)         name=name,
    [221](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/api/client.py:221)         embedding_function=embedding_function,
    [222](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/api/client.py:222)         data_loader=data_loader,
    [223](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/api/client.py:223)         tenant=self.tenant,
    [224](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/api/client.py:224)         database=self.database,
    [225](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/api/client.py:225)     )
...
   (...)
    [235](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/db/mixins/sysdb.py:235)     database=database,
    [236](https://file+.vscode-resource.vscode-cdn.net/Users/devkhant/Desktop/crewAI/~/Desktop/crewAI/.venv/lib/python3.12/site-packages/chromadb/db/mixins/sysdb.py:236) )

UniqueConstraintError: Collection short_term already exists

Seems issue is with get_collection so it's switching to creating new one. Here: https:/crewAIInc/crewAI/blob/main/src/crewai/memory/storage/rag_storage.py#L56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants