feat(core): upgrade to v2.65.0 with Cognition Layer & Proactive Advisor

- Integrated v4.0 Operational Policy into AgentEngine and AgentExecutor.
- Added Context Amplification for policy-driven reasoning.
- Implemented Proactive Advisor for next-action decision forks.
- Added CognitionAudit diagnostics for real-time policy monitoring.
- Updated test suites to support dual-execution cognition patterns.
This commit is contained in:
g1nation
2026-05-04 22:42:08 +09:00
parent 29f271d781
commit 71e39ad78e
11 changed files with 174 additions and 15 deletions
+30
View File
@@ -93,3 +93,33 @@ export class PerformanceProfiler {
);
}
}
export class CognitionAudit {
/**
* [Astra v4.0] 지능적 판단 및 정책 준수 여부를 감사(Audit)합니다.
* 시스템이 얼마나 '생각'하고 '경고'했는지 정량적으로 측정합니다.
*/
public static auditPolicyCompliance(stage: string, content: string): void {
const findings = [];
// 1. 충돌 경고 감지 (Conflict Warning)
if (content.includes('[CONFLICT WARNING]')) {
findings.push('Conflict Detected & Warning Issued');
}
// 2. 선제적 제안 감지 (Proactive Advice)
if (content.includes('## 💡 Astra의 선제적 제안')) {
findings.push('Proactive Advice Generated');
}
// 3. 신뢰도 인용 패턴 확인 (Credibility Usage)
const highTrustCitationCount = (content.match(/\[\[/g) || []).length;
if (highTrustCitationCount > 0) {
findings.push(`Knowledge Density: ${highTrustCitationCount} connections used`);
}
if (findings.length > 0) {
logInfo(`[CognitionAudit] [${stage}] ${findings.join(' | ')}`);
}
}
}
+51 -3
View File
@@ -4,7 +4,7 @@ import * as path from 'path';
import { lockManager } from '../core/lock';
import { actionQueue } from '../core/queue';
import { logInfo, logError } from '../utils';
import { AgentDataValidator, PerformanceProfiler } from './diagnostics';
import { AgentDataValidator, PerformanceProfiler, CognitionAudit } from './diagnostics';
import { WikiFormatter } from './formatter';
// ─────────────────────────────────────────────
@@ -506,8 +506,16 @@ export class AgentEngine {
);
this.validateResult(finalReport, 'Writer');
// --- Phase 4: Proactive Advisor (Astra v4.0) ---
// 리포트 작성 후, 사용자의 다음 행동을 선제적으로 제안합니다.
const proactiveAdvice = await this.generateProactiveAdvice(finalReport, prompt, brainContext, signal);
const enrichedReport = `${finalReport}\n\n---\n## 💡 Astra의 선제적 제안 (Proactive Next Actions)\n${proactiveAdvice}`;
// 3. 지식 저장 포맷 표준화 (Standardization: Astra 피드백)
const standardizedReport = WikiFormatter.format(finalReport, missionId);
const standardizedReport = WikiFormatter.format(enrichedReport, missionId);
// [Astra v4.0] 지능적 판단 감사 (Cognition Audit)
CognitionAudit.auditPolicyCompliance('MissionComplete', standardizedReport);
this.transition(state, 'completed', '미션 완료', onProgress);
logInfo(`[AgentEngine] 미션 완료: ${missionId} (총 ${state.getElapsedMs()}ms)`);
@@ -589,7 +597,12 @@ export class AgentEngine {
}
const startTime = Date.now();
const result = await agent.execute(input, context, signal, options);
// [Astra v4.0] 맥락 증폭 (Context Amplification)
// 에이전트 실행 직전, 지식 신뢰도 및 충돌 처리 정책을 주입합니다.
const amplifiedContext = this.amplifyContext(context, options);
const result = await agent.execute(input, amplifiedContext, signal, options);
const durationMs = Date.now() - startTime;
PerformanceProfiler.logLLMLatency(agentName, durationMs, result.length);
@@ -680,4 +693,39 @@ export class AgentEngine {
// Error Recovery Matrix: Permanent 오류 발생을 방지하기 위한 선제적 핸드오프 검증
AgentDataValidator.validateHandoff(step, data);
}
/**
* [Astra v4.0] 맥락 증폭 로직
* 지식 관리 정책 v4.0을 LLM 지시사항으로 변환하여 주입합니다.
*/
private amplifyContext(context: string, options?: AgentExecuteOptions): string {
const policyDirectives = [
"\n### 🏛️ Knowledge Management Policy v4.0 Applied",
"- [CREDIBILITY] 정보 출처가 의도적으로 작성된 글인 경우 Medium 이상의 신뢰도를 부여하고 우선적으로 인용하십시오.",
"- [QUALITY] 지식의 양보다 '추론 기여 밀도'를 중시하여 핵심 위주로 서술하십시오.",
"- [CONFLICT] 상충되는 지식 발견 시 스스로 판단하지 말고 반드시 [CONFLICT WARNING] 플래그와 함께 두 관점을 모두 보고하십시오."
].join('\n');
return `${context}\n${policyDirectives}`;
}
/**
* [Astra v4.0] 선제적 제안 생성
* 수행된 작업 결과를 분석하여 다음 단계의 의사결정 포크를 제안합니다.
*/
private async generateProactiveAdvice(report: string, originalPrompt: string, context: string, signal: AbortSignal): Promise<string> {
logInfo(`[AgentEngine] 선제적 제안 생성 중...`);
// 본 로직은 별도의 가벼운 추론 단계를 거치거나, WriterAgent의 기능을 확장하여 구현할 수 있습니다.
// 현재는 WriterAgent에게 한 번 더 질의하거나, 리포트에서 액션 아이템을 추출하는 구조로 시작합니다.
const advicePrompt = `다음 리포트를 읽고, 사용자가 다음에 내려야 할 '전략적 의사결정'이나 '실행 작업' 3가지를 제안해줘.
원래 요청: ${originalPrompt}
리포트 요약: ${report.substring(0, 1000)}...`;
try {
// WriterAgent를 Advisor 모드로 재활용
return await this.writer.execute(advicePrompt, context, signal, { config: { role: 'advisor' } });
} catch (err) {
return "다음 단계에 대한 자동 제안을 생성하지 못했습니다. 리포트의 결론 섹션을 참고해 주세요.";
}
}
}