fix(builtin): nudge LLM when it stops tools without frontmatter

LLM sometimes emits plain text (e.g. 'Now I'll write the tests...')
without calling tools, which the loop treated as final output. Now
the loop detects this and injects a user message nudging the LLM
to either continue using tools or output frontmatter with ---.
This commit is contained in:
2026-05-23 21:48:07 +08:00
parent edb979baa9
commit ac55a3e3d9
+15 -2
View File
@@ -95,14 +95,27 @@ export async function runBuiltinLoop(
messages.push(assistantMessage);
if (response.toolCalls === null || response.toolCalls.length === 0) {
finalText = response.content ?? "";
const text = response.content ?? "";
await appendTurn(options.storageRoot, options.sessionId, {
role: "assistant",
content: response.content ?? "",
content: text,
toolCalls: null,
reasoning: null,
});
turnCount += 1;
// If tools are available but LLM stopped calling them without producing
// frontmatter, nudge it to continue working or output frontmatter.
if (!options.noTools && !text.trimStart().startsWith("---") && turn < options.maxTurns - 1) {
log("7FXQM2KN", "text-only turn without frontmatter, nudging LLM to continue");
const nudge =
"You stopped calling tools but your response does not start with the required `---` YAML frontmatter. " +
"Either continue using tools to complete your work, or output your final response starting with `---`.";
messages.push({ role: "user", content: nudge });
continue;
}
finalText = text;
break;
}