-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckpointers.py
More file actions
29 lines (22 loc) · 880 Bytes
/
checkpointers.py
File metadata and controls
29 lines (22 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# checkpointers.py
from langgraph.checkpoint.postgres import PostgresSaver
from langgraph.checkpoint.memory import InMemorySaver
from psycopg import Connection
from typing import Union
# Import from config instead of main
from config import POSTGRESQL_DATABASE_URL
Checkpointer = Union[InMemorySaver, PostgresSaver]
def get_checkpointer(use_postgres: bool = True) -> Checkpointer:
"""
Returns a configured checkpointer instance.
Args:
use_postgres: If True, returns PostgresSaver; otherwise, returns InMemorySaver.
Returns:
Configured checkpointer.
"""
if not use_postgres:
return InMemorySaver()
conn = Connection.connect(conninfo=POSTGRESQL_DATABASE_URL, autocommit=True)
checkpointer = PostgresSaver(conn=conn)
checkpointer.setup() # Creates required tables if they don't exist
return checkpointer