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] Use LTM #2026

Closed
omieee opened this issue Feb 4, 2025 · 5 comments · Fixed by #2049
Closed

[BUG] Use LTM #2026

omieee opened this issue Feb 4, 2025 · 5 comments · Fixed by #2049
Labels
bug Something isn't working

Comments

@omieee
Copy link

omieee commented Feb 4, 2025

Description

Based on Documentation i am trying to use

long_term_memory=EnhanceLongTermMemory(
        storage=LTMSQLiteStorage(
            db_path="/my_data_dir/my_crew1/long_term_memory_storage.db"
        )
    ),

But it doesn't look like it's working am i missing any import or something is off as these classes doesn't look exist.
Docs link: https://docs.crewai.com/concepts/memory

Steps to Reproduce

Follow steps from docs: https://docs.crewai.com/concepts/memory

Expected behavior

Should be able to save result into database

Screenshots/Code snippets

None

Operating System

Windows 11

Python Version

3.11

crewAI Version

0.100.0

crewAI Tools Version

latest

Virtual Environment

Venv

Evidence

none

Possible Solution

some class neds to be imported

Additional context

none

@omieee omieee added the bug Something isn't working label Feb 4, 2025
@jmrichardson
Copy link

Same issue! +1

devin-ai-integration bot added a commit that referenced this issue Feb 6, 2025
- Replace EnhanceLongTermMemory with LongTermMemory to match actual implementation
- Update code examples to show correct usage
- Fixes #2026

Co-Authored-By: Joe Moura <[email protected]>
Copy link
Contributor

