OpenAGI: Introducing Long-Term Memory

OpenAGI: Introducing Long-Term Memory

Oct 9, 2024

Oct 9, 2024

In the rapidly evolving world of artificial intelligence, the ability for machines to not only process information but also remember and learn from past interactions is paramount. OpenAGI’s latest update introduces Long-Term Memory (LTM), a breakthrough that marks a significant step forward in developing intelligent, human-like agents. This innovative feature enhances the way agents interact, adapt, and grow, offering a new level of sophistication in AI-driven systems.

What is Long-Term Memory, and Why Does It Matter?

Long-Term Memory equips AI agents with the capability to store and recall information from previous interactions, much like human memory. This development is not just a new feature but a fundamental shift in how AI systems operate, enhancing both their performance and the user experience.

With LTM, OpenAGI agents can now:

  • Recall past interactions to provide continuity in conversations.

  • Learn and adapt based on user inputs over time.

  • Deliver contextually relevant responses by referencing previous conversations.

  • Improve their accuracy and efficiency with each successive interaction.

Key Features of Long-Term Memory

  1. Seamless Integration: Enabling LTM within OpenAGI is straightforward, requiring just a simple configuration update.

  2. Customizable Memory Storage: Users have control over how and where their agent’s memory is stored.

  3. Smart Retrieval: LTM employs semantic similarity to retrieve and apply relevant information from past experiences.

  4. Feedback-Driven Learning: Agents can incorporate user feedback to continuously enhance their performance.

  5. Privacy Controls: Memory management is user-friendly, allowing easy deletion or modification of stored information.

Implementing LTM in OpenAGI

The implementation of Long-Term Memory in OpenAGI is designed to be as simple as possible. Below is a sample code snippet that demonstrates how to enable and configure LTM within your agent:

  • Importing libraries and modules: This section imports necessary components for interacting with OpenAGI, handling memory, task planning, and using DuckDuckGo for web searches.


  • Setting API key: This line sets the OpenAI API key in the environment, allowing access to the OpenAI model.

os.environ['OPENAI_API_KEY']
  • Loading the OpenAI model: The OpenAI model is initialized by loading configuration data from the environment. This llm object will be used to process tasks.


  • Defining a web search worker: This creates a worker with the role of "Web Researcher" who will use DuckDuckGo to find information based on user queries.

web_searcher = Worker(role="Web Researcher",
                      instructions="""You are tasked with conducting web searches using DuckDuckGo.Find the most relevant and accurate information based on the user's query.""",
                      actions=[DuckDuckGoSearch]

  • Admin setup: Here, an Admin instance is created to manage task execution, using a task planner, long-term memory, and the loaded LLM (OpenAI model).

admin = Admin(
actions=[DuckDuckGoSearch]

  • Assigning workers: The web_searcher worker is assigned to the admin to handle web search tasks.

admin.assign_workers([web_searcher]
  • Prompting user input: The program prompts the user to enter a query, and creates a description based on that query.


  • Running the agent: The admin executes the task with the user’s query and description. The DuckDuckGoSearch worker is invoked to fetch relevant information.

  • Displaying results: The results of the search are printed in a formatted way to provide the user with the output.

With LTM activated, your agent will now retain knowledge from previous interactions and use that information to provide more relevant and intelligent responses.

Real-World Application: The Power of Memory in Action

Consider a real-world scenario where you’re building a music assistant that retrieves song lyrics for users. The agent’s ability to remember user preferences and previous interactions demonstrates the potential of LTM:

Initial query:

User: “Provide the lyrics of the song ‘Bohemian Rhapsody’ by Queen.”

Agent:

After pressing Enter we get the lyrics as the output and a message indicating that the Long Term Memory has been updated:

Subsequent query:

User: “Now give me the lyrics for ‘Radio Ga Ga.’”

Now, the agent looks for similar queries in the Long Term Memory and retrieves them:

In this example, the agent remembered the user’s prior interest in Queen, providing context-aware responses. This level of interaction is made possible by the integration of Long-Term Memory.

Customizing Your Agent’s Memory

One of the key advantages of OpenAGI’s LTM feature is its flexibility. Developers can fine-tune various parameters to customize their agent’s memory capabilities:

  • long_term: Boolean flag to enable or disable LTM.

  • ltm_threshold: Defines the semantic similarity threshold for retrieving memories (default: 0.7).

  • long_term_dir: Specifies the directory for memory storage.

Here’s an example of how to customize these parameters:

from openagi.memory import Memory
memory = Memory(
 long_term=True,
 ltm_threshold=0.8,
 long_term_dir="/path/to/custom/memory/storage"
)
admin = Admin(
 actions=[YourCustomTool]

This level of customization allows developers to optimize memory storage and retrieval, ensuring that agents operate efficiently in complex environments.

How LTM Enhances Decision-Making

The Long-Term Memory feature follows a systematic decision-making process. When a query is received, the agent checks its memory for similar past queries and follows these steps:

  1. If LTM is enabled, the agent searches for related memories.

  2. If a memory with a high similarity score is found and has no negative feedback, the agent uses that memory to respond.

  3. If feedback from a past interaction indicates a mistake, the agent adjusts its response accordingly.

  4. New interactions are stored in the LTM, along with feedback for future reference.

This feedback-driven approach ensures continuous learning and improvement.

Learning from Feedback

A significant strength of LTM lies in its ability to learn from user feedback. For instance, if a user provides negative feedback on a response, the agent stores this information and adjusts future interactions accordingly:

Why Long-Term Memory is a Game-Changer

The introduction of Long-Term Memory transforms OpenAGI into a more powerful and adaptive platform. Agents that can remember, learn, and improve over time are not only more useful but are essential in solving complex real-world problems. By incorporating LTM into your AI projects, you can create agents that offer smarter, contextually aware assistance.

Imagine an AI assistant that remembers your preferences, avoids repeating mistakes, and grows smarter with each interaction. This is the future of intelligent systems, and Long-Term Memory is a key step in that direction.

Get Started Today

Explore the capabilities of Long-Term Memory by visiting our GitHub repository. Whether you’re developing personal assistants or complex systems, LTM offers an exciting opportunity to enhance your agents’ intelligence and adaptability.

Elevate your AI projects with the power of Long-Term Memory in OpenAGI.