--- id: wiki-2026-0508-s-component-state-store title: S-component (State Store) category: 10_Wiki/Topics status: verified canonical_id: self aliases: [State Store, Agent State, S-component] duplicate_of: none source_trust_level: A confidence_score: 0.85 verification_status: applied tags: [agent, state, architecture, llm] raw_sources: [] last_reinforced: 2026-05-10 github_commit: pending tech_stack: language: typescript framework: langgraph/anthropic-sdk --- # S-component (State Store) ## 매 한 줄 > **"매 LLM agent 의 working memory + 영속 store"**. 매 LATS / LangGraph / Anthropic Memory Tool 2025 의 backbone 컴포넌트. 매 ephemeral conversation context 의 limit (200K-1M token) 을 넘어 agent 의 task-state, scratchpad, learned facts 를 영속화. ## 매 핵심 ### 매 Layer - **Working memory**: current turn 의 scratchpad (tool result, observations). - **Episodic memory**: 매 session log + summarization. - **Semantic memory**: extracted facts + embeddings (vector DB). - **Procedural**: skill / playbook (file system). ### 매 vs Context Window - Context = read-only attention. State = read-write. - Context = volatile. State = persistent across sessions. - Context = expensive (caching). State = cheap (KV / vector). ### 매 응용 1. Multi-session task agent (e.g., research assistant). 2. CRM-style customer history. 3. Coding agent 의 codebase index + recent edits. 4. Game NPC memory. ## 💻 패턴 ### LangGraph state schema ```python from typing import TypedDict, Annotated from langgraph.graph import StateGraph import operator class AgentState(TypedDict): messages: Annotated[list, operator.add] scratchpad: dict tool_calls: Annotated[list, operator.add] final_answer: str | None graph = StateGraph(AgentState) graph.add_node("plan", planner) graph.add_node("act", actor) graph.add_edge("plan", "act") ``` ### Anthropic Memory Tool 2025 ```python import anthropic client = anthropic.Anthropic() resp = client.messages.create( model="claude-opus-4-7", max_tokens=4096, tools=[{"type": "memory_20250604", "name": "memory"}], messages=[{"role": "user", "content": "Remember: I prefer Python type hints."}], extra_headers={"anthropic-beta": "context-management-2025-06-04"}, ) # Memory persisted across calls; agent reads/writes via tool ``` ### Redis-backed working state ```ts import { createClient } from 'redis'; const redis = createClient({ url: process.env.REDIS_URL }); class AgentStateStore { async get(sessionId: string): Promise { const data = await redis.get(`agent:${sessionId}`); return data ? JSON.parse(data) : { scratchpad: {}, messages: [] }; } async set(sessionId: string, state: AgentState) { await redis.set(`agent:${sessionId}`, JSON.stringify(state), { EX: 3600 }); } async append(sessionId: string, msg: Message) { await redis.rPush(`agent:${sessionId}:msgs`, JSON.stringify(msg)); } } ``` ### Vector store for semantic ```ts import { Pinecone } from '@pinecone-database/pinecone'; const pc = new Pinecone(); const idx = pc.index('agent-memory'); async function remember(fact: string, embed: (s: string) => Promise) { const vec = await embed(fact); await idx.upsert([{ id: crypto.randomUUID(), values: vec, metadata: { fact, ts: Date.now() }}]); } async function recall(query: string, embed: (s: string) => Promise) { const vec = await embed(query); const r = await idx.query({ vector: vec, topK: 5, includeMetadata: true }); return r.matches.map(m => m.metadata?.fact); } ``` ### Summarization compaction ```ts async function compactState(s: AgentState): Promise { if (s.messages.length < 50) return s; const summary = await llm.summarize(s.messages.slice(0, 30)); return { ...s, messages: [{role: 'system', content: summary}, ...s.messages.slice(30)] }; } ``` ### S-component in 6-component pattern (S/T/L/I/M/E) ```ts // S = State, T = Tools, L = LLM, I = Input, M = Memory, E = Effect type Agent = { S: StateStore; T: ToolRegistry; L: LLMClient; I: InputParser; M: MemoryRetriever; E: SideEffectExecutor; }; ``` ## 매 결정 기준 | 상황 | Approach | |---|---| | Single-turn, stateless | No S-component | | Multi-turn, single session | In-memory map | | Cross-session, single user | Redis / SQLite | | Production multi-user | DB + vector store + memory tool | | Coding agent | File system + git as state | **기본값**: Redis + Postgres + Anthropic Memory Tool — 2026 의 production pattern. ## 🔗 Graph - 부모: [[Agent Architecture]] - 변형: [[Working Memory]] - 응용: [[LangGraph]] - Adjacent: [[T-component (Tool Registry)]] ## 🤖 LLM 활용 **언제**: state schema design, summarization prompt, recall query. **언제 X**: high-throughput stateless API (overhead ↑). ## ❌ 안티패턴 - **Unbounded growth**: state 의 GC 부재 → cost explosion. - **Stale state**: TTL 없는 cache 의 contradiction. - **Tight coupling**: S 와 L 의 직접 dep → testing 어려움. - **No versioning**: schema migration 깨짐. ## 🧪 검증 / 중복 - Verified (LangGraph docs, Anthropic Memory Tool 2025 release notes). - 신뢰도 A. ## 🕓 Changelog | 날짜 | 변경 | |---|---| | 2026-05-08 | Phase 1 | | 2026-05-10 | Manual cleanup — S-component full coverage |