Conversation Memory v1.2
Overview
You can persist and load memory by using Conversation Memory Drivers. You can build drivers for your own data stores by extending BaseConversationMemoryDriver.
Conversation Memory Drivers
Gen AI Builder
The GriptapeCloudConversationMemoryDriver allows you to persist Conversation Memory in Gen AI Builder. It provides seamless integration with Gen AI Builder's cloud-based Threads and Messages resources.
import os from griptape.drivers.memory.conversation.griptape_cloud import GriptapeCloudConversationMemoryDriver from griptape.memory.structure import ConversationMemory from griptape.structures import Agent cloud_conversation_driver = GriptapeCloudConversationMemoryDriver( api_key=os.environ["GT_CLOUD_API_KEY"], alias="my_thread_alias", ) agent = Agent(conversation_memory=ConversationMemory(conversation_memory_driver=cloud_conversation_driver)) agent.run("My name is Jeff.") agent.run("What is my name?")
[02/27/25 20:26:45] INFO PromptTask 60d62b3fa90f4c299b286b793b9c972c
Input: My name is Jeff.
[02/27/25 20:26:47] INFO PromptTask 60d62b3fa90f4c299b286b793b9c972c
Output: Hello, Jeff! If there's anything you'd like
to discuss or any questions you have, feel free to
share. I'm here to help!
[02/27/25 20:26:49] INFO PromptTask 60d62b3fa90f4c299b286b793b9c972c
Input: What is my name?
[02/27/25 20:26:50] INFO PromptTask 60d62b3fa90f4c299b286b793b9c972c
Output: Your name is Jeff. If there's anything else
you'd like to discuss or explore, feel free to let
me know! Local
The LocalConversationMemoryDriver allows you to persist Conversation Memory in a local JSON file.
from griptape.drivers.memory.conversation.local import LocalConversationMemoryDriver from griptape.memory.structure import ConversationMemory from griptape.structures import Agent local_driver = LocalConversationMemoryDriver(persist_file="memory.json") agent = Agent(conversation_memory=ConversationMemory(conversation_memory_driver=local_driver)) agent.run("Surfing is my favorite sport.") agent.run("What is my favorite sport?")
[02/27/25 20:24:54] INFO PromptTask 77d41348dd384110b71f98a7efcbba54
Input: Surfing is my favorite sport.
[02/27/25 20:24:55] INFO PromptTask 77d41348dd384110b71f98a7efcbba54
Output: That's awesome! Surfing is a thrilling and
challenging sport that offers a great connection
with nature. Whether you're riding the waves for
fun or competing, it can be an exhilarating
experience. Do you have a favorite surfing spot or
any memorable surfing experiences you'd like to
share?
[02/27/25 20:24:56] INFO PromptTask 77d41348dd384110b71f98a7efcbba54
Input: What is my favorite sport?
[02/27/25 20:24:57] INFO PromptTask 77d41348dd384110b71f98a7efcbba54
Output: Your favorite sport is surfing! Amazon DynamoDb
Info
This driver requires the drivers-memory-conversation-amazon-dynamodb extra.
The AmazonDynamoDbConversationMemoryDriver allows you to persist Conversation Memory in Amazon DynamoDb.
import os import uuid from griptape.drivers.memory.conversation.amazon_dynamodb import AmazonDynamoDbConversationMemoryDriver from griptape.memory.structure import ConversationMemory from griptape.structures import Agent conversation_id = uuid.uuid4().hex dynamodb_driver = AmazonDynamoDbConversationMemoryDriver( table_name=os.environ["DYNAMODB_TABLE_NAME"], partition_key="id", value_attribute_key="memory", partition_key_value=conversation_id, ) agent = Agent(conversation_memory=ConversationMemory(conversation_memory_driver=dynamodb_driver)) agent.run("My name is Jeff.") agent.run("What is my name?")
[02/27/25 20:23:05] INFO PromptTask 34167b4190a94c23aa10895f75f400ec
Input: My name is Jeff.
[02/27/25 20:23:06] INFO PromptTask 34167b4190a94c23aa10895f75f400ec
Output: Hello, Jeff! How can I assist you today?
[02/27/25 20:23:07] INFO PromptTask 34167b4190a94c23aa10895f75f400ec
Input: What is my name?
[02/27/25 20:23:10] INFO PromptTask 34167b4190a94c23aa10895f75f400ec
Output: Your name is Jeff. Optional parameters sort_key and sort_key_value can be supplied for tables with a composite primary key.
Redis
Info
This driver requires the drivers-memory-conversation-redis extra.
The RedisConversationMemoryDriver allows you to persist Conversation Memory in Redis.
import os import uuid from griptape.drivers.memory.conversation.redis import RedisConversationMemoryDriver from griptape.memory.structure import ConversationMemory from griptape.structures import Agent conversation_id = uuid.uuid4().hex redis_conversation_driver = RedisConversationMemoryDriver( host=os.environ["REDIS_HOST"], port=int(os.environ["REDIS_PORT"]), username=os.environ["REDIS_USERNAME"], password=os.environ["REDIS_PASSWORD"], index=os.environ["REDIS_INDEX"], conversation_id=conversation_id, ) agent = Agent(conversation_memory=ConversationMemory(conversation_memory_driver=redis_conversation_driver)) agent.run("My name is Jeff.") agent.run("What is my name?")
[02/27/25 20:26:33] INFO PromptTask af6050aa04784fc8b95083c25f7fd573
Input: My name is Jeff.
[02/27/25 20:26:34] INFO PromptTask af6050aa04784fc8b95083c25f7fd573
Output: Hello, Jeff! How can I assist you today?
[02/27/25 20:26:35] INFO PromptTask af6050aa04784fc8b95083c25f7fd573
Input: What is my name?
[02/27/25 20:26:36] INFO PromptTask af6050aa04784fc8b95083c25f7fd573
Output: Your name is Jeff. - On this page
- Overview
- Conversation Memory Drivers