fix: Agent Loop 多轮迭代消息互相覆盖 — 每轮创建独立消息气泡
问题:Agent Loop 多轮迭代(thought→action→observation→循环)时,每轮 onContent 回调都通过 updateLastAssistantMessage 替换同一个 placeholder 的 innerHTML,导致前一轮的回复内容被后一轮覆盖,只有最后一轮保留。 修复: - agent-engine.ts: AgentCallbacks 新增 onNewIteration 回调,每轮迭代 开始前通知 UI 层 - input-area.ts: sendMessageWithAgentLoop + handleRetry 添加 onNewIteration 处理——保存当前轮内容为独立消息、重置状态、创建新 placeholder。onDone 根据 agentModeIterations 判断是否需要重复保存
This commit is contained in:
@@ -357,6 +357,8 @@ export interface AgentCallbacks {
|
||||
onToolCallError: (name: string, error: string, call: ToolCall) => void;
|
||||
onDone: (finalContent: string, toolRecords?: ToolCallRecord[], stats?: { eval_count?: number; total_duration?: number }) => void;
|
||||
onConfirmTool: (call: ToolCall) => Promise<boolean>;
|
||||
/** Agent Loop 新迭代开始(前一轮工具执行完毕,下一轮流式输出即将开始) */
|
||||
onNewIteration?: () => void;
|
||||
}
|
||||
|
||||
/** 保存执行轨迹到 SQLite */
|
||||
@@ -530,6 +532,11 @@ export async function runAgentLoop(
|
||||
throw new DOMException('Aborted', 'AbortError');
|
||||
}
|
||||
|
||||
// 非首轮迭代:通知 UI 创建新的消息气泡(防止每轮内容互相覆盖)
|
||||
if (loopCount > 1 && callbacks.onNewIteration) {
|
||||
callbacks.onNewIteration();
|
||||
}
|
||||
|
||||
logAgentLoop(loopCount, maxLoops);
|
||||
|
||||
let thinking = '';
|
||||
|
||||
Reference in New Issue
Block a user