From 3efccc74a56d65bb6af0bf64e3776e9e977ca4a0 Mon Sep 17 00:00:00 2001 From: hy Date: Fri, 17 Apr 2026 15:45:20 +0800 Subject: [PATCH] Add live run delay and simplify brain prompt --- scripts/test-workflow.mjs | 28 +++++++++++++++++++- src/main/services/ai/human/prompts/brain.ts | 29 ++++++++++----------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/scripts/test-workflow.mjs b/scripts/test-workflow.mjs index 0d4735e3..8ae7d604 100644 --- a/scripts/test-workflow.mjs +++ b/scripts/test-workflow.mjs @@ -17,7 +17,8 @@ const parseArgs = (argv) => { suite: '', groups: [], caseId: '', - runs: 1 + runs: 1, + runDelayMs: 0 } for (let index = 0; index < argv.length; index += 1) { @@ -51,12 +52,19 @@ const parseArgs = (argv) => { if (current === '--runs' && next) { parsed.runs = Math.max(1, Number(next)) index += 1 + continue + } + if (current === '--run-delay-ms' && next) { + parsed.runDelayMs = Math.max(0, Number(next)) + index += 1 } } return parsed } +const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) + const walk = async (target) => { const entries = await readdir(target, { withFileTypes: true }) const files = [] @@ -177,6 +185,17 @@ const runTypeWorkflow = async (input) => { } let exitCode = 0 + const { liveFiles } = + input.type === 'backend' + ? partitionBackendTestFiles(testFiles) + : { liveFiles: [] } + const runDelayMs = + input.runs > 1 && liveFiles.length > 0 + ? input.runDelayMs > 0 + ? input.runDelayMs + : 3000 + : 0 + for (let iteration = 0; iteration < input.runs; iteration += 1) { if (input.type === 'backend') { const { nonLiveFiles, liveFiles } = partitionBackendTestFiles(testFiles) @@ -211,6 +230,13 @@ const runTypeWorkflow = async (input) => { if (exitCode !== 0) { break } + + if (runDelayMs > 0 && iteration < input.runs - 1) { + process.stdout.write( + `[test-workflow] waiting ${String(runDelayMs)}ms before next live run (${String(iteration + 2)}/${String(input.runs)})\n` + ) + await sleep(runDelayMs) + } } return exitCode diff --git a/src/main/services/ai/human/prompts/brain.ts b/src/main/services/ai/human/prompts/brain.ts index 351e6211..1b9903e6 100644 --- a/src/main/services/ai/human/prompts/brain.ts +++ b/src/main/services/ai/human/prompts/brain.ts @@ -14,12 +14,12 @@ import { import { renderHumanStableNotes } from '../shared/memoryRenderers' import { renderLoadedHistoryText, renderRoundSection } from '../shared/historyRenderers' import { getToolSpec } from '../tools/registry' -import { renderBrainOutputSchemaForPrompt, renderToolSchemaForPrompt } from '../tools/schemaPromptRenderer' +import { + renderBrainOutputSchemaForPrompt, + renderToolSchemaForPrompt +} from '../tools/schemaPromptRenderer' import { humanDecisionSchema } from '../schema' -import type { - HumanState, - ToolPromptExample -} from '../types' +import type { HumanState, ToolPromptExample } from '../types' import type { HumanToolSpec } from '../tools/types' import { renderWatchHintForBrain } from './watchHints' @@ -124,22 +124,21 @@ export const buildBrainPrompt = (input: { state: HumanState; ctx: AiRunContext } - 如果最终交付必须补充不来自本地资料的模型常识,应在收口时明确说明这些补充点不来自当前本地资料。 - + - 你只负责判断下一步,不亲自补能力、执行工具或直接对用户表达。 + - nextAction 只能在 learning、hand、mouth 三者中选择其一。 + - learning 只负责补齐当前真正缺失的技能说明。 - hand 只负责执行已经决定好的工具计划。 - mouth 只负责整理最终结果,不新增事实,不继续执行工具。 - - - - nextAction 只能在 learning、hand、mouth 三者中选择其一。 - 选择 learning:当你已经知道缺少哪类能力说明,且补齐后能明显降低不确定性时。 - 选择 hand:当下一步已经明确成一批工具调用,且你能给出完整合法的 toolUsePlan 时。 - - 如果你现在无法给出某个工具的完整必填参数,不要猜;应改为 learning 或 mouth。 - - hand 的 toolUsePlan 单轮只能选择一种 mode。只有只读且彼此独立、并行安全的动作才用 parallel;其余情况必须用 serial。 - - 如果结果仍依赖未来的工具动作才能完成,readyToDeliver 必须为 false,且不能选择 mouth。 - 选择 mouth:只在 readyToDeliver=true 且当前已经足够形成最终交付时。 - + + - 如果你现在无法给出某个工具的完整必填参数,不要猜;应改为 learning 或 mouth。 + - 如果结果仍依赖未来的工具动作才能完成,readyToDeliver 必须为 false,且不能选择 mouth。 + - task_goal:用户原始诉求与限制。 @@ -187,7 +186,7 @@ ${outputShapeText} - + { "decision": { "summary": "先学习当前缺失的技能", @@ -227,7 +226,7 @@ ${outputShapeText} } - + { "updatedStableMemory": { "currentUnderstanding": "- 已确认审批驳回时原文件保持不变。",