将记忆存储到数据库中

from langchain.agents import create_agent

import pymysql

from langgraph.checkpoint.memory import InMemorySaver

from langgraph.checkpoint.mysql.pymysql import PyMySQLSaver

from init_llm import deepseek_llm

DB_URI="mysql+pymsql://root:Zyj@xx@43.11.11.88:3306/langchain_db?charset=utf8mb4"

with PyMySQLSaver.from_conn_string(DB_URI) as checkpointer:

checkpointer.setup()

agent = create_agent(

model=deepseek_llm,

tools=\[\],

checkpointer=checkpointer

)

config={"configurable": {"thread_id":"session01"}}

resp=agent.invoke({"messages":{"role":"user","content":"我叫张三,你是谁?""}},config=config)

print(resp'messages'-1)

resp=agent.invoke({"messages":{"role":"user","content":"请问我叫什么名字?""}},config=config)

print(resp'messages'-1)

相关推荐
Android系统攻城狮12 小时前
Linux Gstreamer深度解析之gst_audio_encoder_set_frame_max调用流程与实战(六十一)
android·linux·运维·音视频·gstreamer音视频·音视频进阶·gstreamer音视频进阶
传奇开心果编程15 小时前
【Compose Multiplatform 跨端开发学与练】第7课 平台适配与互操作
android·windows·学习·ui·ios·kotlin·composer
mmsx15 小时前
Android 地图数据链路:从 GDAL、KML 到多引擎适配
android·kotlin
2601_9689007715 小时前
大模型版本回归评估实战:从能力指标到额度口径的完整链路
android·数据挖掘·回归
ao-weilai18 小时前
MySQL数据库:基本查询
android·数据库·mysql
事圆则缓18 小时前
Kotlin 泛型方差实战:out、in、星投影与类型擦除
android·开发语言·kotlin
传奇开心果编程20 小时前
【Compose Multiplatform 跨端开发学与练】第5课 网络与数据层
android·网络·学习·ui·ios·kotlin·composer
ao-weilai21 小时前
MySQL数据库:内置函数
android·数据库·mysql
SWAGGY..21 小时前
【C++进阶】:(7)红黑树的原理与 C++ 实现:结构设计、插入调整及性质验证
android·java·开发语言·c++·算法
Android打工仔21 小时前
CoroutineScheduler 设计解析(上)—— 为什么 Dispatchers.IO 会创建更多线程?
android·kotlin·源码阅读