Replies: 1 comment
-
To implement persistent memory using a database and file system for from langchain_community.chat_message_histories import SQLChatMessageHistory
from langgraph.prebuilt import create_react_agent
from langchain.schema import HumanMessage
# Initialize with a file-based SQLite database
memory = SQLChatMessageHistory(
session_id="test_session_id",
connection_string="sqlite:///sqlite.db"
)
# Create the react agent with persistent memory
react_agent = create_react_agent(
model=self.llm_with_tools,
tools=self.tools,
messages_modifier=self.prompt_str,
checkpointer=memory,
debug=True
)
# Define inputs and configuration
inputs = {"messages": [HumanMessage(content=self.contexto["input"])], "chat_history": "", "agent_scratchpad": ""}
config = {"configurable": {"thread_id": "1"}}
# Invoke the agent
result = await react_agent.ainvoke(inputs, config=config, debug=True) In this example:
This setup ensures that the agent's state is saved persistently across sessions [1][2][3]. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Checked other resources
Commit to Help
Example Code
Description
@dosu, How do I implement persistent memory (database and file system) to create_react_agent?
System Info
langchain==0.2.6
langchain-community==0.2.6
langchain-core==0.2.10
langchain-experimental==0.0.62
langchain-openai==0.1.13
langchain-qdrant==0.1.0
langchain-text-splitters==0.2.1
langchainhub==0.1.20
Beta Was this translation helpful? Give feedback.
All reactions