Skip to content

Conversation Memory Drivers

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

Local

The LocalConversationMemoryDriver allows you to persist Conversation Memory in a local JSON file.

from griptape.structures import Agent
from griptape.drivers import LocalConversationMemoryDriver
from griptape.memory.structure import ConversationMemory

local_driver = LocalConversationMemoryDriver(file_path="memory.json")
agent = Agent(conversation_memory=ConversationMemory(driver=local_driver))

agent.run("Surfing is my favorite sport.")
agent.run("What is my favorite sport?")

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 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(driver=dynamodb_driver))

agent.run("My name is Jeff.")
agent.run("What is my name?")

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 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=os.environ["REDIS_PORT"],
    password=os.environ["REDIS_PASSWORD"],
    index=os.environ["REDIS_INDEX"],
    conversation_id = conversation_id
)

agent = Agent(conversation_memory=ConversationMemory(driver=redis_conversation_driver))

agent.run("My name is Jeff.")
agent.run("What is my name?")