1+ """
2+ Clear conversation history from PostgreSQL.
3+ Set mode below: delete a single thread or wipe all threads.
4+ """
15from langgraph .checkpoint .postgres import PostgresSaver
26from langgraph_react_with_database_memory_base .utils import get_database_uri
37
4- thread_id = "PLACEHOLDER FOR YOUR THREAD ID"
8+ # ============================================
9+ # SET YOUR THREAD ID HERE
10+ # Leave empty to delete ALL threads
11+ # ============================================
12+ thread_id = "YOUR_THREAD_ID"
513
6- # Get database URI from environment variables
714DB_URI = get_database_uri ()
815
9- # Delete the thread from the database
10- with PostgresSaver .from_conn_string (DB_URI ) as saver :
11- saver .delete_thread (thread_id )
16+ if thread_id :
17+ # Delete a single thread
18+ with PostgresSaver .from_conn_string (DB_URI ) as saver :
19+ saver .delete_thread (thread_id )
20+ print (f"Deleted thread: { thread_id } " )
1221
13- print (f"Successfully deleted conversation with id: { thread_id } " )
22+ else :
23+ # Delete all threads
24+ with PostgresSaver .from_conn_string (DB_URI ) as saver :
25+ count = 0
26+ seen = set ()
27+ for cp_tuple in saver .list (None ):
28+ tid = cp_tuple .config ["configurable" ]["thread_id" ]
29+ if tid not in seen :
30+ seen .add (tid )
31+
32+ for tid in seen :
33+ saver .delete_thread (tid )
34+ count += 1
35+ print (f" Deleted: { tid } " )
36+
37+ print (f"\n Deleted { count } thread(s)." )
0 commit comments