Building Agent Short-Term Memory with Redis
A Juejin tutorial proposes a layered memory architecture for stateless AI agents: in-process messages for one request, Redis for current-session context, and PostgreSQL or pgvector for cross-session memory. It provides Redis data-structure examples, a RedisMessageStore implementation using LangChain message mappings, an agent invocation loop, and production cautions covering TTLs, persistence, serialization, client configuration, and scaling.
The article provides an implementable pattern for preserving agent context across requests and multiple instances while separating short- and long-term memory responsibilities.
先说结论
大模型本身是无状态的。它不是"记性差",而是根本没有记忆——每次请求对它来说都是第一次见面。
所以我们说的 Agent Memory,本质上只解决一个问题:让一个无状态的模型,在多轮、多实例、长时间跨度的对话里表现得像"记得"。
我的分层方案很简单:
本轮内存 messages → Redis(短期记忆) → PostgreSQL / pgvector(长期记忆)
一次请求内 当前会话 跨会话、用户画像
一句话记住:Redis 管"这次聊到哪了",PostgreSQL 管"这个人是谁"。
#Redis#RedisMessageStore#LangChain#PostgreSQL#pgvector#Mem0#ioredis