Skip to content

Commit ea2d4af

Browse files
committed
support SQLite checkpointer
1 parent 1c8cbbc commit ea2d4af

File tree

5 files changed

+59
-5
lines changed

5 files changed

+59
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,5 @@ generated/
168168
*.db
169169
*.wav
170170
mlartifacts
171+
*.sqlite
172+
*.bin

docs/references.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- [Add and manage memory](https://docs.langchain.com/oss/python/langgraph/add-memory)
2121
- [Persistence](https://langchain-ai.github.io/langgraph/concepts/persistence/)
2222
- [Chatbot with message summarization & external DB memory](https://github.com/langchain-ai/langchain-academy/blob/main/module-2/chatbot-external-memory.ipynb)
23+
- [LangGraph の会話履歴を SQLite に保持しよう](https://www.creationline.com/tech-blog/chatgpt-ai/75797)
2324

2425
### LangChain
2526

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies = [
2727
"langchain-text-splitters>=0.3.9",
2828
"langfuse>=3.6.2",
2929
"langgraph>=0.6.2",
30+
"langgraph-checkpoint-sqlite>=2.0.11",
3031
"langgraph-supervisor>=0.0.29",
3132
"mlflow>=3.4.0",
3233
"openai-whisper>=20250625",

template_langgraph/services/streamlits/pages/chat_with_tools_agent.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
2+
import sqlite3
23
import tempfile
4+
import uuid
35
from base64 import b64encode
46
from dataclasses import dataclass
57

@@ -9,8 +11,8 @@
911
StreamlitCallbackHandler,
1012
)
1113
from langfuse.langchain import CallbackHandler
12-
from langgraph.checkpoint.memory import InMemorySaver
13-
from langgraph.store.memory import InMemoryStore
14+
from langgraph.checkpoint.sqlite import SqliteSaver
15+
from langgraph.store.sqlite import SqliteStore
1416

1517
from template_langgraph.agents.chat_with_tools_agent.agent import (
1618
AgentState,
@@ -20,6 +22,10 @@
2022
from template_langgraph.speeches.tts import TtsWrapper
2123
from template_langgraph.tools.common import get_default_tools
2224

25+
checkpoints_conn = sqlite3.connect("checkpoints.sqlite", check_same_thread=False)
26+
store_conn = sqlite3.connect("store.sqlite", check_same_thread=False)
27+
thread_id = str(uuid.uuid4())
28+
2329

2430
def image_to_base64(image_bytes: bytes) -> str:
2531
return b64encode(image_bytes).decode("utf-8")
@@ -72,8 +78,12 @@ def ensure_agent_graph(selected_tools: list) -> None:
7278
if "graph" not in st.session_state or graph_signature != signature:
7379
st.session_state["graph"] = ChatWithToolsAgent(
7480
tools=selected_tools,
75-
checkpointer=InMemorySaver(), # You can replace this with a persistent checkpointer if needed
76-
store=InMemoryStore(), # You can replace this with a persistent store if needed
81+
checkpointer=SqliteSaver(
82+
conn=checkpoints_conn,
83+
),
84+
store=SqliteStore(
85+
conn=store_conn,
86+
),
7787
).create_graph()
7888
st.session_state["graph_tools_signature"] = signature
7989

@@ -311,7 +321,7 @@ def invoke_agent(graph_messages: list) -> AgentState:
311321
CallbackHandler(),
312322
],
313323
"configurable": {
314-
"thread_id": "1",
324+
"thread_id": thread_id,
315325
"user_id": "user_1",
316326
},
317327
},

uv.lock

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)