
chat-agent-persistence
by eco2-team
๐ฑ ์ด์ฝ์์ฝ(Ecoยฒ) BE
SKILL.md
name: chat-agent-persistence description: Chat ์๋น์ค์ ์์ํ ๋ ์ด์ด ๊ฐ์ด๋. Checkpointer(๋ฉํฐํด ์ปจํ ์คํธ), Message Persistence(PostgreSQL), Redis Streams Consumer ์ํคํ ์ฒ ๋ฐ ํธ๋ฌ๋ธ์ํ . Use when: (1) chat.messages ํ ์ด๋ธ์ด ๋น์ด์์ ๋, (2) checkpointer ๊ด๋ จ ์๋ฌ ๋ฐ์ ์, (3) ๋ฉํฐํด ๋ํ ์ปจํ ์คํธ๊ฐ ์ ์ง๋์ง ์์ ๋, (4) Redis Streams consumer group ์ค์ ์.
Chat Agent Persistence Guide
Chat ์๋น์ค์ ๋ฐ์ดํฐ ์์ํ ๋ ์ด์ด (Checkpointer + Message Storage)
Architecture Overview
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Chat Persistence Architecture โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโ โ
โ โ chat-worker โ โ
โ โ (LangGraph) โ โ
โ โโโโโโโโฌโโโโโโโ โ
โ โ โ
โ โโโโโโดโโโโโ โ
โ โ โ โ
โ โผ โผ โ
โ Checkpointer Progress Events โ
โ (Multi-turn) (Stage updates) โ
โ โ โ โ
โ โ โ XADD โ
โ โผ โผ โ
โ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โ โ PostgreSQL โ โ Redis Streams โ โ
โ โcheckpoints โ โ chat:events:{0-3}โ โ
โ โโโโโโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโผโโโโโโโโโโโโโ โ
โ โ โ โ โ
โ โผ โผ โผ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โ โ eventrouter โ โchat-persist โ โ (other groups) โ โ
โ โ (group) โ โ (group) โ โ โ โ
โ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ โผ โผ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โevent-router โ โchat-consumer โ โ
โ โ (SSE fan) โ โ (DB write) โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโฌโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโ โ
โ โ PostgreSQL โ โ
โ โchat.messages โ โ
โ โโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Two Persistence Paths
| Path | Purpose | Component | Target |
|---|---|---|---|
| Checkpointer | ๋ฉํฐํด ์ปจํ ์คํธ (LangGraph state) | CachedPostgresSaver | checkpoints ํ ์ด๋ธ |
| Message Storage | ๋ํ ์ด๋ ฅ (user/assistant) | ChatPersistenceConsumer | chat.messages ํ ์ด๋ธ |
Quick Diagnosis
# 1. chat.messages ํ
์ด๋ธ ํ์ธ
kubectl exec -n postgres deploy/postgresql -- psql -U sesacthon -d ecoeco -c \
"SELECT COUNT(*) FROM chat.messages;"
# 2. Checkpointer ์ํ ํ์ธ (worker ๋ก๊ทธ)
kubectl logs -n chat deploy/chat-worker --tail=100 | grep -E "(CachedPostgresSaver|checkpointer|InMemory)"
# 3. Redis Streams consumer group ํ์ธ
kubectl exec -n redis rfr-streams-redis-0 -c redis -- redis-cli XINFO GROUPS chat:events:0
Common Issues
Issue 1: CachedPostgresSaver ์ด๊ธฐํ ์คํจ
์ฆ์: InMemory checkpointer created (Redis fallback disabled)
๋ก๊ทธ:
[WARNING] CachedPostgresSaver failed, falling back to Redis only:
object _AsyncGeneratorContextManager can't be used in 'await' expression
์์ธ: checkpointer.py:228์์ async context manager๋ฅผ await๋ก ํธ์ถ
์์ธ: See checkpointer.md
Issue 2: chat.messages ํ ์ด๋ธ ๋น์ด์์
์ฆ์: chat.conversations์ ๋ฐ์ดํฐ ์์ง๋ง chat.messages๋ 0๊ฑด
์ง๋จ:
# Consumer group ํ์ธ - "chat-persistence" ์์ผ๋ฉด ๋ฏธ๋ฐฐํฌ
kubectl exec -n redis rfr-streams-redis-0 -c redis -- redis-cli XINFO GROUPS chat:events:0
์์ธ: ChatPersistenceConsumer ๋ฏธ๋ฐฐํฌ
์์ธ: See message-consumer.md
Code Locations
| Component | Path |
|---|---|
| Checkpointer | apps/chat_worker/infrastructure/orchestration/langgraph/checkpointer.py |
| Dependencies | apps/chat_worker/setup/dependencies.py (Lines 641-678) |
| Consumer Entry | apps/chat/consumer.py |
| Consumer Infra | apps/chat/infrastructure/messaging/redis_streams_consumer.py |
| Consumer Adapter | apps/chat/presentation/consumer/redis_streams_adapter.py |
Reference Files
- Checkpointer ์์ธ: See checkpointer.md - Cache-Aside ํจํด, LangGraph API
- Message Consumer ์์ธ: See message-consumer.md - ๋ฐฐํฌ ๋ฐฉ๋ฒ, Consumer Group
- ํธ๋ฌ๋ธ์ํ
๋ฌธ์:
docs/troubleshooting/chat-messages-not-persisted.md - PostgreSQL ๋ถ์:
docs/reports/postgres-chat-data-analysis.md
ในใณใข
็ทๅในใณใข
ใชใใธใใชใฎๅ่ณชๆๆจใซๅบใฅใ่ฉไพก
SKILL.mdใใกใคใซใๅซใพใใฆใใ
ใฉใคใปใณในใ่จญๅฎใใใฆใใ
100ๆๅญไปฅไธใฎ่ชฌๆใใใ
GitHub Stars 100ไปฅไธ
3ใถๆไปฅๅ ใซๆดๆฐใใใ
10ๅไปฅไธใใฉใผใฏใใใฆใใ
ใชใผใใณIssueใ50ๆชๆบ
ใใญใฐใฉใใณใฐ่จ่ชใ่จญๅฎใใใฆใใ
1ใคไปฅไธใฎใฟใฐใ่จญๅฎใใใฆใใ
ใฌใใฅใผ
ใฌใใฅใผๆฉ่ฝใฏ่ฟๆฅๅ ฌ้ไบๅฎใงใ