Skip to content

Commit 41a4aa4

Browse files
committed
fixed context manager for postgres
1 parent 55c6c1b commit 41a4aa4

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

api/llm/agent.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import atexit
21
import os
32
from functools import lru_cache
43
from typing import List, Optional
@@ -14,17 +13,15 @@
1413
_agent_executor = None
1514

1615

17-
@lru_cache
16+
@lru_cache(maxsize=1)
1817
def get_checkpointer():
1918
DATABASE_URL = os.environ.get("DATABASE_URL")
2019
if not DATABASE_URL:
2120
raise RuntimeError("DATABASE_URL is not set. Point it to your Neon connection string.")
2221

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
22+
checkpointer = PostgresSaver.from_conn_string(DATABASE_URL)
23+
checkpointer.setup() # create tables on first run; no-op afterward
24+
return checkpointer
2825

2926

3027
def get_agent():

0 commit comments

Comments
 (0)