feat: Intelligent Resilience & Trust Reporting (v2.77.2)

This commit is contained in:
g1nation
2026-05-05 17:04:27 +09:00
parent 037eafa02b
commit cf10d14148
29 changed files with 490 additions and 166 deletions
+59 -5
View File
@@ -2,10 +2,9 @@ import { logInfo } from '../utils';
export class AgentDataValidator {
/**
* 에이전트 간 핸드오프(Handoff) 시 데이터 무결성을 검증합니다.
* 데이터 누락이나 스키마 오류를 감지하여 파이프라인의 안정성을 높입니다.
* 에이전트 간 핸드오프(Handoff) 시 데이터 무결성을 검증하고 품질 점수를 반환합니다.
*/
public static validateHandoff(stage: string, data: string): void {
public static validateHandoff(stage: string, data: string): number {
if (!data || data.trim().length === 0) {
throw new Error(`[IntegrityError] 데이터 누락: ${stage} 에이전트의 출력이 비어 있습니다.`);
}
@@ -17,7 +16,6 @@ export class AgentDataValidator {
if (data.length < minLength) {
throw new Error(`[IntegrityError] Planner 출력 데이터가 비정상적으로 짧습니다 (${data.length} chars). 계획 누락 의심.`);
}
// 향후 JSON 스키마 검증(Zod 등)을 여기에 추가할 수 있습니다.
break;
case 'researcher':
if (data.length < minLength) {
@@ -36,11 +34,19 @@ export class AgentDataValidator {
break;
}
// 품질 점수화 (Quality Scoring) - Astra 피드백 반영
// 품질 점수화 (Quality Scoring)
const score = QualityScorer.evaluate(data);
if (score < 50) {
logInfo(`[QualityWarning] ${stage} 결과 품질 낮음 (Score: ${score}). 내용 보강이 필요할 수 있습니다.`);
}
// [New] 지능형 충돌 감지 및 위험도 평가
const conflictRisk = ConflictDetector.analyzeSemanticDivergence(data);
if (conflictRisk > 40) {
logInfo(`[ConflictAlert] ${stage} 단계에서 지식 충돌 위험 감지 (Risk: ${conflictRisk}).`);
}
return score - (conflictRisk * 0.5); // 충돌 위험이 높으면 전체 품질 점수를 감쇄함
}
}
@@ -94,6 +100,54 @@ export class PerformanceProfiler {
}
}
export class ConflictDetector {
/**
* [Astra v4.1] 도메인 맥락 기반의 의미적 괴리(Semantic Divergence)를 분석합니다.
* 데이터 내의 논리적 모순이나 상충하는 지표를 탐지하여 위험도를 산출합니다.
*/
public static analyzeSemanticDivergence(data: string): number {
if (!data) return 0;
let riskScore = 0;
// 1. 수치적 모순 탐지 (Metric Contradiction)
// 동일 문맥 내에서 서로 다른 수치가 발견되는 패턴 탐지
const metricPatterns = [
/(\d+%)\s+vs\s+(\d+%)/g,
/(\d+ms)\s+대비\s+(\d+ms)/g,
/상충되는\s+(데이터|정보|결과)/i
];
for (const pattern of metricPatterns) {
if (pattern.test(data)) riskScore += 25;
}
// 2. 논리적 상충 용어 탐지 (Logical Divergence)
const conflictTerms = [
['최적화', '성능 저하'],
['안정적', '불안정'],
['증가', '감소'],
['승인', '반려/경고'],
['임상 등급', '비승인/소비자용']
];
for (const [pos, neg] of conflictTerms) {
if (data.includes(pos) && data.includes(neg)) {
// 두 상충 용어가 너무 가까운 거리(예: 200자 이내)에 있으면 충돌 확률 높음
const posIdx = data.indexOf(pos);
const negIdx = data.indexOf(neg);
if (Math.abs(posIdx - negIdx) < 300) {
riskScore += 15;
}
}
}
// 3. 명시적 경고 태그 확인
if (data.includes('[CONFLICT WARNING]')) riskScore += 30;
return Math.min(100, riskScore);
}
}
export class CognitionAudit {
/**
* [Astra v4.0] 지능적 판단 및 정책 준수 여부를 감사(Audit)합니다.