Skip to content

Commit 1c8cbbc

Browse files
committed
support store/checkpoint feature
1 parent 80366f6 commit 1c8cbbc

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

docs/references.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
- [Custom UI for Deep Agents](https://github.com/langchain-ai/deep-agents-ui)
1818
- [How to deploy self-hosted standalone server](https://docs.langchain.com/langgraph-platform/deploy-standalone-server)
1919
- [「現場で活用するための AI エージェント実践入門」リポジトリ](https://github.com/masamasa59/genai-agent-advanced-book)
20+
- [Add and manage memory](https://docs.langchain.com/oss/python/langgraph/add-memory)
21+
- [Persistence](https://langchain-ai.github.io/langgraph/concepts/persistence/)
22+
- [Chatbot with message summarization & external DB memory](https://github.com/langchain-ai/langchain-academy/blob/main/module-2/chatbot-external-memory.ipynb)
2023

2124
### LangChain
2225

template_langgraph/agents/chat_with_tools_agent/agent.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,16 @@ def __call__(self, inputs: dict):
5050

5151

5252
class ChatWithToolsAgent:
53-
def __init__(self, tools=get_default_tools()):
53+
def __init__(
54+
self,
55+
tools=get_default_tools(),
56+
checkpointer=None,
57+
store=None,
58+
):
5459
self.llm = AzureOpenAiWrapper().chat_model
5560
self.tools = tools
61+
self.checkpointer = checkpointer
62+
self.store = store
5663

5764
def create_graph(self):
5865
"""Create the main graph for the agent."""
@@ -83,6 +90,8 @@ def create_graph(self):
8390
# Compile the graph
8491
return workflow.compile(
8592
name=ChatWithToolsAgent.__name__,
93+
checkpointer=self.checkpointer,
94+
store=self.store,
8695
)
8796

8897
def chat_with_tools(self, state: AgentState) -> AgentState:

template_langgraph/services/streamlits/pages/chat_with_tools_agent.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
StreamlitCallbackHandler,
1010
)
1111
from langfuse.langchain import CallbackHandler
12+
from langgraph.checkpoint.memory import InMemorySaver
13+
from langgraph.store.memory import InMemoryStore
1214

1315
from template_langgraph.agents.chat_with_tools_agent.agent import (
1416
AgentState,
@@ -68,7 +70,11 @@ def ensure_agent_graph(selected_tools: list) -> None:
6870
signature = tuple(tool.name for tool in selected_tools)
6971
graph_signature = st.session_state.get("graph_tools_signature")
7072
if "graph" not in st.session_state or graph_signature != signature:
71-
st.session_state["graph"] = ChatWithToolsAgent(tools=selected_tools).create_graph()
73+
st.session_state["graph"] = ChatWithToolsAgent(
74+
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
77+
).create_graph()
7278
st.session_state["graph_tools_signature"] = signature
7379

7480

@@ -296,12 +302,18 @@ def build_graph_messages() -> list:
296302

297303
def invoke_agent(graph_messages: list) -> AgentState:
298304
return st.session_state["graph"].invoke(
299-
{"messages": graph_messages},
305+
{
306+
"messages": graph_messages,
307+
},
300308
{
301309
"callbacks": [
302310
StreamlitCallbackHandler(st.container()),
303311
CallbackHandler(),
304-
]
312+
],
313+
"configurable": {
314+
"thread_id": "1",
315+
"user_id": "user_1",
316+
},
305317
},
306318
)
307319

0 commit comments

Comments
 (0)