Long-term memory in Microsoft Agent Framework

Long-term memory in AI agents refers to the ability to retain information across multiple interactions and sessions. This is essential for creating a more personalized user experience, as it allows agents to recall user preferences, past conversations, and contextual information. The Microsoft Agent Framework employs a dual memory architecture that includes both short-term and long-term memory.

Memory Architecture

  1. Short-Term Memory: This component tracks ongoing interactions and is typically volatile, meaning it is cleared after the session ends. It allows the agent to respond to immediate queries and maintain a fluid conversation.
  2. Long-Term Memory: In contrast, long-term memory retains information across sessions, enabling the agent to remember details that can enhance future interactions. This memory is crucial for building a relationship with users, as it allows the agent to provide continuity and context in conversations.

Context Providers

In MAF, long-term memory is managed through ContextProviders. These components allow agents to access relevant past interactions, user preferences, and other contextual information. By leveraging ContextProviders, agents can provide more relevant responses based on historical data, making interactions feel more natural and engaging.

Integration with Databases

To effectively manage long-term memory, AI agents require a reliable storage solution. Databases play a critical role in this process. Popular databases such as Neo4j and Azure Cosmos DB are commonly used to store long-term memory.

  • Neo4j: This graph database allows for the storage of entities extracted from conversations. It enables the classification and linking of these entities back to the original messages, facilitating complex queries and relationships.
  • Azure Cosmos DB: This database offers a unified solution for memory systems, providing speed and scalability essential for AI agents. Its multi-model capabilities allow for the storage of various data types, making it a versatile choice for long-term memory management.

Real-World Use Cases

The integration of databases into the Microsoft Agent Framework opens up a plethora of possibilities for AI agents. Here are some real-world use cases that illustrate the benefits of long-term memory:

Personalized Recommendations

With long-term memory an AI agent can remember user preferences and past interactions to suggest tailored options. If a user frequently inquires about travel destinations, the agent can store this information and offer relevant suggestions in future conversations. This not only enhances user satisfaction but also fosters a sense of connection between the user and the agent.

Contextual Awareness

Long-term memory enables agents to maintain context over multiple sessions. For example, if a user mentions a specific project during one interaction, the agent can recall details about that project in subsequent conversations. This continuity enhances the overall user experience, as it allows for more meaningful and relevant interactions. Users are more likely to engage with an agent that remembers their interests and past discussions.

Supporting Data and Quotes

. According to a blog post on Neo4j, “Long-term memory consists of entities which can be automatically extracted from conversations using the LLM and classified with the POLE+O schema.” This highlights the need for a systematic approach to data storage that allows for easy retrieval and classification.

POLE+P schema is a framework used to analyze systems by breaking them into five interacting dimensions:

  • P)eople – Human actors
  • O)bjects – tangible or digital artifacts
  • L)ocation – spatial or contextual setting
  • E)vents – actions that trigger change
  • O)rganization – the structure or procedural layer that connects everything

In essence, this is the Who, What, Where, When and How.

A Microsoft Community Hub article states, “Long-term memory is typically shared across sessions,” emphasizing the necessity of a database that can persist data beyond individual interactions. This persistence is crucial for building a comprehensive understanding of user preferences and behaviors.

When an agent interacts with a user, it can save important information (like preferences or past conversations) in a database. The next time the user interacts with the agent, it can retrieve this information to provide a more personalized experience. This process is fundamental to creating a seamless and engaging interaction between users and AI agents.

Code Example

To illustrate how an AI agent might store and retrieve user preferences using a database, here’s a simple example in C#:

public class UserPreferences
{
    public string UserId { get; set; }
    public string Preference { get; set; }
}

public class MemoryDatabase
{
    private List<UserPreferences> preferencesStore = new List<UserPreferences>();

    public void SavePreference(string userId, string preference)
    {
        preferencesStore.Add(new UserPreferences { UserId = userId, Preference = preference });
    }

    public List<string> GetPreferences(string userId)
    {
        return preferencesStore.Where(p => p.UserId == userId).Select(p => p.Preference).ToList();
    }
}

// Usage
var memoryDb = new MemoryDatabase();
memoryDb.SavePreference("user123", "likes travel");
var userPreferences = memoryDb.GetPreferences("user123");

In this code snippet, we define a UserPreferences class to represent user preferences and a MemoryDatabase class to manage the storage and retrieval of these preferences. The SavePreference method allows the agent to store user preferences, while the GetPreferences method retrieves them for future interactions.

Conclusion

The integration of databases into the Microsoft Agent Framework is crucial for enabling long-term memory in AI agents. By leveraging structured data storage, agents can provide personalized and contextually aware interactions, significantly enhancing user experience. As AI technology continues to advance, the ability to remember and learn from past interactions will become increasingly important, making the role of databases in AI development more critical than ever. By understanding and implementing these concepts, developers can create more intelligent and responsive AI agents that truly understand and cater to user needs.

Unknown's avatar

About Jesse Liberty

** Note ** Jesse is currently looking for a new position. You can learn more about him at https://jesseliberty.bio Thank you. Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET, is now available wherever you buy your books. Liberty was a Team Lead and Senior Software Engineer for various corporations, a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a 13 year Microsoft MVP.
This entry was posted in AI. Bookmark the permalink.