| name | memory-arch |
| description | Design an agent memory system โ working memory, episodic memory, semantic memory, and procedural memory. Use when building agents that need to remember context across sessions, learn from interactions, or maintain persistent knowledge. Covers storage strategy, retrieval patterns, and context management. |
| argument-hint | [agent requiring persistence] |
| allowed-tools | ["Read","Write"] |
| model | inherit |
Memory Architecture
์์ด์ ํธ ๋ฉ๋ชจ๋ฆฌ ์์คํ
์ค๊ณ โ ๋จ๊ธฐ ์ปจํ
์คํธ, ์ฅ๊ธฐ ์ ์ฅ, ๊ฒ์ ์ ๋ต
Core Goal
- ๋จ์ผ ์คํ์ ์ปจํ
์คํธ ์๋์ฐ๋ฅผ ๋์ด ์คํ ๊ฐ ํ์ต๊ณผ ๊ธฐ์ต์ ์ ์งํ๋ ๋ฉ๋ชจ๋ฆฌ ์ํคํ
์ฒ ์ค๊ณํ์ฌ ์์ด์ ํธ์ ์งํ ๊ฐ๋ฅํ๊ฒ ํจ
- 4๊ฐ์ง ๋ฉ๋ชจ๋ฆฌ ์ ํ(Working, Episodic, Semantic, Procedural)์ ๊ฐ๊ฐ ์ ์ ํ ์ ์ฅ์์ ๋ฐฐ์นํ์ฌ ๊ฒ์ ํจ์จ์ฑ๊ณผ ๋น์ฉ์ ์ต์ ํ
- ์ ํ๋ ์ปจํ
์คํธ ์๋์ฐ ๋ด์์ ๊ฐ์ฅ ๊ด๋ จ์ฑ ๋์ ๋ฉ๋ชจ๋ฆฌ๋ง ์ฃผ์
ํ๋ ๊ฒ์ ๋ฐ ๋ญํน ์ ๋ต ์๋ฆฝ
Trigger Gate
Use This Skill When
- ์์ด์ ํธ๊ฐ ์ฌ๋ฌ ์คํ(์ธ์
)์์ ์ผ๊ด๋ ๋์์ ํด์ผ ํ๋ ๊ฒฝ์ฐ
- ์ฌ์ฉ์ ์ ํธ๋, ๊ณผ๊ฑฐ ์๋ด ๋ด์ฉ, ๋๋ ๋๋ฉ์ธ ์ง์์ ๊ธฐ์ตํด์ผ ํ๋ ์์ด์ ํธ
- ์์ด์ ํธ๊ฐ ๊ฐ ์ํธ์์ฉ์์ ํ์ตํ๊ณ ๊ฐ์ ๋์ด์ผ ํ๋ ๊ฒฝ์ฐ
Route to Other Skills When
- ๋ฉ๋ชจ๋ฆฌ๊ฐ ํ๋ผ์ดํ (์ฌ์ฉ โ ๊ฐ์ )์ ์ผ๋ถ์ธ ๊ฒฝ์ฐ โ strategy --focus growth-loop (๋ฐ์ดํฐ ๊ตฌ์กฐ ์ค๊ณ)
- ๋ฉํฐ ์์ด์ ํธ ๊ฐ ๋ฉ๋ชจ๋ฆฌ ๊ณต์ ํ์ โ orchestration (์์ด์ ํธ ๊ฐ ๋ฐ์ดํฐ ํ๋ฆ)
- 3-tier ์์คํ
์์ workers ๊ฐ ์ปจํ
์คํธ ์ ๋ฌ โ orchestration (Hierarchical pattern ํต์ ํ๋กํ ์ฝ)
- ๋ฉ๋ชจ๋ฆฌ ์ ์ฅ์์ ๋น์ฉ ๊ตฌ์กฐ ์ต์ ํ โ strategy --focus biz-model (์ธํ๋ผ ๋น์ฉ ๊ณ์ฐ)
Boundary Checks
- ๋จ์ผ ์คํ ๋ด์์๋ง ๋ฉ๋ชจ๋ฆฌ ํ์ (์ธ์
๊ฐ ํ์ต ์์) โ Working Memory๋ง ๊ตฌํ, ์ฅ๊ธฐ ์ ์ฅ์ ๋ถํ์
- ์ปจํ
์คํธ ์๋์ฐ๊ฐ ์ถฉ๋ถํ ํฌ๋ฉด (1M ์ด์) โ Vector DB ๋์ in-context learning์ผ๋ก ๋จ์ํ ๊ฐ๋ฅ
- ๋ฉ๋ชจ๋ฆฌ ์ ์ฅ์๊ฐ ํ๋ผ์ด๋น์ด ์๋๋ฉด (๊ณต์ ๋จ) โ ์ฌ์ฉ์ ๊ฒฉ๋ฆฌ ๋ก์ง ์ถ๊ฐ ํ์
๊ฐ๋
์์ด์ ํธ์ ์ง๋ฅ์ ๋ฉ๋ชจ๋ฆฌ์์ ๋์จ๋ค. ๋จ์ผ ์คํ์ ์ปจํ
์คํธ ์๋์ฐ๋ฅผ ๋์ด์, ์คํ ๊ฐ ํ์ต๊ณผ ๊ธฐ์ต์ ์ ์งํ๋ ๋ฉ๋ชจ๋ฆฌ ์ํคํ
์ฒ๊ฐ ์์ด์ ํธ์ ์งํ๋ฅผ ๊ฐ๋ฅํ๊ฒ ํ๋ค.
Instructions
You are designing a memory architecture for: $ARGUMENTS
Step 1 โ Memory Type Classification
| Memory Type | Scope | Storage | Example |
|---|
| Working Memory | Single execution | Context window | Current task instructions, user input |
| Episodic Memory | Across executions | File/DB | "Last time user X asked about Y, they preferred Z format" |
| Semantic Memory | Permanent knowledge | Embeddings/DB | Domain knowledge, best practices, TK entries |
| Procedural Memory | How-to knowledge | Instructions/Skills | Workflow patterns, prompt templates |
Step 2 โ What to Remember
For each agent interaction, decide:
Always Store:
- User preferences and corrections
- Successful output patterns
- Error cases and resolutions
- Key decisions and reasoning
Never Store:
- Sensitive personal data (unless explicitly needed)
- Temporary calculation artifacts
- Redundant information already in semantic memory
Step 3 โ Storage Architecture
Choose the storage layer:
| Approach | Best For | Complexity | Cost |
|---|
| File-based (Markdown) | Simple agents, personal use | Low | Free |
| Vector DB (Pinecone, Chroma) | Semantic search over large corpus | Medium | $$ |
| Structured DB (PostgreSQL) | Relational data, complex queries | Medium | $ |
| Hybrid (File + Vector) | Best retrieval + human-readable | High | $$ |
Step 4 โ Retrieval Strategy
Design how the agent finds relevant memories:
Retrieval Pipeline:
1. Extract query from current context
2. Search relevant memory stores:
- Recency: recent interactions first
- Relevance: semantic similarity
- Importance: priority-tagged memories
3. Rank and select top-K memories
4. Inject into context window (within budget)
Step 5 โ Memory Budget
Allocate context window for memory:
Total Context Window: [tokens]
โโโ System Prompt: [tokens] (fixed)
โโโ Memory Injection: [tokens] (variable)
โ โโโ User preferences: [tokens]
โ โโโ Relevant past interactions: [tokens]
โ โโโ Domain knowledge: [tokens]
โโโ Current Input: [tokens] (variable)
โโโ Output Reserve: [tokens] (fixed)
Rule: Memory injection should not exceed 30% of available context
Step 6 โ Memory Lifecycle
Define how memories age:
New Memory โ Active (immediate access)
โ after 30 days unused โ Archive (lower priority retrieval)
โ after 90 days unused โ Cold Storage (manual retrieval only)
โ contradicted by newer info โ Deprecated (flagged, not deleted)
Output
Present the memory architecture:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Agent: [name] โ
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Working โ Context window management โ
โ Episodic โ [storage choice] โ
โ Semantic โ [storage choice] โ
โ Proceduralโ Skills/Instructions โ
โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Retrieval: [strategy] โ
โ Budget: [X tokens for memory] โ
โ Lifecycle: [aging policy] โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Failure Handling
| ์คํจ ์ํฉ | ๊ฐ์ง | ๋์ |
|---|
| ๋ฉ๋ชจ๋ฆฌ ์ฃผ์
์ผ๋ก ์ธํ ์ปจํ
์คํธ ์ค๋ฒํ๋ก์ฐ | ์ปจํ
์คํธ ์๋์ฐ ์ด๊ณผ ๋๋ ์๋ต ์ง์ฐ | ๋ฉ๋ชจ๋ฆฌ ์์ฐ ์ถ์ (30% โ 20%), ๋ ์ค์ํ ๊ธฐ์ต ์ ๊ฑฐ, ๋๋ ๋ฉ๋ชจ๋ฆฌ ์์ฝ ์ถ๊ฐ |
| ๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ๊ด๋ จ์ฑ ์์ | "์ต์ ์ ๋ณด"๋ฅผ ์์ฒญํ๋๋ฐ 3๊ฐ์ ์ ๋ฉ๋ชจ๋ฆฌ ๋ฐํ | ๊ฒ์ ์๊ณ ๋ฆฌ์ฆ ๊ฐ์ : recency weighting ์ถ๊ฐ, ํค์๋ ํํฐ๋ง, ๋๋ ๋ช
์์ ์ฟผ๋ฆฌ ์์ฑ |
| ๋ฉ๋ชจ๋ฆฌ ๋ชจ์: ์ ์ ๋ณด๊ฐ ๊ธฐ์กด ์ ๋ณด์ ์ถฉ๋ | ์์ด์ ํธ๊ฐ "์ด์ ๊ณผ ๋ค๋ฅธ ๋ต๋ณ" โ ์ฌ์ฉ์ ํผ๋ | ๋ฉ๋ชจ๋ฆฌ ๋ฒ์ ๊ด๋ฆฌ ์์คํ
๋์
, ๋๋ ๋ชจ์ ๊ฐ์ง ์ ์ฌ์ฉ์์๊ฒ ํ์ธ ์์ฒญ |
| ๊ฐ์ธ์ ๋ณด ๋์: ๊ณต์ ๋ฉ๋ชจ๋ฆฌ์ ๋ฏผ๊ฐํ ๋ฐ์ดํฐ ์ ์ฅ๋จ | ํ ์ฌ์ฉ์์ ๋ฉ๋ชจ๋ฆฌ๊ฐ ๋ค๋ฅธ ์ฌ์ฉ์์๊ฒ ๋
ธ์ถ | ์ฆ์ ๊ฒฉ๋ฆฌ ๋ก์ง ์ถ๊ฐ (user_id ๊ธฐ๋ฐ ํํฐ๋ง), ๊ธฐ์กด ๋ฉ๋ชจ๋ฆฌ ๊ฐ์ฌ ๋ฐ ์ ์ |
Quality Gate
Examples
Good Example
์์ด์ ํธ: "๊ฐ์ธ ๋น์ (์ฌ์ฉ์๋ณ ์ฅ๊ธฐ ๋ฉ๋ชจ๋ฆฌ)"
[๋ฉ๋ชจ๋ฆฌ ๋ ์ด์ด]
1. Working Memory (์ปจํ
์คํธ ์๋์ฐ)
- ํ์ฌ ์์
๋ด์ฉ
- ํ์ฌ ๋ํ ์ปจํ
์คํธ
- ์ ์ฅ์: LLM ์ปจํ
์คํธ ์๋์ฐ (๊ณ ์ )
2. Episodic Memory (์ฌ์ฉ์ ์ํธ์์ฉ ๊ธฐ๋ก)
- "์ง๋์ฃผ ์์์ผ ํ์์์ CEO๊ฐ Q2 ๋ชฉํ ๋ณ๊ฒฝ ์ธ๊ธ"
- "๊ณ ๊ฐ X๊ฐ ํญ์ CSV ํ์ ์ ํธ"
- ์ ์ฅ์: PostgreSQL (user_id, timestamp ์ธ๋ฑ์ฑ)
3. Semantic Memory (๋๋ฉ์ธ ์ง์)
- ํ์ฌ ์กฐ์ง๋, ์ ํ ์ ๋ณด, ์ ์ฑ
- ๊ฒฝ์์ฌ ๋ถ์ ์๋ฃ
- ์ ์ฅ์: Vector DB (Pinecone, ์ ์ฌ๋ ๊ฒ์)
4. Procedural Memory (์ํฌํ๋ก์ฐ)
- "์๋ง ๋ง๊ฐ ํ๋ก์ธ์ค: [๋จ๊ณ 1, 2, 3]"
- ์์ฃผ ์ฐ๋ ํ
ํ๋ฆฟ, ์คํฌ๋ฆฝํธ
- ์ ์ฅ์: Markdown ํ์ผ (๋ฒ์ ๊ด๋ฆฌ)
[๊ฒ์ ์ ๋ต]
์ฌ์ฉ์ ์ง๋ฌธ: "CEO๊ฐ ๋ญ๋ผ๊ณ ํ๋๋ฐ?"
1. Episodic์์ user_id = 123, recent ์ ๋ ฌ๋ก "CEO ์ธ๊ธ" ์ฐพ๊ธฐ
2. ์ ์ฌ๋ ์์๋ก top-3 ๋ฐํ
3. ๊ฐ ๋ฉ๋ชจ๋ฆฌ์ ์ ๋ขฐ๋ ์ ์ (๋ฐ์ดํฐ ๋์ด, ์ ํ๋) ์ฒจ๋ถ
4. ๋ชจ์ ๊ฐ์ง ์ ์ฌ์ฉ์์๊ฒ "๋ค์ ์ค ์ด๋ค ๊ฒ? A/B" ํ์ธ
[๋ฉ๋ชจ๋ฆฌ ์์ฐ]
- ์ปจํ
์คํธ ์๋์ฐ: 200K ํ ํฐ
- Working Memory: 50K (ํ์ฌ ๋ํ)
- ๋ฉ๋ชจ๋ฆฌ ์ฃผ์
: 40K (30% ร 200K์์ ์ผ๋ถ๋ง)
- Episodic ์ต์ 3๊ฐ: 20K
- Semantic ๊ด๋ จ 2๊ฐ: 15K
- Procedural 1๊ฐ: 5K
[๋ผ์ดํ์ฌ์ดํด]
์ ์ํผ์๋ โ ํ์ฑ (์ฆ์ ๊ฒ์)
โ 30์ผ ๋ฏธ์ฌ์ฉ ํ โ ์์นด์ด๋ธ (๋ฎ์ ์ฐ์ ์์)
โ 90์ผ ๋ฏธ์ฌ์ฉ ํ โ ์ฝ๋ ์คํ ๋ฆฌ์ง (์๋ ์กฐํ ํ์)
โ ๋ชจ์ ๋ฐ์ โ deprecated (ํ๋๊ทธ๋ง, ์ญ์ ์ํจ)
Bad Example
๋ฐ์ฌ๋ก 1: ๋ชจ๋ ๋ฉ๋ชจ๋ฆฌ๊ฐ ํ ๊ณณ์
- ๋ชจ๋ ์ ๋ณด๋ฅผ Vector DB์๋ง ์ ์ฅ
- "CEO ์ธ๊ธ ์ฐพ๊ธฐ" โ ์์ฒ ๊ฐ ๋ฒกํฐ ์ ์ฌ๋ ๊ณ์ฐ โ ๋๋ฆผ
- ์๊ฐ์ ๊ฒ์ ํ์ํ์ง๋ง ๊ตฌํ ์ ๋จ
๋ฐ์ฌ๋ก 2: ๋ฉ๋ชจ๋ฆฌ ์์ฐ ๋ฌด์
- ๊ฒ์๋ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๋ค ์ฃผ์
: "200K ํ ํฐ ์ค 100K๊ฐ ๋ฉ๋ชจ๋ฆฌ"
- ์ฌ์ฉ์ ์๋ก์ด ์
๋ ฅ ๊ณต๊ฐ ๋ถ์กฑ
- ์๋ต ์ง์ฐ, ํ ํฐ ๋ญ๋น
๋ฐ์ฌ๋ก 3: ์ฌ์ฉ์ ๊ฒฉ๋ฆฌ ์์
- ๊ณต์ Vector DB์ ๋ชจ๋ ์ฌ์ฉ์์ Episodic ์ ์ฅ
- ๊ฒ์ ํํฐ๋ง ์ ํจ
- ์ฌ์ฉ์ A์ ๊ฐ์ธ ์ ๋ณด๊ฐ ์ฌ์ฉ์ B์๊ฒ ๋
ธ์ถ (์ฌ๊ฐํ ๋ฒ๊ทธ)
๋ฐ์ฌ๋ก 4: ๋ฉ๋ชจ๋ฆฌ ๋ชจ์ ๋ฏธํด๊ฒฐ
- ์ฌ์ฉ์๊ฐ "์ด์ ๊ณผ ๋ค๋ฅธ ๋ต๋ณ ์ฃผ๋ค?"
- ๋ฉ๋ชจ๋ฆฌ ์์คํ
์ด ์ด์ ๋ฐ์ดํฐ๋ฅผ ๋จผ์ ๋ฐํํ์
- "์ ๋ขฐํ ์ ์๋ ์์ด์ ํธ" โ ์ดํ
Further Reading
- LangChain Memory Documentation โ Memory pattern implementations
- Letta (formerly MemGPT) โ Long-term memory architecture for agents
Contextual Knowledge (auto-loaded)
๋ณด์กฐ ํ์ผ์ด ์กด์ฌํ ๋๋ง ์๋ ๋ก๋๋ฉ๋๋ค. ํ์ผ์ด ์์ผ๋ฉด ๊ฑด๋๋๋๋ค.
Good Example
!cat examples/good-01.md 2>/dev/null || echo ""
Bad Example
!cat examples/bad-01.md 2>/dev/null || echo ""
Domain Context
!cat context/domain.md 2>/dev/null || echo ""
Test Cases
!cat references/test-cases.md 2>/dev/null || echo ""
Troubleshooting
!cat references/troubleshooting.md 2>/dev/null || echo ""