将记忆存储到数据库中

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)

相关推荐
limuyang232 分钟前
PDF Viewer KMP(基于 chrome 的 PDFium 内核)
android·kotlin
心平气和量大福大4 小时前
android-控件-搜索框SearchView
android·gitee
2601_962177134 小时前
【MySQL篇】聚合查询,联合查询
android·java·mysql
壮哥_icon4 小时前
【Android】批量 VectorDrawable 动态分别修改 fillColor 和 strokeColor 的踩坑与终极解决方案
android
齐天qaq6 小时前
Android 系统 APK 分区与权限
android
心平气和量大福大6 小时前
android-控件-多选框CheckBox
android·gitee
pengyu8 小时前
【Kotlin 协程修仙录 · 大乘境 · 初阶】 | 跳出三界:协程在 KMP 与后端开发中的跨平台之道
android·kotlin
XiaoLeisj8 小时前
Android Memory Profiler:堆内存指标、内存抖动与泄漏定位
android·性能优化·内存抖动·内存泄露·memory profiler
未来猫咪花8 小时前
Everything is ViewModel:让状态管理回到对象世界
android·flutter·ios