Using Memory
How to use memory to persist information across different conversations
Memory in ControlFlow allows agents to store and retrieve information across different conversations or workflow executions. This is particularly useful for maintaining context over time or sharing information between separate interactions.
Setup
In order to use memory, you’ll need to configure a memory provider. For this example, we’ll use the default Chroma provider. You’ll need to pip install chromadb
to install its dependencies.
Code
In this example, we’ll create a simple workflow that remembers a user’s favorite color across different conversations. For simplicity, we’ll demonstrate the memory by using two different flows, which represent two different threads.
Ordinarily, running the flows above would result in two separate — unconnected — conversations. The agent in the recall_color
flow would have no way of knowing about the information from the first flow, even though its the same agent, because the conversation histories are not shared.
However, because we gave the agent a memory module and instructions for how to use it, the agent will be able to recall the information from the first flow.
Run the first flow:
When we run the second flow, the agent correctly recalls the favorite color:
Key concepts
-
Memory creation: We create a
Memory
object with a unique key and instructions for its use. -
Assigning memory to agents: We assign the memory to an agent, allowing it to access and modify the stored information.
-
Using memory across flows: By using the same memory in different flows, we can access information across separate conversations.
This example demonstrates how ControlFlow’s memory feature allows information to persist across different workflow executions, enabling more context-aware and personalized interactions.