From 0cec940a756a6e28f3a86c78a3f82977e8b80fc7 Mon Sep 17 00:00:00 2001 From: kicer Date: Wed, 2 Sep 2026 11:10:21 +0800 Subject: [PATCH] add debug all of context --- app/config.example.yml | 2 +- app/server/engine.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/config.example.yml b/app/config.example.yml index 9085c78..019a65c 100644 --- a/app/config.example.yml +++ b/app/config.example.yml @@ -22,7 +22,7 @@ workspace_root: "./data/tasks" # db_path: "/data/.agent.db" # 日志等级(改后重启生效):debug < info < warn < error < none,只输出 ≥ 该等级的日志;none=全部静默。 -# info(默认)=关键动作;debug 另加工具调用参数/结果等排查细节。 +# info(默认)=关键动作概述;debug 另加用户/AI 消息全文、工具调用参数/结果等排查细节。 log_level: info terminal: diff --git a/app/server/engine.js b/app/server/engine.js index e2e2550..af6dc0b 100644 --- a/app/server/engine.js +++ b/app/server/engine.js @@ -92,6 +92,13 @@ function saveMessage(sessionId, msg) { } log.info('[msg] ' + sessionId + ' AI 回复:文本 ' + String(msg.content || '').length + ' 字' + toolDesc); } + // debug 等级:用户/AI 消息全文打印(含 tool_calls 参数),方便调试;info 仍只给概述。 + // 不含 tool 角色:工具结果另在 runLoopInner 记 debug,且含图消息的大段 base64 不应刷进日志。 + if (msg.role === 'user' || msg.role === 'assistant') { + log.debug('[msg] ' + sessionId + ' ' + (msg.role === 'user' ? '用户消息全文' : 'AI 回复全文') + + (msg.name ? '(' + msg.name + ')' : '') + ':\n' + String(msg.content || '') + + (msg.tool_calls ? '\ntool_calls: ' + JSON.stringify(msg.tool_calls) : '')); + } return info.lastInsertRowid; } @@ -429,7 +436,7 @@ async function runLoopInner(sessionId, run) { for (const tc of msgRow.tool_calls) { if (run.cancelled) break; const id = tc.id || ('call_' + Math.random().toString(36).slice(2, 10)); - log.debug('[tool] ' + sessionId + ' 调用 ' + tc.function.name + ' 参数: ' + String(tc.function.arguments || '').slice(0, 500)); + log.debug('[tool] ' + sessionId + ' 调用 ' + tc.function.name + ' 参数: ' + String(tc.function.arguments || '')); bus.emit(sessionId, 'tool_call', { id, name: tc.function.name, arguments: tc.function.arguments }); let output; let isError = false; @@ -452,7 +459,7 @@ async function runLoopInner(sessionId, run) { outText = String(output == null ? '' : output); } if (run.cancelled && !isError) outText = (outText ? outText + '\n' : '') + '(用户已终止任务)'; - log.debug('[tool] ' + sessionId + ' ' + tc.function.name + (isError ? ' 失败: ' : ' 完成: ') + outText.slice(0, 500)); + log.debug('[tool] ' + sessionId + ' ' + tc.function.name + (isError ? ' 失败: ' : ' 完成: ') + outText); const toolContent = imageDataUrl ? encodeBlocks([ { type: 'text', text: outText },