Skip to content

Commit d69a54c

Browse files
committed
fix(checkpoint): streamline checkpointer creation to prioritize MemorySaver for in-memory paths
1 parent 65ac57d commit d69a54c

3 files changed

Lines changed: 27 additions & 24 deletions

File tree

BaseAgent/base_agent.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,21 +1028,22 @@ def _create_checkpointer(self):
10281028
warning if langgraph-checkpoint-sqlite is not installed and a file path
10291029
was requested.
10301030
"""
1031+
from langgraph.checkpoint.memory import MemorySaver
1032+
10311033
db_path = self.checkpoint_db_path
1034+
if db_path == ":memory:":
1035+
return MemorySaver()
10321036
if _HAS_SQLITE_SAVER:
10331037
import sqlite3
10341038
conn = sqlite3.connect(db_path, check_same_thread=False)
10351039
return SqliteSaver(conn)
1036-
else:
1037-
from langgraph.checkpoint.memory import MemorySaver
1038-
if db_path != ":memory:":
1039-
warnings.warn(
1040-
"langgraph-checkpoint-sqlite is not installed; falling back to "
1041-
"in-memory checkpointer. State will NOT persist across sessions. "
1042-
"Install with: pip install langgraph-checkpoint-sqlite",
1043-
stacklevel=3,
1044-
)
1045-
return MemorySaver()
1040+
warnings.warn(
1041+
"langgraph-checkpoint-sqlite is not installed; falling back to "
1042+
"in-memory checkpointer. State will NOT persist across sessions. "
1043+
"Install with: pip install langgraph-checkpoint-sqlite",
1044+
stacklevel=3,
1045+
)
1046+
return MemorySaver()
10461047

10471048
def close(self):
10481049
"""Release checkpointer resources (closes the SQLite connection if open)."""

BaseAgent/multi_agent/orchestrator.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,18 @@ def _route(self, state: MultiAgentState) -> str:
263263
# ------------------------------------------------------------------
264264

265265
def _create_checkpointer(self):
266+
from langgraph.checkpoint.memory import MemorySaver
267+
266268
db_path = default_config.checkpoint_db_path
267-
if _HAS_SQLITE_SAVER:
268-
return SqliteSaver.from_conn_string(db_path)
269-
else:
270-
from langgraph.checkpoint.memory import MemorySaver
271-
if db_path != ":memory:":
272-
warnings.warn(
273-
"langgraph-checkpoint-sqlite is not installed; falling back to "
274-
"in-memory checkpointer for AgentTeam.",
275-
stacklevel=3,
276-
)
269+
if db_path == ":memory:":
277270
return MemorySaver()
271+
if _HAS_SQLITE_SAVER:
272+
import sqlite3
273+
conn = sqlite3.connect(db_path, check_same_thread=False)
274+
return SqliteSaver(conn)
275+
warnings.warn(
276+
"langgraph-checkpoint-sqlite is not installed; falling back to "
277+
"in-memory checkpointer for AgentTeam.",
278+
stacklevel=3,
279+
)
280+
return MemorySaver()

BaseAgent/tests/test_checkpointing.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,12 @@ def test_returns_sqlite_saver_when_available(self, base_agent, tmp_path):
7979
cp = base_agent._create_checkpointer()
8080
assert isinstance(cp, SqliteSaver)
8181

82-
def test_memory_path_uses_in_memory_sqlite(self, base_agent):
83-
pytest.importorskip("langgraph.checkpoint.sqlite", reason="langgraph-checkpoint-sqlite not installed")
84-
from langgraph.checkpoint.sqlite import SqliteSaver
82+
def test_memory_path_uses_memory_saver(self, base_agent):
83+
from langgraph.checkpoint.memory import MemorySaver
8584

8685
base_agent.checkpoint_db_path = ":memory:"
8786
cp = base_agent._create_checkpointer()
88-
assert isinstance(cp, SqliteSaver)
87+
assert isinstance(cp, MemorySaver)
8988

9089
def test_fallback_warns_when_sqlite_missing_and_file_path(self, base_agent):
9190
"""When sqlite package absent AND a file path is given, a warning is emitted."""

0 commit comments

Comments
 (0)