feat: upgrade core agent workflow and system utilities

This commit is contained in:
g1nation
2026-05-01 20:24:00 +09:00
parent 2d16c4ae14
commit 82db8495f8
8 changed files with 56 additions and 262 deletions
+28 -45
View File
@@ -1,5 +1,5 @@
import { ConfigurableWorkflowAgent } from './factory';
import { DEFAULT_MULTI_AGENT_WORKFLOW, MultiAgentStageConfig } from '../config';
import { PlannerAgent, ResearcherAgent, WriterAgent } from './factory';
import { AgentEngine, PipelineStage } from '../lib/engine';
export class AgentWorkflowManager {
/**
@@ -10,28 +10,24 @@ export class AgentWorkflowManager {
modelName: string,
brainContext: string,
signal: AbortSignal,
onProgress: (step: string, message: string) => void,
workflow: MultiAgentStageConfig[] = DEFAULT_MULTI_AGENT_WORKFLOW
onProgress: (step: string, message: string) => void
): Promise<string> {
const stages = workflow.length > 0 ? workflow : DEFAULT_MULTI_AGENT_WORKFLOW;
const stageOutputs: string[] = [];
const planner = new PlannerAgent(modelName);
const researcher = new ResearcherAgent(modelName);
const writer = new WriterAgent(modelName);
const engine = new AgentEngine(planner, researcher, writer);
const missionId = `mission_${Date.now()}`;
try {
for (const [index, stage] of stages.entries()) {
if (signal.aborted) throw new Error('AbortError');
const agent = new ConfigurableWorkflowAgent(modelName, stage);
const stepName = stage.name || `Stage ${index + 1}`;
onProgress(stepName, `Running ${index + 1}/${stages.length}`);
const stageInput = this.buildStageInput(stage, prompt, stageOutputs);
const result = await agent.execute(stageInput, brainContext, signal);
this.validateResult(result, stepName);
stageOutputs.push(result);
onProgress(stepName, `Completed ${index + 1}/${stages.length}`);
}
return stageOutputs[stageOutputs.length - 1];
return await engine.runMission(
missionId,
prompt,
brainContext,
signal,
(stage: PipelineStage, message: string) => {
onProgress(this.mapStageToUI(stage), message);
}
);
} catch (error: any) {
if (error.name === 'AbortError' || error.message.includes('cancelled')) {
throw error;
@@ -40,28 +36,15 @@ export class AgentWorkflowManager {
}
}
private static buildStageInput(stage: MultiAgentStageConfig, originalPrompt: string, stageOutputs: string[]): string {
const previous = stageOutputs[stageOutputs.length - 1] || '';
if (stage.input === 'original') {
return originalPrompt;
}
if (stage.input === 'previous') {
return previous || originalPrompt;
}
return [
'## Original User Request',
originalPrompt,
'',
'## Previous Stage Output',
previous || 'No previous stage output.'
].join('\n');
}
private static validateResult(data: string, step: string) {
if (!data || data.trim().length < 10) {
throw new Error(`${step} agent did not return a usable response.`);
}
private static mapStageToUI(stage: PipelineStage): string {
const maps: Record<PipelineStage, string> = {
idle: '대기',
planner: 'Planner',
researcher: 'Researcher',
writer: 'Writer',
completed: '완료',
error: '오류'
};
return maps[stage] || '진행 중';
}
}
+1 -27
View File
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import { MultiAgentStageConfig, getConfig } from '../config';
import { getConfig } from '../config';
export abstract class BaseAgent {
constructor(protected readonly modelName: string) {}
@@ -145,29 +145,3 @@ Your goal is to produce a state-of-the-art final report that wows the user.
return this.callLLM(this.persona, wrappedInput, signal);
}
}
export class ConfigurableWorkflowAgent extends BaseAgent {
constructor(
modelName: string,
private readonly stage: MultiAgentStageConfig
) {
super(modelName);
}
async execute(input: string, context?: string, signal?: AbortSignal): Promise<string> {
const wrappedInput = [
`### Stage: ${this.stage.name}`,
'',
'### Available Context',
context || 'No specific context available.',
'',
'### Stage Input',
input,
'',
'### Mission',
'Complete this stage according to your role instructions. Be concise, concrete, and preserve details needed by later stages.'
].join('\n');
return this.callLLM(this.stage.prompt, wrappedInput, signal);
}
}