@@ -68,58 +68,72 @@ with CouchbaseSaver.from_conn_info(
68
68
bucket_name = os.getenv(" CB_BUCKET" ) or " test" ,
69
69
scope_name = os.getenv(" CB_SCOPE" ) or " langgraph" ,
70
70
) as checkpointer:
71
- # Create the agent with checkpointing
72
- graph = create_react_agent(model, tools = tools, checkpointer = checkpointer)
73
-
74
- # Configure with a unique thread ID
75
- config = {" configurable" : {" thread_id" : " 1" }}
76
-
77
- # Run the agent
78
- res = graph.invoke({" messages" : [(" human" , " what's the weather in sf" )]}, config)
79
-
80
- # Retrieve checkpoints
81
- latest_checkpoint = checkpointer.get(config)
82
- latest_checkpoint_tuple = checkpointer.get_tuple(config)
83
- checkpoint_tuples = list (checkpointer.list(config))
84
-
85
- print (latest_checkpoint)
86
- print (latest_checkpoint_tuple)
87
- print (checkpoint_tuples)
71
+ # Create the agent with checkpointing
72
+ graph = create_react_agent(model, tools = tools, checkpointer = checkpointer)
73
+
74
+ # Configure with a unique thread ID
75
+ config = {" configurable" : {" thread_id" : " 1" }}
76
+
77
+ # Run the agent
78
+ res = graph.invoke({" messages" : [(" human" , " what's the weather in sf" )]}, config)
79
+
80
+ # Retrieve checkpoints
81
+ latest_checkpoint = checkpointer.get(config)
82
+ latest_checkpoint_tuple = checkpointer.get_tuple(config)
83
+ checkpoint_tuples = list (checkpointer.list(config))
84
+
85
+ print (latest_checkpoint)
86
+ print (latest_checkpoint_tuple)
87
+ print (checkpoint_tuples)
88
88
```
89
89
90
90
### Asynchronous Usage
91
91
92
92
``` python
93
93
import os
94
+ from acouchbase.cluster import Cluster as ACluster
95
+ from couchbase.auth import PasswordAuthenticator
96
+ from couchbase.options import ClusterOptions
94
97
from langgraph_checkpointer_couchbase import AsyncCouchbaseSaver
95
98
from langgraph.graph import create_react_agent
96
99
97
- async with AsyncCouchbaseSaver.from_conn_info(
98
- cb_conn_str = os.getenv(" CB_CLUSTER" ) or " couchbase://localhost" ,
99
- cb_username = os.getenv(" CB_USERNAME" ) or " Administrator" ,
100
- cb_password = os.getenv(" CB_PASSWORD" ) or " password" ,
101
- bucket_name = os.getenv(" CB_BUCKET" ) or " test" ,
102
- scope_name = os.getenv(" CB_SCOPE" ) or " langgraph" ,
100
+ auth = PasswordAuthenticator(
101
+ os.getenv(" CB_USERNAME" ) or " Administrator" ,
102
+ os.getenv(" CB_PASSWORD" ) or " password" ,
103
+ )
104
+ options = ClusterOptions(auth)
105
+ cluster = await ACluster.connect(os.getenv(" CB_CLUSTER" ) or " couchbase://localhost" , options)
106
+
107
+ bucket_name = os.getenv(" CB_BUCKET" ) or " test"
108
+ scope_name = os.getenv(" CB_SCOPE" ) or " langgraph"
109
+
110
+ async with AsyncCouchbaseSaver.from_cluster(
111
+ cluster = cluster,
112
+ bucket_name = bucket_name,
113
+ scope_name = scope_name,
103
114
) as checkpointer:
104
- # Create the agent with checkpointing
105
- graph = create_react_agent(model, tools = tools, checkpointer = checkpointer)
106
-
107
- # Configure with a unique thread ID
108
- config = {" configurable" : {" thread_id" : " 2" }}
109
-
110
- # Run the agent asynchronously
111
- res = await graph.ainvoke(
112
- {" messages" : [(" human" , " what's the weather in nyc" )]}, config
113
- )
114
-
115
- # Retrieve checkpoints asynchronously
116
- latest_checkpoint = await checkpointer.aget(config)
117
- latest_checkpoint_tuple = await checkpointer.aget_tuple(config)
118
- checkpoint_tuples = [c async for c in checkpointer.alist(config)]
119
-
120
- print (latest_checkpoint)
121
- print (latest_checkpoint_tuple)
122
- print (checkpoint_tuples)
115
+ # Create the agent with checkpointing
116
+ graph = create_react_agent(model, tools = tools, checkpointer = checkpointer)
117
+
118
+ # Configure with a unique thread ID
119
+ config = {" configurable" : {" thread_id" : " 2" }}
120
+
121
+ # Run the agent asynchronously
122
+ res = await graph.ainvoke(
123
+ {" messages" : [(" human" , " what's the weather in nyc" )]}, config
124
+ )
125
+
126
+ # Retrieve checkpoints asynchronously
127
+ latest_checkpoint = await checkpointer.aget(config)
128
+ latest_checkpoint_tuple = await checkpointer.aget_tuple(config)
129
+ checkpoint_tuples = [c async for c in checkpointer.alist(config)]
130
+
131
+ print (latest_checkpoint)
132
+ print (latest_checkpoint_tuple)
133
+ print (checkpoint_tuples)
134
+
135
+ # Close the cluster when done
136
+ await cluster.close()
123
137
```
124
138
125
139
## Configuration Options
0 commit comments