将记忆存储到数据库中

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)

相关推荐
我就是妖怪8 小时前
KMP全栈开发:从Android到AI Agent的技术演进与实践
android·人工智能
心平气和量大福大9 小时前
android-实例-蒲公英-更新与安装-5-签名与生成APK
android·java·开发语言
阿pin10 小时前
Android随笔-Serializable与Parcelable
android·serializable·parcelable
天空之城--10 小时前
Android 事件分发机制深度解析——原理、源码与实战综合总结
android
阿pin11 小时前
Android随笔-AIDL
android·开发语言·aidl
2501_9160074712 小时前
Bundle ID 注册与管理 App ID 创建指南 命名规则 权限开关与删除注意事项
android·ios·小程序·https·uni-app·iphone·webview
雨白12 小时前
面向对象六大基本原则实战:从零重构支持引擎切换的网络框架
android·架构
张赐荣13 小时前
Android TalkBack 无障碍优化: 为控件自定义转子导航动作
android·microsoft
天空之城--15 小时前
Android Flutter行业动态与学习参考(2026年8月)
android·flutter
quantdash_cc16 小时前
基于 QuantDash 5 分钟 K 线的网格交易策略参数网格搜索寻优实战
android·开发语言·pandas·量化·quantdash