feat: implement next-gen vectorized engine, async architecture, and modernization roadmap v2.32.0
This commit is contained in:
@@ -1,19 +1,10 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { PlannerAgent, ResearcherAgent, WriterAgent } from './factory';
|
||||
|
||||
/**
|
||||
* 에이전트 간의 데이터 인계 계약(Contract) 정의
|
||||
*/
|
||||
export interface AgentResult {
|
||||
step: string;
|
||||
content: string;
|
||||
timestamp: number;
|
||||
success: boolean;
|
||||
}
|
||||
import { AgentEngine, PipelineStage } from '../lib/engine';
|
||||
|
||||
export class AgentWorkflowManager {
|
||||
/**
|
||||
* 멀티 에이전트 워크플로우를 강력한 동기화(Synchronization) 하에 실행합니다.
|
||||
* 리팩토링된 고성능 에이전트 엔진을 통해 워크플로우를 실행합니다.
|
||||
*/
|
||||
public static async runStrictWorkflow(
|
||||
prompt: string,
|
||||
@@ -23,35 +14,30 @@ export class AgentWorkflowManager {
|
||||
onProgress: (step: string, message: string) => void
|
||||
): Promise<string> {
|
||||
|
||||
// 1. 에이전트 인스턴스화
|
||||
// 1. 에이전트 준비 (DI를 위한 인스턴스화)
|
||||
const planner = new PlannerAgent(modelName);
|
||||
const researcher = new ResearcherAgent(modelName);
|
||||
const writer = new WriterAgent(modelName);
|
||||
|
||||
// 2. 엔진 인스턴스 생성 (의존성 주입)
|
||||
const engine = new AgentEngine(planner, researcher, writer);
|
||||
|
||||
// 3. 고유 미션 ID 생성 (현재는 타임스탬프 기반)
|
||||
const missionId = `mission_${Date.now()}`;
|
||||
|
||||
try {
|
||||
// --- Phase 1: Planner (Decomposition & Strategy) ---
|
||||
if (signal.aborted) throw new Error('AbortError');
|
||||
onProgress('Planner', '전략 분석 및 작업 분해 중...');
|
||||
const plan = await planner.execute(prompt, brainContext, signal);
|
||||
this.validateResult(plan, 'Planner');
|
||||
|
||||
// --- Phase 2: Researcher (Fact Harvesting) ---
|
||||
if (signal.aborted) throw new Error('AbortError');
|
||||
// 동기화를 위한 의도적 미세 지연 (서버 부하 분산)
|
||||
await new Promise(r => setTimeout(r, 800));
|
||||
onProgress('Researcher', '데이터 수집 및 핵심 정보 추출 중...');
|
||||
const research = await researcher.execute(plan, brainContext, signal);
|
||||
this.validateResult(research, 'Researcher');
|
||||
|
||||
// --- Phase 3: Writer (Final Synthesis) ---
|
||||
if (signal.aborted) throw new Error('AbortError');
|
||||
await new Promise(r => setTimeout(r, 800));
|
||||
onProgress('Writer', '수집된 정보를 바탕으로 최종 리포트 작성 중...');
|
||||
const finalReport = await writer.execute(research, prompt, signal);
|
||||
this.validateResult(finalReport, 'Writer');
|
||||
|
||||
return finalReport;
|
||||
|
||||
// 4. 엔진을 통한 미션 실행 (Producer-Consumer & Mutex 적용)
|
||||
return await engine.runMission(
|
||||
missionId,
|
||||
prompt,
|
||||
brainContext,
|
||||
signal,
|
||||
(stage: PipelineStage, message: string) => {
|
||||
// UI 피드백을 위한 프로그레스 업데이트
|
||||
const uiStepName = this.mapStageToUI(stage);
|
||||
onProgress(uiStepName, message);
|
||||
}
|
||||
);
|
||||
} catch (error: any) {
|
||||
if (error.name === 'AbortError' || error.message.includes('cancelled')) {
|
||||
throw error;
|
||||
@@ -61,12 +47,17 @@ export class AgentWorkflowManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* 데이터 정합성(Data Integrity) 검증
|
||||
* 엔진 스테이지를 UI 표시용 명칭으로 매핑
|
||||
*/
|
||||
private static validateResult(data: string, step: string) {
|
||||
if (!data || data.trim().length < 20) {
|
||||
const preview = data ? `(Content: "${data.substring(0, 100)}...")` : '(Empty Response)';
|
||||
throw new Error(`${step} 단계에서 생성된 데이터가 불충분합니다. ${preview} 모델을 더 똑똑한 것으로 변경해 보세요.`);
|
||||
}
|
||||
private static mapStageToUI(stage: PipelineStage): string {
|
||||
const maps: Record<PipelineStage, string> = {
|
||||
idle: '대기',
|
||||
planner: 'Planner',
|
||||
researcher: 'Researcher',
|
||||
writer: 'Writer',
|
||||
completed: '완료',
|
||||
error: '오류'
|
||||
};
|
||||
return maps[stage] || '진행 중';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user