将记忆存储到数据库中

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)

相关推荐
Xzaveir36 分钟前
别把所有“认证”都塞进 AuthService:实名、一键登录与号码身份的领域拆分
android·人工智能
BerrySen1781 小时前
KMP全栈开发:从Android到AI Agent的技术演进与实践
android·人工智能
YM52e3 小时前
鸿蒙Flutter Center居中组件:Align对齐详解
android·学习·flutter·华为·harmonyos·鸿蒙
时间的拾荒人3 小时前
MySQL 视图详解
android·数据库·mysql
祉猷并茂,雯华若锦4 小时前
Appium 3.x安卓按键与通知栏操作全指南
android·appium
码农coding5 小时前
android 12 SurfaceFlinger开机启动分析
android
hunterandroid5 小时前
Paging 3 RemoteMediator 实战:构建离线优先的分页列表
android·前端
码农coding5 小时前
android12 开机启动PMS
android
Days20505 小时前
GPT-Image-2 国风美学人设生成提示词分享
android·gpt
浮江雾6 小时前
Flutter第十节-----Flutter布局与组件全解析
android·开发语言·前端·学习·flutter·入门