feat: add memory system and troubleshoot agent

Memory System:
- Add category-based memory storage (company, tech, role, location, server)
- Silent background saving via saveMemorySilently()
- Category-based overwrite (same category replaces old memory)
- Server-related pattern detection (AWS, GCP, k8s, traffic info)
- Memory management tool (list, delete)

Troubleshoot Agent:
- Session-based troubleshooting conversation (KV, 1h TTL)
- 20-year DevOps/SRE expert persona
- Support for server/infra, domain/DNS, code/deploy, network, database issues
- Internal tools: search_solution (Brave), lookup_docs (Context7)
- Auto-trigger on error-related keywords
- Session completion and cancellation support

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
kappa
2026-01-27 14:28:22 +09:00
parent 6392a17d4f
commit 860e36a688
13 changed files with 1328 additions and 58 deletions

View File

@@ -0,0 +1,75 @@
import type { Env } from '../types';
import { createLogger } from '../utils/logger';
const logger = createLogger('troubleshoot-tool');
export const manageTroubleshootTool = {
type: 'function',
function: {
name: 'manage_troubleshoot',
description: '기술 문제 해결 도우미. 서버 에러, 도메인 문제, 배포 실패, 네트워크 오류, 데이터베이스 이슈 등을 진단하고 해결합니다. 사용자가 "에러", "문제", "안돼", "느려", "오류" 등을 언급하면 이 도구를 사용하세요.',
parameters: {
type: 'object',
properties: {
action: {
type: 'string',
enum: ['start', 'cancel'],
description: 'start=문제 해결 시작, cancel=세션 취소',
},
},
required: ['action'],
},
},
};
export async function executeManageTroubleshoot(
args: { action: 'start' | 'cancel' },
env?: Env,
telegramUserId?: string
): Promise<string> {
const { action } = args;
logger.info('트러블슈팅 도구 호출', { action, userId: telegramUserId });
if (!env?.SESSION_KV || !telegramUserId) {
return '🚫 트러블슈팅 기능을 사용할 수 없습니다.';
}
const { getTroubleshootSession, saveTroubleshootSession, deleteTroubleshootSession } = await import('../troubleshoot-agent');
if (action === 'cancel') {
await deleteTroubleshootSession(env.SESSION_KV, telegramUserId);
return '✅ 트러블슈팅 세션이 취소되었습니다.';
}
// action === 'start'
const existingSession = await getTroubleshootSession(env.SESSION_KV, telegramUserId);
if (existingSession && existingSession.status !== 'completed') {
return '이미 진행 중인 트러블슈팅 세션이 있습니다. 계속 진행해주세요.\n\n현재까지 파악된 정보:\n' +
(existingSession.collectedInfo.category ? `• 분류: ${existingSession.collectedInfo.category}\n` : '') +
(existingSession.collectedInfo.symptoms ? `• 증상: ${existingSession.collectedInfo.symptoms}\n` : '');
}
// Create new session
const newSession = {
telegramUserId,
status: 'gathering' as const,
collectedInfo: {},
messages: [],
createdAt: Date.now(),
updatedAt: Date.now(),
};
await saveTroubleshootSession(env.SESSION_KV, telegramUserId, newSession);
logger.info('트러블슈팅 세션 시작', { userId: telegramUserId });
return '__DIRECT__🔧 기술 문제 해결 도우미입니다.\n\n' +
'어떤 문제가 발생했나요? 최대한 자세히 설명해주세요.\n\n' +
'💡 예시:\n' +
'• "서버가 502 에러를 반환해요"\n' +
'• "도메인이 연결이 안돼요"\n' +
'• "배포가 실패해요"\n' +
'• "데이터베이스 연결이 느려요"';
}