Quickstart
Get started with MemFuse in minutes
Quickstart Guide
This guide will help you get started with MemFuse quickly, showing you how to add memory capabilities to your AI applications using our Python SDK.
Basic Usage Example
Here's a complete example demonstrating MemFuse integration with OpenAI:
Creating a Stateful Conversation
Setting Up
First, ensure you have MemFuse installed. If not, check the Installation guide.
Initialize LLM Client
Create a LLM client for your application. Note that MemFuse's memory contexts are flexible and optional:
Start a New Conversation
Create your first conversation by sending a message to your agent. MemFuse will automatically establish a persistent memory context.
Continue the Conversation with Context
MemFuse maintains conversation history by using the same session_id
from the memory
context. This allows the agent to reference earlier messages without you having to manage the context.
Customize Model Parameters and System Prompts
You can switch to a different model or add a system prompt at any point in the conversation. In this example, we add a system prompt that instructs the agent to respond like a cowboy.
Switch Between Different LLM Providers
MemFuse maintains conversation history regardless of which LLM provider you use. This lets you switch seamlessly between providers while maintaining context.
Understanding Memory Contexts
In MemFuse, a memory is fundamentally owned by a User and can exist within multiple optional contexts. The examples above demonstrate how to create memories with various contexts:
- User context: Specifying a
user
is mandatory, as it ensures that memories are associated with a specific user. - Agent context: When you specify an
agent
, memories become associated with a specific AI agent. If not specified,"agent_default"
is used. - Session context: When you specify a
session
, memories become tied to a specific conversation session. Messages and interactions within this active session constitute short-term memory. Memories from other sessions belonging to the same user are considered long-term memory, which is automatically retrieved and utilized by default. Developers have the option to disable long-term memory retrieval if needed for specific use cases.
While the user
context is always required, the agent
and session
contexts offer flexible scoping for memories. For example:
- Memories can be primarily scoped by
user
andagent
. This is useful when an agent needs to remember general information about a user, not specific to one conversation (session). - Memories can be scoped by
user
andsession
to capture a specific conversation. Anagent
(either specified or default) is also associated with this conversational memory. - All memories are tied to a
user
and can persist across differentsessions
(conversations). This enables long-term memory recall for the user, even for information from past conversations or interactions with different agents.
Accessing Memory Context Properties
The memory
object created earlier provides access to the context properties:
These identifiers can be useful for tracking, logging, or referencing specific conversations in your application. The stable IDs align with those used in the HTTP API and won't change even if the human-readable names are modified.
Next Steps
Now that you've learned the basics of using MemFuse, explore our detailed guides:
- Key Concepts - Understand the core ideas behind MemFuse.
- Simple Chat App with Memory - Build a basic chat application with memory.