This was a documentation issue where the docs showed EnhanceLongTermMemory class which doesn't exist. The correct class to use is LongTermMemory. I've submitted a PR to fix the documentation (#2049). In the meantime, you can use this code:

from crewai import Crew
from crewai.memory.long_term.long_term_memory import LongTermMemory
from crewai.memory.storage.ltm_sqlite_storage import LTMSQLiteStorage

crew = Crew(
    agents=[...],
    tasks=[...],
    memory=True,
    long_term_memory=LongTermMemory(
        storage=LTMSQLiteStorage(
            db_path='/my_data_dir/my_crew1/long_term_memory_storage.db'
        )
    )
)

Copy link
Contributor

This was a documentation issue where the docs showed EnhanceLongTermMemory class which doesn't exist. The correct class to use is LongTermMemory. I've submitted a PR to fix the documentation (#2049). In the meantime, you can use this code:

from crewai import Crew
from crewai.memory import LongTermMemory
from crewai.memory.storage import LTMSQLiteStorage

crew = Crew(
    agents=[...],
    tasks=[...],
    memory=True,
    long_term_memory=LongTermMemory(
        storage=LTMSQLiteStorage(
            db_path='/memory.db'
        )
    )
)

The PR includes additional improvements like proper type hints, security considerations, and configuration examples. All CI checks have passed and the PR is ready for review.

@jmrichardson
Copy link

Got imports working with this:

from crewai.memory import LongTermMemory
from crewai.memory.storage.ltm_sqlite_storage import LTMSQLiteStorage

    crew = Crew(
        agents=[agent],
        tasks=[task],
        process=Process.sequential,
        long_term_memory=LongTermMemory(
          storage=LTMSQLiteStorage(
            db_path='memory.db'
          )
        ),
        memory=True, # Enable memory for the crew - this activates short-term, long-term, entity, contextual memory
        verbose=True,
        llm=crew_llm # Explicitly set the Crew's LLM to ollama_llm
    )

Getting error:

Traceback (most recent call last):
  File "D:\Anaconda3\envs\freqtrade\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "D:\Anaconda3\envs\freqtrade\lib\asyncio\base_events.py", line 649, in run_until_complete
    return future.result()
  File "D:\Projects\NostalgiaForInfinity\user_data\agent_tune\create_doc_prompts.py", line 135, in main
    qa_output_text = await generate_qa_pairs(markdown_content, md_file, iteration, prompt_engineer_agent, ollama_llm) # Pass ollama_llm to generate_qa_pairs
  File "D:\Projects\NostalgiaForInfinity\user_data\agent_tune\create_doc_prompts.py", line 83, in generate_qa_pairs
    crew = Crew(
  File "D:\Anaconda3\envs\freqtrade\lib\site-packages\pydantic\main.py", line 214, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Crew
  Value error, Please provide an OpenAI API key. You can get one at https://platform.openai.com/account/api-keys [type=value_error, input_value={'agents': [Agent(role=Pr... at 0x000001682A961F00>}, input_type=dict]

joaomdmoura added a commit that referenced this issue Feb 9, 2025
* docs: fix long term memory class name in examples

- Replace EnhanceLongTermMemory with LongTermMemory to match actual implementation
- Update code examples to show correct usage
- Fixes #2026

Co-Authored-By: Joe Moura <[email protected]>

* docs: improve memory examples with imports, types and security

- Add proper import statements
- Add type hints for better readability
- Add descriptive comments for each memory type
- Add security considerations section
- Add configuration examples section
- Use environment variables for storage paths

Co-Authored-By: Joe Moura <[email protected]>

* Update memory.mdx

* Update memory.mdx

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Joe Moura <[email protected]>
Co-authored-by: João Moura <[email protected]>
devin-ai-integration bot added a commit that referenced this issue Feb 9, 2025
* docs: fix long term memory class name in examples

- Replace EnhanceLongTermMemory with LongTermMemory to match actual implementation
- Update code examples to show correct usage
- Fixes #2026

Co-Authored-By: Joe Moura <[email protected]>

* docs: improve memory examples with imports, types and security

- Add proper import statements
- Add type hints for better readability
- Add descriptive comments for each memory type
- Add security considerations section
- Add configuration examples section
- Use environment variables for storage paths

Co-Authored-By: Joe Moura <[email protected]>

* Update memory.mdx

* Update memory.mdx

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Joe Moura <[email protected]>
Co-authored-by: João Moura <[email protected]>
@ShifanaPalya
Copy link

ShifanaPalya commented Feb 12, 2025

`ImportError Traceback (most recent call last)
Input In [26], in <cell line: 1>()
----> 1 from crewai.memory.storage import LTMSQLiteStorage
2 from crewai.memory import LongTermMemory, ShortTermMemory, EntityMemory
3 # crew = Crew(
4 # agents=[support_agent, support_quality_assurance_agent],
5 # tasks=[inquiry_resolution, quality_assurance_review],
(...)
12 # ),
13 # )

ImportError: cannot import name 'LTMSQLiteStorage' from 'crewai.memory.storage' (unknown location)`

The documentation issue still persists.

Imports worked with:

from crewai.memory.storage.ltm_sqlite_storage import LTMSQLiteStorage

It has created long_term_memory.db file. However, it's giving memory and validation error and asking for openAI API key. Seems like it's trying to use OpenAI embeddings, but in the documentation it's mentioned that it uses SQLite3 to store task results. Am I missing something or doing something wrong?

Following is the error:

MEMORY ERROR: An error occurred during database initialization: unable to open database file

from crewai.memory.storage.ltm_sqlite_storage import LTMSQLiteStorage
2 from crewai.memory import LongTermMemory, ShortTermMemory, EntityMemory
----> 3 crew = Crew(
4 agents=[support_agent, support_quality_assurance_agent],
5 tasks=[inquiry_resolution, quality_assurance_review],
6 memory=True,
7 long_term_memory = LongTermMemory(
8 storage=LTMSQLiteStorage(
9 db_path="/long_term_memory_storage.db"
10 )
11 ),
12 )

tracebackhide tells pytest and some other tools to omit this function from tracebacks
213 tracebackhide = True
--> 214 validated_self = self.pydantic_validator.validate_python(data, self_instance=self)
215 if self is not validated_self:
216 warnings.warn(
217 'A custom validator is returning a value other than self.\n'
218 "Returning anything other than self from a top level model validator isn't supported when validating via __init__.\n"
219 'See the model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.',
...
221 )
ValidationError: 1 validation error for Crew
Value error, Please provide an OpenAI API key. You can get one at https://platform.openai.com/account/api-keys [type=value_error, input_value={'agents': [Agent(role=Se... at 0x000002044FE911B0>}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.10/v/value_error

I am using python 3.10.16 and crewai = 0.100.1

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

Successfully merging a pull request may close this issue.

3 participants