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
+14 -7
View File
@@ -97,6 +97,14 @@ export class AgentExecutor {
return { problem, goal, reasoning };
}
private sanitizeAssistantContent(text: string): string {
return text
.replace(/<rationale>[\s\S]*?<\/rationale>/gi, '')
.replace(/^\s*\[PROBLEM\][\s\S]*?\[GOAL\][\s\S]*?\[REASONING\][^\n]*(?:\n+|$)/i, '')
.replace(/^\s*\[PROBLEM\][\s\S]*?(?:\n\s*\n|$)/i, '')
.trim();
}
private async restoreLastSession() {
try {
const lastSession = this.sessionManager.loadLastActiveSession();
@@ -394,12 +402,13 @@ export class AgentExecutor {
// 5. Execute Actions
const rationale = this.parseRationale(aiResponseText);
const assistantMessage: ChatMessage = { role: 'assistant', content: aiResponseText, internal: false, rationale };
const assistantContent = this.sanitizeAssistantContent(aiResponseText);
const assistantMessage: ChatMessage = { role: 'assistant', content: assistantContent, internal: false, rationale };
this.chatHistory.push(assistantMessage);
this.statusBarManager.updateStatus(AgentStatus.Executing);
const report = await this.executeActions(aiResponseText, rootPath);
if (!aiResponseText.trim() && report.length === 0) {
if (!assistantContent.trim() && report.length === 0) {
this.chatHistory.pop();
logError('Model returned an empty response without actions.', { model: actualModel, engine, apiUrl, loopDepth });
this.webview.postMessage({
@@ -414,7 +423,7 @@ export class AgentExecutor {
return;
}
if (report.length === 0 && loopDepth === 0 && this.isUnproductiveWaitingReply(aiResponseText)) {
if (report.length === 0 && loopDepth === 0 && this.isUnproductiveWaitingReply(assistantContent)) {
assistantMessage.internal = false;
const correctedReply = await this.buildUnproductiveReplyCorrection(prompt || '');
assistantMessage.content = correctedReply;
@@ -453,7 +462,7 @@ export class AgentExecutor {
this.emitHistoryChanged();
this.statusBarManager.updateStatus(AgentStatus.Success);
this.webview.postMessage({ type: 'streamChunk', value: aiResponseText });
this.webview.postMessage({ type: 'streamChunk', value: assistantContent });
} catch (error: any) {
this.statusBarManager.updateStatus(AgentStatus.Error, error.message);
@@ -505,7 +514,6 @@ export class AgentExecutor {
logError('Failed to load brain context for agents', ctxErr);
}
const workflow = getConfig().multiAgentWorkflow;
const selectedAgentContext = options.agentSkillContext
? `\nSelected Agent Reference:\n${options.agentSkillContext}`
: '';
@@ -520,8 +528,7 @@ export class AgentExecutor {
this.webview?.postMessage({ type: 'autoContinue', value: `${step}: ${msg}` });
// 각 단계별 시작을 알림
this.webview?.postMessage({ type: 'streamChunk', value: `\n\n> **[${step}]** ${msg}\n\n` });
},
workflow
}
);
if (signal.aborted || !this.webview) return;