get_session_context
Retrieve previous session context including memory, knowledge graphs, and recent work history to quickly understand project status when starting new conversations.
Instructions
π [μ λν/μΈμ μμ μ μλ μ€ν κΆμ₯] μ΄μ μΈμ μ λ©λͺ¨λ¦¬, μ§μ κ·Έλν, μ΅κ·Ό μμ λ΄μμ ν λ²μ μ‘°νν©λλ€.
μ΄ λꡬλ μλ‘μ΄ λνλ₯Ό μμν λ κ°μ₯ λ¨Όμ μ€ννλ©΄ μ’μ΅λλ€. νλ‘μ νΈμ 컨ν μ€νΈλ₯Ό λΉ λ₯΄κ² νμ ν μ μμ΅λλ€.
ν€μλ: μΈμ μμ, 컨ν μ€νΈ, μ΄μ μμ , session start, context, previous work, what did we do
μ¬μ© μμ:
"μ΄μ μ λ¬΄μ¨ μμ νμμ§?"
"νλ‘μ νΈ μ»¨ν μ€νΈ μλ €μ€"
"μΈμ 컨ν μ€νΈ μ‘°ν"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectName | No | νλ‘μ νΈλͺ μΌλ‘ νν°λ§ (μ ν) | |
| category | No | μΉ΄ν κ³ λ¦¬λ‘ νν°λ§ (μ ν) | |
| memoryLimit | No | μ‘°νν λ©λͺ¨λ¦¬ μ (κΈ°λ³Έκ°: 15) | |
| includeGraph | No | μ§μ κ·Έλν ν¬ν¨ μ¬λΆ (κΈ°λ³Έκ°: true) | |
| includeTimeline | No | νμλΌμΈ ν¬ν¨ μ¬λΆ (κΈ°λ³Έκ°: true) | |
| timeRange | No | νμλΌμΈ μ‘°ν λ²μ | 7d |
Implementation Reference
- Main handler function that fetches and formats session context including memory stats, recent memories, knowledge graph summary, and recent timeline using MemoryManager. Handles optional filters like projectName, category, limits.export async function getSessionContext(args: GetSessionContextArgs): Promise<ToolResult> { try { const { projectName, category, memoryLimit = 15, includeGraph = true, includeTimeline = true, timeRange = '7d' } = args; const memoryManager = MemoryManager.getInstance(); const sections: string[] = []; // Header sections.push('# π§ μΈμ 컨ν μ€νΈ\n'); sections.push(`> μ΄μ μΈμ μ λ©λͺ¨λ¦¬μ μμ λ΄μμ λλ€.\n`); // 1. Memory Statistics const stats = memoryManager.getStats(); sections.push('## π λ©λͺ¨λ¦¬ ν΅κ³\n'); sections.push(`- **μ΄ λ©λͺ¨λ¦¬**: ${stats.total}κ°`); const categoryStats = Object.entries(stats.byCategory) .sort((a, b) => b[1] - a[1]) .slice(0, 5) .map(([cat, count]) => `${cat}: ${count}`) .join(', '); sections.push(`- **μΉ΄ν κ³ λ¦¬**: ${categoryStats || 'μμ'}\n`); // 2. Recent Memories (Priority-sorted) sections.push('## π μ£Όμ λ©λͺ¨λ¦¬\n'); let memories = memoryManager.list(category); // Filter by project name if specified if (projectName) { memories = memories.filter(m => m.key.toLowerCase().includes(projectName.toLowerCase()) || m.value.toLowerCase().includes(projectName.toLowerCase()) || m.category.toLowerCase().includes(projectName.toLowerCase()) ); } // Sort by priority (desc) then timestamp (desc) memories.sort((a, b) => { const priorityDiff = (b.priority || 0) - (a.priority || 0); if (priorityDiff !== 0) return priorityDiff; return new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime(); }); const topMemories = memories.slice(0, memoryLimit); if (topMemories.length === 0) { sections.push('_μ μ₯λ λ©λͺ¨λ¦¬κ° μμ΅λλ€._\n'); } else { for (const memory of topMemories) { const priority = memory.priority ? `β${memory.priority}` : ''; const preview = memory.value.length > 120 ? memory.value.substring(0, 120) + '...' : memory.value; const date = formatDate(memory.timestamp); sections.push(`### ${memory.key} ${priority}`); sections.push(`**[${memory.category}]** | ${date}`); sections.push(`> ${preview}\n`); } } // 3. Knowledge Graph (if enabled and has relations) if (includeGraph && memories.length > 0) { const graph = memoryManager.getMemoryGraph(undefined, 2); if (graph.edges.length > 0) { sections.push('## π μ§μ κ·Έλν\n'); // Show key relationships const relationSummary = summarizeRelations(graph.edges); sections.push(relationSummary); // Show clusters if (graph.clusters.length > 0) { sections.push('\n**κ΄λ ¨ κ·Έλ£Ή**:'); for (const cluster of graph.clusters.slice(0, 3)) { sections.push(`- [${cluster.join(' β ')}]`); } } sections.push(''); } } // 4. Recent Timeline (if enabled) if (includeTimeline) { sections.push('## π μ΅κ·Ό νμλΌμΈ\n'); const startDate = getStartDate(timeRange); const timeline = memoryManager.getTimeline(startDate, undefined, 10); if (timeline.length === 0) { sections.push('_μ΅κ·Ό νλμ΄ μμ΅λλ€._\n'); } else { const groupedByDate = groupByDate(timeline); for (const [date, items] of Object.entries(groupedByDate).slice(0, 5)) { sections.push(`**${date}**`); for (const item of (items as any[]).slice(0, 3)) { sections.push(`- \`${item.key}\`: ${item.value.substring(0, 50)}${item.value.length > 50 ? '...' : ''}`); } } sections.push(''); } } // 5. Quick Actions Hint sections.push('---'); sections.push('## π‘ λ€μ λ¨κ³\n'); sections.push('- νΉμ λ©λͺ¨λ¦¬ μμΈ μ‘°ν: `recall_memory`'); sections.push('- μ λ©λͺ¨λ¦¬ μ μ₯: `save_memory`'); sections.push('- κ·Έλν νμ: `get_memory_graph`'); sections.push('- κ³ κΈ κ²μ: `search_memories_advanced`'); return { content: [{ type: 'text', text: sections.join('\n') }] }; } catch (error) { return { content: [{ type: 'text', text: `β μΈμ 컨ν μ€νΈ μ‘°ν μ€λ₯: ${error instanceof Error ? error.message : 'μ μ μλ μ€λ₯'}` }] }; } }
- ToolDefinition object defining the input schema, description, and annotations for the get_session_context tool.export const getSessionContextDefinition: ToolDefinition = { name: 'get_session_context', description: `π [μ λν/μΈμ μμ μ μλ μ€ν κΆμ₯] μ΄μ μΈμ μ λ©λͺ¨λ¦¬, μ§μ κ·Έλν, μ΅κ·Ό μμ λ΄μμ ν λ²μ μ‘°νν©λλ€. μ΄ λꡬλ μλ‘μ΄ λνλ₯Ό μμν λ κ°μ₯ λ¨Όμ μ€ννλ©΄ μ’μ΅λλ€. νλ‘μ νΈμ 컨ν μ€νΈλ₯Ό λΉ λ₯΄κ² νμ ν μ μμ΅λλ€. ν€μλ: μΈμ μμ, 컨ν μ€νΈ, μ΄μ μμ , session start, context, previous work, what did we do μ¬μ© μμ: - "μ΄μ μ λ¬΄μ¨ μμ νμμ§?" - "νλ‘μ νΈ μ»¨ν μ€νΈ μλ €μ€" - "μΈμ 컨ν μ€νΈ μ‘°ν"`, inputSchema: { type: 'object', properties: { projectName: { type: 'string', description: 'νλ‘μ νΈλͺ μΌλ‘ νν°λ§ (μ ν)' }, category: { type: 'string', description: 'μΉ΄ν κ³ λ¦¬λ‘ νν°λ§ (μ ν)' }, memoryLimit: { type: 'number', description: 'μ‘°νν λ©λͺ¨λ¦¬ μ (κΈ°λ³Έκ°: 15)', default: 15 }, includeGraph: { type: 'boolean', description: 'μ§μ κ·Έλν ν¬ν¨ μ¬λΆ (κΈ°λ³Έκ°: true)', default: true }, includeTimeline: { type: 'boolean', description: 'νμλΌμΈ ν¬ν¨ μ¬λΆ (κΈ°λ³Έκ°: true)', default: true }, timeRange: { type: 'string', description: 'νμλΌμΈ μ‘°ν λ²μ', enum: ['1d', '7d', '30d', 'all'], default: '7d' } } }, annotations: { title: 'Get Session Context', audience: ['user', 'assistant'], readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false } };
- src/index.ts:175-175 (registration)Registration of the tool handler in the toolHandlers map for dynamic dispatch during tool execution.'get_session_context': getSessionContext,
- src/index.ts:108-108 (registration)Registration of the tool definition in the tools array provided to ListToolsRequestHandler.getSessionContextDefinition,
- src/index.ts:56-56 (registration)Import statement bringing in the handler and definition from the implementation file.import { getSessionContextDefinition, getSessionContext } from './tools/memory/getSessionContext.js';