将记忆存储到数据库中

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])

相关推荐
俩个逗号。。7 小时前
Gradle 踩过的坑
android
土星碎冰机10 小时前
ai自学笔记(3.安卓篇,制作app
android·笔记·ai
随遇丿而安11 小时前
专题:Glide / Coil / Fresco,不是三种写法,而是三套图片加载思路
android
只可远观12 小时前
Android 自动埋点(页面打开 / 关闭 + 点击事件)完整方案
android·kotlin
私人珍藏库13 小时前
【Android】小小最新AI--千变万化扮演任何角色--沉浸式互动
android·app·工具·软件·多功能
zh_xuan13 小时前
Android MVI架构
android·mvi
测试开发-学习笔记14 小时前
Airtest+Poco快速上手
android·其他
李斯维14 小时前
Android Jetpack 简介:由来和演进
android·android studio·android jetpack
阿巴斯甜14 小时前
ARouter 的使用:
android
沐言人生14 小时前
ReactNative 源码分析9——Native View初始化
android·react native