When I use PostgresSQL for memory, it seems that I have to do create_agent all the time since PostgresSQL is required to be wrapped with the with statement
i.e:
with PostgresSaver.from_conn_string(SUPABASE_DB_URL) as checkpointer:
agent = build_agent("gpt-4o-mini", checkpointer) thread_id = "user-123"
config = {"configurable": {"thread_id": "user-123"}}
print(invoke_agent(agent, thread_id, "What's the capital of the moon?"))
So does that mean every time I ask a follow up question, I’ll need to call build_agent again? There has to be a better way to do this (other than refactoring to a function) because won’t it be redundant and create memory issues?
# Create the context manager
_checkpointer_cm = PostgresSaver.from_conn_string(os.getenv("POSTGRES_URI"))
# Enter it once and keep the real PostgresSaver
checkpointer = _checkpointer_cm.__enter__()
checkpointer.setup() # once on startup
# ...
agent = create_agent("gpt-4o-mini", checkpointer=checkpointer)
Hmmm I read articles, study the codebases, help here on the forum solving problems, code… I dunno, I just like programming and Langchain specifically