Skip to main content

LangGraph Checkpoint Couchbase

A Couchbase implementation of the LangGraph CheckpointSaver interface that enables persisting agent state and conversation history in a Couchbase database.

License: MIT

Overview

This package provides a seamless way to persist LangGraph agent states in Couchbase, enabling:

  • State persistence across application restarts
  • Retrieval of historical conversation steps
  • Continued conversations from previous checkpoints
  • Both synchronous and asynchronous interfaces

Installation

pip install langgraph-checkpointer-couchbase

Requirements

  • Python 3.8+
  • Couchbase Server (7.0+ recommended)
  • LangGraph 0.3.22+
  • LangChain OpenAI 0.3.11+

Prerequisites

  • A running Couchbase cluster
  • A bucket created for storing checkpoints
  • Appropriate credentials with read/write access

Quick Start

First, set up your agent tools and model:

from typing import Literal
from langchain_openai import ChatOpenAI

@tool
def get_weather(city: Literal["nyc", "sf"]):
    """Use this to get weather information."""
    if city == "nyc":
        return "It might be cloudy in nyc"
    elif city == "sf":
        return "It's always sunny in sf"
    else:
        raise AssertionError("Unknown city")


tools = [get_weather]
model = ChatOpenAI(model_name="gpt-4o-mini", temperature=0)

Synchronous Usage

import os
from langgraph_checkpointer_couchbase import CouchbaseSaver
from langgraph.graph import create_react_agent

with CouchbaseSaver.from_conn_info(
        cb_conn_str=os.getenv("CB_CLUSTER") or "couchbase://localhost",
        cb_username=os.getenv("CB_USERNAME") or "Administrator",
        cb_password=os.getenv("CB_PASSWORD") or "password",
        bucket_name=os.getenv("CB_BUCKET") or "test",
        scope_name=os.getenv("CB_SCOPE") or "langgraph",
    ) as checkpointer:
    # Create the agent with checkpointing
    graph = create_react_agent(model, tools=tools, checkpointer=checkpointer)
    
    # Configure with a unique thread ID
    config = {"configurable": {"thread_id": "1"}}
    
    # Run the agent
    res = graph.invoke({"messages": [("human", "what's the weather in sf")]}, config)
    
    # Retrieve checkpoints
    latest_checkpoint = checkpointer.get(config)
    latest_checkpoint_tuple = checkpointer.get_tuple(config)
    checkpoint_tuples = list(checkpointer.list(config))

    print(latest_checkpoint)
    print(latest_checkpoint_tuple)
    print(checkpoint_tuples)

Asynchronous Usage

import os
from acouchbase.cluster import Cluster as ACluster
from couchbase.auth import PasswordAuthenticator
from couchbase.options import ClusterOptions
from langgraph_checkpointer_couchbase import AsyncCouchbaseSaver
from langgraph.graph import create_react_agent

auth = PasswordAuthenticator(
    os.getenv("CB_USERNAME") or "Administrator",
    os.getenv("CB_PASSWORD") or "password",
)
options = ClusterOptions(auth)
cluster = await ACluster.connect(os.getenv("CB_CLUSTER") or "couchbase://localhost", options)

bucket_name = os.getenv("CB_BUCKET") or "test"
scope_name = os.getenv("CB_SCOPE") or "langgraph"

async with AsyncCouchbaseSaver.from_cluster(
        cluster=cluster,
        bucket_name=bucket_name,
        scope_name=scope_name,
    ) as checkpointer:
    # Create the agent with checkpointing
    graph = create_react_agent(model, tools=tools, checkpointer=checkpointer)
    
    # Configure with a unique thread ID
    config = {"configurable": {"thread_id": "2"}}
    
    # Run the agent asynchronously
    res = await graph.ainvoke(
        {"messages": [("human", "what's the weather in nyc")]}, config
    )

    # Retrieve checkpoints asynchronously
    latest_checkpoint = await checkpointer.aget(config)
    latest_checkpoint_tuple = await checkpointer.aget_tuple(config)
    checkpoint_tuples = [c async for c in checkpointer.alist(config)]

    print(latest_checkpoint)
    print(latest_checkpoint_tuple)
    print(checkpoint_tuples)

# Close the cluster when done
await cluster.close()

Configuration Options

Parameter Description Default
CB_CLUSTER Couchbase connection string couchbase://localhost
CB_USERNAME Username for Couchbase Administrator
CB_PASSWORD Password for Couchbase password
CB_BUCKET Bucket to store checkpoints test
CB_SCOPE Scope within bucket langgraph

Usage Data

This product automatically collects usage and performance data (such as product name and version) and browser information (such as IP address) (collectively, "Usage Data"). Couchbase uses Usage Data, along with other data you may provide to Couchbase (such as your user name or email address), to develop and improve our products as well as inform our sales and marketing programs. We do not access or collect any data you store in Couchbase products. We use Usage Data to understand aggregate usage patterns and make our products more useful to you. For more information on how Couchbase collects, protects, and processes information, please refer to the Couchbase Privacy Policy viewable at https://www.couchbase.com/privacy-policy.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📢 Support Policy

We truly appreciate your interest in this project!
This project is community-maintained, which means it's not officially supported by our support team.

If you need help, have found a bug, or want to contribute improvements, the best place to do that is right here — by opening a GitHub issue.
Our support portal is unable to assist with requests related to this project, so we kindly ask that all inquiries stay within GitHub.

Your collaboration helps us all move forward together — thank you!

Download files

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

Source Distribution

langgraph_checkpointer_couchbase-1.0.9.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file langgraph_checkpointer_couchbase-1.0.9.tar.gz.

File metadata

File hashes

Hashes for langgraph_checkpointer_couchbase-1.0.9.tar.gz
Algorithm Hash digest
SHA256 fa1cb6c6509951bfbc0c7f6dde77f0e2e462271bedda6d7af86f2de44fbeb5ce
MD5 dc6a2a7243f7000316630b5dec7fad28
BLAKE2b-256 2a875d709a96d285fcef973a7835fb687150ae4473b3b0c2cf34eb96873bdde7

See more details on using hashes here.

Provenance

The following attestation bundles were made for langgraph_checkpointer_couchbase-1.0.9.tar.gz:

Publisher: release.yaml on Couchbase-Ecosystem/langgraph-checkpointer-couchbase

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_checkpointer_couchbase-1.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for langgraph_checkpointer_couchbase-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 e47ba1716935d119af3d59accab080eb5c46405e70a1077b8013b3c88683eea4
MD5 5e9d07ceee3397afea07337a7782a4db
BLAKE2b-256 64eeb5db2d54f444577ab182a05846f0e996dfc2f7f2ecee8ae194a514fbf2a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for langgraph_checkpointer_couchbase-1.0.9-py3-none-any.whl:

Publisher: release.yaml on Couchbase-Ecosystem/langgraph-checkpointer-couchbase

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

Release history Release notifications | RSS feed

This release

1.0.9 This release

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page