11import asyncio
22from typing import Literal
3- from langchain_core .runnables import ConfigurableField
43from langchain_core .tools import tool
54from langchain_openai import ChatOpenAI
6- from langgraph . prebuilt import create_react_agent
5+ from langchain . agents import create_agent
76from langgraph_checkpointer_couchbase import CouchbaseSaver , AsyncCouchbaseSaver
87from dotenv import load_dotenv
98import os
9+
1010load_dotenv ()
1111
1212@tool
@@ -21,37 +21,49 @@ def get_weather(city: Literal["nyc", "sf"]):
2121
2222
2323tools = [get_weather ]
24- model = ChatOpenAI (model_name = "gpt-4o-mini" , temperature = 0 )
24+ model = ChatOpenAI (model = "gpt-5-mini" , temperature = 0 )
25+
2526
2627def syncTest ():
2728 with CouchbaseSaver .from_conn_info (
28- cb_conn_str = os .getenv ("CB_CLUSTER" ) or "couchbase://localhost" ,
29- cb_username = os .getenv ("CB_USERNAME" ) or "Administrator" ,
30- cb_password = os .getenv ("CB_PASSWORD" ) or "password" ,
31- bucket_name = os .getenv ("CB_BUCKET" ) or "test" ,
32- scope_name = os .getenv ("CB_SCOPE" ) or "langgraph" ,
29+ cb_conn_str = os .getenv ("CB_CLUSTER" ),
30+ cb_username = os .getenv ("CB_USERNAME" ),
31+ cb_password = os .getenv ("CB_PASSWORD" ),
32+ bucket_name = os .getenv ("CB_BUCKET" ),
33+ scope_name = os .getenv ("CB_SCOPE" ),
3334 ) as checkpointer :
34- graph = create_react_agent (model , tools = tools , checkpointer = checkpointer )
35+ graph = create_agent (
36+ model ,
37+ tools = tools ,
38+ checkpointer = checkpointer ,
39+ )
3540 config = {"configurable" : {"thread_id" : "1" }}
3641 res = graph .invoke ({"messages" : [("human" , "what's the weather in sf" )]}, config )
3742
3843 latest_checkpoint = checkpointer .get (config )
3944 latest_checkpoint_tuple = checkpointer .get_tuple (config )
4045 checkpoint_tuples = list (checkpointer .list (config ))
4146
42- print (latest_checkpoint )
43- print (latest_checkpoint_tuple )
44- print (checkpoint_tuples )
47+ print ("=== Sync Test Results ===" )
48+ print (f"Response: { res } " )
49+ print (f"Latest checkpoint: { latest_checkpoint } " )
50+ print (f"Latest checkpoint tuple: { latest_checkpoint_tuple } " )
51+ print (f"All checkpoint tuples: { checkpoint_tuples } " )
52+
4553
4654async def asyncTest ():
4755 async with AsyncCouchbaseSaver .from_conn_info (
48- cb_conn_str = os .getenv ("CB_CLUSTER" ) or "couchbase://localhost" ,
49- cb_username = os .getenv ("CB_USERNAME" ) or "Administrator" ,
50- cb_password = os .getenv ("CB_PASSWORD" ) or "password" ,
51- bucket_name = os .getenv ("CB_BUCKET" ) or "test" ,
52- scope_name = os .getenv ("CB_SCOPE" ) or "langgraph" ,
56+ cb_conn_str = os .getenv ("CB_CLUSTER" ),
57+ cb_username = os .getenv ("CB_USERNAME" ),
58+ cb_password = os .getenv ("CB_PASSWORD" ),
59+ bucket_name = os .getenv ("CB_BUCKET" ),
60+ scope_name = os .getenv ("CB_SCOPE" ),
5361 ) as checkpointer :
54- graph = create_react_agent (model , tools = tools , checkpointer = checkpointer )
62+ graph = create_agent (
63+ model ,
64+ tools = tools ,
65+ checkpointer = checkpointer ,
66+ )
5567 config = {"configurable" : {"thread_id" : "2" }}
5668 res = await graph .ainvoke (
5769 {"messages" : [("human" , "what's the weather in nyc" )]}, config
@@ -61,10 +73,16 @@ async def asyncTest():
6173 latest_checkpoint_tuple = await checkpointer .aget_tuple (config )
6274 checkpoint_tuples = [c async for c in checkpointer .alist (config )]
6375
64- print (latest_checkpoint )
65- print (latest_checkpoint_tuple )
66- print (checkpoint_tuples )
76+ print ("=== Async Test Results ===" )
77+ print (f"Response: { res } " )
78+ print (f"Latest checkpoint: { latest_checkpoint } " )
79+ print (f"Latest checkpoint tuple: { latest_checkpoint_tuple } " )
80+ print (f"All checkpoint tuples: { checkpoint_tuples } " )
81+
6782
6883if __name__ == "__main__" :
84+ print ("Running sync test..." )
6985 syncTest ()
70- asyncio .run (asyncTest ())
86+ print ("\n Running async test..." )
87+ asyncio .run (asyncTest ())
88+ print ("\n All tests completed!" )
0 commit comments