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

[FEATURE] Support for custom path in RAGStorage #1659

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MahlerTom
Copy link

@MahlerTom MahlerTom commented Nov 26, 2024

Added support for custom path in RAGStorage as for feature request #1658

The support is also extended to the EntityMemory and ShortTermMemory classes that initialize RAGStorage.
Finally, I added path to LongTermMemory for completeness.

Here are the tests I did (note that Oliver Kane is an AI-generated persona that ChatGPT generated for me):

import os

from crewai import Agent, Crew, Task
from crewai.memory import (
    EntityMemory,
    LongTermMemory,
    ShortTermMemory,
)
from crewai.memory.storage.ltm_sqlite_storage import LTMSQLiteStorage
from crewai_tools import tool

LONG_TERM_MEMORY_PATH = os.path.normpath(
    os.path.join(os.getcwd(), "db/long_term_memory_storage.db"),
)
SHORT_TERM_MEMORY_PATH = os.path.normpath(
    os.path.join(os.getcwd(), "db/short_term_memory_storage"),
)
ENTITY_MEMORY_PATH = os.path.normpath(
    os.path.join(os.getcwd(), "db/entity_memory_storage"),
)

long_term_memory = LongTermMemory(
    storage=LTMSQLiteStorage(db_path=LONG_TERM_MEMORY_PATH)
)

short_term_memory = ShortTermMemory(
    path=SHORT_TERM_MEMORY_PATH,
)
entity_memory = EntityMemory(
    path=ENTITY_MEMORY_PATH,
)


@tool("person-tool")
def person_tool() -> str:
    """Get information on Person.

    Returns:
        str: The information on Person.
    """
    return """Name: Oliver Kane
Age: 34
Gender: Male
Occupation: Freelance Photographer
Location: Portland, Oregon, USA

Background:
Oliver grew up in a small town in Colorado and moved to Portland in his late 20s to explore the Pacific Northwest's natural beauty. He's a self-taught photographer who specializes in outdoor and wildlife photography, often working with eco-tourism companies and environmental organizations. He occasionally contributes to local magazines and blogs about his travel adventures.

Education: Bachelor's Degree in Environmental Science, University of Colorado Boulder.

Hobbies:

* Hiking and camping in national parks.
* Collecting vintage cameras.
* Brewing his own kombucha.
* Volunteering at a local animal shelter.

Personality Traits:
* Adventurous and curious, always looking for the next big story to capture through his lens.
* A bit of a perfectionist when it comes to his work but laid-back in his personal life.
* Loves striking up conversations with strangers, especially when traveling.

Goals:
* To publish a coffee table book featuring his favorite photos from around the world.
* To visit and photograph Antarctica within the next three years.
* To adopt a rescue dog when his schedule allows more stability."""


def main():
    agent = Agent(
        role="Learn Person Agent",
        goal="Save information on person to memory",
        backstory="You have a person_tool tool that provides information about a person. You use this tool to enrich your memory.",
        tools=[person_tool],
        llm="gpt-4o-mini",
    )

    task = Task(
        name="Learn about person",
        description="Learn about a person using your person_tool.",
        expected_output="Information about the person",
        agent=agent,
    )

    crew1 = Crew(
        tasks=[task],
        agents=[agent],
        memory=True,
        long_term_memory=long_term_memory,
        short_term_memory=short_term_memory,
        entity_memory=entity_memory,
    )

    crew1.kickoff()

    print("#" * 50)
    print("Done learning about person.")
    print("#" * 50)

    agent2 = Agent(
        role="Recall Person Agent",
        goal="Recall information on person from memory",
        backstory="You have a memory with information on a person, you need to recall information on that person.",
        llm="gpt-4o-mini",
    )

    task2 = Task(
        name="Get information on Oliver Kane",
        description="Look in your memory, What are the goals of Oliver Kane?",
        expected_output="Only the three goals of Oliver Kane if you know them, otherwise, say you don't know.",
        agent=agent2,
    )

    crew2 = Crew(
        tasks=[task2],
        agents=[agent2],
        memory=True,
        long_term_memory=long_term_memory,
        short_term_memory=short_term_memory,
        entity_memory=entity_memory,
    )

    crew2.kickoff()


if __name__ == "__main__":
    main()

First, I run the above test which creates the db in the designated path with the memory.
The expected output is the correct 3 goals of Oliver Kane.

Then, I run the above test a second time, commenting out the crew1.kickoff() so that it will not be able to learn from the second run.
The expected output is the correct 3 goals of Oliver Kane that was learned from the first run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant