DOCS/journey/plans/251225_프롬프트_동적관리_계획.md
2026-01-04 14:28:10 +09:00

3.0 KiB

프롬프트 동적 관리 시스템 계획

날짜: 2025-12-25 작성자: happybell80 관련 파일: rb8001/app/services/llm/gemini_handler.py, rb8001/app/services/llm/llm_service.py 상태: 📋 계획 단계


목표

프롬프트 DB화를 통한 동적 변경 및 개인화 구현

DB 스키마 설계

CREATE TABLE prompt_templates (
    id UUID PRIMARY KEY,
    scope_level VARCHAR(20) NOT NULL,  -- 'global', 'robeing', 'user', 'task'
    scope_id VARCHAR(255),              -- robeing_id, user_id, task_type 등
    prompt_type VARCHAR(50) NOT NULL,   -- 'system', 'chat', 'extract', 'calendar_confirm', 'ir_analysis' 등
    version VARCHAR(20) DEFAULT '1.0',
    content JSONB NOT NULL,             -- 템플릿 내용 + 변수 정의 (XML 구조 유지)
    is_active BOOLEAN DEFAULT true,
    created_at TIMESTAMPTZ DEFAULT now(),
    updated_at TIMESTAMPTZ DEFAULT now(),
    
    UNIQUE(scope_level, scope_id, prompt_type, version)
);

프롬프트 분류 기준

1. 변경 빈도별

  • 거의 안 바뀜: Global/system_basic (기본 정체성)
  • 자주 변경: User/preferred_name (사용자 피드백 반영)

2. 계층적 범위(Scope)

  • Global: 모든 사용자 공통 기본 프롬프트
  • Robeing: 특정 로빙 공통
  • User: 사용자별 개인화
  • Task: 작업 타입별 (chat, extract, calendar_confirm 등)

3. 병합 로직

  • Global → Robeing → User 순서로 조회
  • 각 레벨별 개별 쿼리 후 애플리케이션에서 병합
  • Global scope는 scope_id=NULL로 조회

구현 Phase

Phase 1: DB 스키마 및 기본 인프라

파일: rb8001/app/state/repositories/prompt_repository.py (신규)

  • prompt_templates 테이블 생성
  • PromptService 클래스 (조회, 병합, 캐싱)
  • 기본 프롬프트 마이그레이션 (하드코딩 → DB)

Phase 2: 핵심 프롬프트 DB화

파일: rb8001/app/services/llm/gemini_handler.py, rb8001/app/services/llm/llm_service.py

  • 시스템 프롬프트 DB 조회로 변경
  • 작업 타입별 프롬프트 (chat, extract, calendar_confirm) DB화
  • 폴백 로직: DB 조회 실패 시 기존 _get_system_prompt() 메서드 사용

Phase 3: 개인화 및 동적 프롬프트

파일: rb8001/app/services/llm/prompt_service.py (신규)

  • 사용자별 프롬프트 오버라이드
  • 감정 기반 동적 프롬프트 조합
  • 변수 치환 시스템 ({current_time}, {emotion_labels})

Phase 4: A/B 테스트 및 모니터링

파일: rb8001/app/services/llm/prompt_service.py

  • 프롬프트 버전 관리
  • A/B 테스트 지원
  • 롤백 기능

참고 문서