[Phase 17-A] Reflexion 자기성찰 메모리 시스템 구현

ReflexionEvaluatorService 신규 구현 (ReflexionService.cs):
- LLM 기반 자기평가: 완성도 점수(0~1), 강점/약점/교훈 추출
- $$raw string 평가 프롬프트로 JSON 포맷 안전하게 삽입
- JSON 블록 추출 + 역직렬화, LLM 실패 시 규칙 기반 폴백 엔트리
- ReflexionRepository.BuildContextPromptAsync() maxEntries 파라미터 추가

AgentLoopService.Reflexion.cs (신규, 82줄):
- InjectReflexionContextAsync(): 세션 시작 전 과거 교훈→시스템 메시지 주입
- FireAndForgetReflexionEval(): 세션 완료 후 Task.Run 비동기 자기평가 저장
- 지연 초기화(_reflexionRepo, _reflexionEval): 사용 시점에 생성

AgentLoopService.cs 통합 포인트 2개 추가:
- RunAsync() 루프 시작 전: await InjectReflexionContextAsync()
- finally 블록 통계 섹션: FireAndForgetReflexionEval() 호출

AgentSettingsPanel — 자기성찰 메모리 섹션 추가:
- 활성화 토글(ChkReflexionEnabled)
- 성공 세션만 평가 토글(ChkReflexionSuccessOnly)
- 최대 참고 교훈 수 슬라이더(1~20, 기본값 5)
- LoadFromSettings() 초기화 + 3개 이벤트 핸들러

빌드: 경고 0, 오류 0
This commit is contained in:
2026-04-03 23:07:59 +09:00
parent 5fe6d5c6ba
commit 90d5943327
6 changed files with 380 additions and 4 deletions

View File

@@ -196,6 +196,9 @@ public partial class AgentLoopService
var context = BuildContext(activeTabSnapshot);
// Phase 17-A: Reflexion — 과거 교훈을 시스템 메시지에 주입
await InjectReflexionContextAsync(messages, userQuery);
try
{
// ── 플랜 모드 "always": 첫 번째 호출은 계획만 생성 (도구 없이) ──
@@ -820,6 +823,13 @@ public partial class AgentLoopService
$"소요 {durationSec:F1}초 | 사용 도구: {toolList}";
EmitEvent(AgentEventType.StepDone, "total_stats", summary);
}
// Phase 17-A: Reflexion — 세션 완료 후 자기평가 비동기 저장
var isSessionSuccess = statsSuccessCount > 0 && statsFailCount == 0;
var lastResult = messages.LastOrDefault(m => m.Role == "assistant")?.Content ?? "";
FireAndForgetReflexionEval(
userQuery, lastResult, _sessionId ?? "",
isSessionSuccess, totalToolCalls, iteration);
}
}
}