File tree Expand file tree Collapse file tree 3 files changed +28
-4
lines changed
agents/chat_with_tools_agent
services/streamlits/pages Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -50,9 +50,16 @@ def __call__(self, inputs: dict):
5050
5151
5252class 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 :
Original file line number Diff line number Diff line change 99 StreamlitCallbackHandler ,
1010)
1111from langfuse .langchain import CallbackHandler
12+ from langgraph .checkpoint .memory import InMemorySaver
13+ from langgraph .store .memory import InMemoryStore
1214
1315from 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
297303def 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
You can’t perform that action at this time.
0 commit comments