Skip to content

Commit d0ab01d

Browse files
committed
reverted changes to db connection
1 parent 41a4aa4 commit d0ab01d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

api/llm/agent.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import atexit
12
import os
23
from functools import lru_cache
34
from typing import List, Optional
@@ -13,15 +14,17 @@
1314
_agent_executor = None
1415

1516

16-
@lru_cache(maxsize=1)
17+
@lru_cache
1718
def get_checkpointer():
1819
DATABASE_URL = os.environ.get("DATABASE_URL")
1920
if not DATABASE_URL:
2021
raise RuntimeError("DATABASE_URL is not set. Point it to your Neon connection string.")
2122

22-
checkpointer = PostgresSaver.from_conn_string(DATABASE_URL)
23-
checkpointer.setup() # create tables on first run; no-op afterward
24-
return checkpointer
23+
cm = PostgresSaver.from_conn_string(DATABASE_URL)
24+
saver = cm.__enter__() # enter the context manager once
25+
atexit.register(lambda: cm.__exit__(None, None, None)) # clean shutdown
26+
saver.setup() # create tables on first run; no-op afterward
27+
return saver
2528

2629

2730
def get_agent():

0 commit comments

Comments
 (0)