在langchain0.2.14中,执行以下代码:
memory = SqliteSaver.from_conn_string(":memory:")
agent_executor = create_react_agent(model, tools, checkpointer=memory)
出现如下错误:
ValidationError: 1 validation error for CompiledStateGraph
checkpointer
instance of BaseCheckpointSaver expected (type=type_error.arbitrary_type; expected_arbitrary_type=BaseCheckpointSaver)
问题原因:
langchain新版本from_conn_string() 返回的是 _contextlib.GeneratorContextManager 对象,不是 BaseCheckpointSaver 对象。
解决方法:
import sqlite3
conn = sqlite3.connect(":memory:", check_same_thread=False)
memory = SqliteSaver(conn)
或者 :
with SqliteSaver.from_conn_string(":memory:") as memory:
# code goes here
参考:https://github.com/langchain-ai/langchain/issues/25137