Skip to main content

DynamoDB Saver for LangGraph Checkpoints

Project description

langgraph-checkpoint-dynamodb

Implementation of a LangGraph CheckpointSaver that uses a AWS's DynamoDB

Inspiration

Based on: https://github.com/researchwiseai/langgraphjs-checkpoint-dynamodb

Required DynamoDB Tables

To be able to use this checkpointer, two DynamoDB table's are needed, one to store checkpoints and the other to store writes. Below are some examples of how you can create the required tables.

Terraform

# Variables for table names
variable "checkpoints_table_name" {
  type = string
}

variable "writes_table_name" {
  type = string
}

# Checkpoints Table
resource "aws_dynamodb_table" "checkpoints_table" {
  name         = var.checkpoints_table_name
  billing_mode = "PAY_PER_REQUEST"

  hash_key  = "thread_id"
  range_key = "checkpoint_id"

  attribute {
    name = "thread_id"
    type = "S"
  }

  attribute {
    name = "checkpoint_id"
    type = "S"
  }
}

# Writes Table
resource "aws_dynamodb_table" "writes_table" {
  name         = var.writes_table_name
  billing_mode = "PAY_PER_REQUEST"

  hash_key  = "thread_id_checkpoint_id_checkpoint_ns"
  range_key = "task_id_idx"

  attribute {
    name = "thread_id_checkpoint_id_checkpoint_ns"
    type = "S"
  }

  attribute {
    name = "task_id_idx"
    type = "S"
  }
}

AWS CDK

from aws_cdk import (
    Stack,
    aws_dynamodb as dynamodb,
)
from constructs import Construct

class DynamoDbStack(Stack):
    def __init__(self, scope: Construct, id: str, **kwargs):
        super().__init__(scope, id, **kwargs)

        checkpoints_table_name = 'YourCheckpointsTableName'
        writes_table_name = 'YourWritesTableName'

        # Checkpoints Table
        dynamodb.Table(
            self,
            'CheckpointsTable',
            table_name=checkpoints_table_name,
            billing_mode=dynamodb.BillingMode.PAY_PER_REQUEST,
            partition_key=dynamodb.Attribute(
                name='thread_id',
                type=dynamodb.AttributeType.STRING,
            ),
            sort_key=dynamodb.Attribute(
                name='checkpoint_id',
                type=dynamodb.AttributeType.STRING,
            ),
        )

        # Writes Table
        dynamodb.Table(
            self,
            'WritesTable',
            table_name=writes_table_name,
            billing_mode=dynamodb.BillingMode.PAY_PER_REQUEST,
            partition_key=dynamodb.Attribute(
                name='thread_id_checkpoint_id_checkpoint_ns',
                type=dynamodb.AttributeType.STRING,
            ),
            sort_key=dynamodb.Attribute(
                name='task_id_idx',
                type=dynamodb.AttributeType.STRING,
            ),
        )

Using the Checkpoint Saver

Default

To use the DynamoDB checkpoint saver, you only need to specify the names of the checkpoints and writes tables. In this scenario the DynamoDB client will be instantiated with the default configuration, great for running on AWS Lambda.

from langgraph_checkpoint_dynamodb import DynamoDBSaver
...
checkpoints_table_name = 'YourCheckpointsTableName'
writes_table_name = 'YourWritesTableName'

memory = DynamoDBSaver(
    checkpoints_table_name=checkpoints_table_name,
    writes_table_name=writes_table_name,
)

graph = workflow.compile(checkpointer=memory)

Providing Client Configuration

If you need to provide custom configuration to the DynamoDB client, you can pass in an object with the configuration options. Below is an example of how you can provide custom configuration.

memory = DynamoDBSaver(
    checkpoints_table_name=checkpoints_table_name,
    writes_table_name=writes_table_name,
    client_config={
        'region': 'us-west-2',
        'accessKeyId': 'your-access-key-id',
        'secretAccessKey': 'your-secret-access-key',
    }
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langgraph_checkpoint_dynamodb-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langgraph_checkpoint_dynamodb-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file langgraph_checkpoint_dynamodb-0.1.0.tar.gz.

File metadata

File hashes

Hashes for langgraph_checkpoint_dynamodb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7135d6ee58b1388421a0ef17c6659f031d1d42e1a33b3a5907b8deebe781e1d7
MD5 4f44a9db071e0af4c4d281c5e4cd63bb
BLAKE2b-256 0758400d36651e29726a9d552b8d09d73baf70a48f70d86dab64894a28d927ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for langgraph_checkpoint_dynamodb-0.1.0.tar.gz:

Publisher: publish.yml on justinram11/langgraph-checkpoint-dynamodb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langgraph_checkpoint_dynamodb-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langgraph_checkpoint_dynamodb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5992954728862b2a4b2f9947c989cedc9e945c526b9f6ecf42eb21f787fc6ce2
MD5 05bbccbf1690be6d4784a92eabcfe9e1
BLAKE2b-256 c9f354da77f0242523c1908481bcd99134cb413cdab63b933c7c214c5cb1fbea

See more details on using hashes here.

Provenance

The following attestation bundles were made for langgraph_checkpoint_dynamodb-0.1.0-py3-none-any.whl:

Publisher: publish.yml on justinram11/langgraph-checkpoint-dynamodb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page