fix: add reasoning tag hint for local providers

This commit is contained in:
Peter Steinberger
2025-12-23 14:34:56 +00:00
parent 42f1a56832
commit b05981ef27
3 changed files with 20 additions and 0 deletions

View File

@@ -333,12 +333,15 @@ export async function runEmbeddedPiAgent(params: {
node: process.version,
model: `${provider}/${modelId}`,
};
const reasoningTagHint =
provider === "lmstudio" || provider === "ollama";
const systemPrompt = buildSystemPrompt({
appendPrompt: buildAgentSystemPromptAppend({
workspaceDir: resolvedWorkspace,
defaultThinkLevel: params.thinkLevel,
extraSystemPrompt: params.extraSystemPrompt,
ownerNumbers: params.ownerNumbers,
reasoningTagHint,
runtimeInfo,
}),
contextFiles,

View File

@@ -22,4 +22,14 @@ describe("buildAgentSystemPromptAppend", () => {
expect(prompt).not.toContain("## User Identity");
expect(prompt).not.toContain("Owner numbers:");
});
it("adds reasoning tag hint when enabled", () => {
const prompt = buildAgentSystemPromptAppend({
workspaceDir: "/tmp/clawd",
reasoningTagHint: true,
});
expect(prompt).toContain("## Reasoning Format");
expect(prompt).toContain("<think>...</think>");
});
});

View File

@@ -5,6 +5,7 @@ export function buildAgentSystemPromptAppend(params: {
defaultThinkLevel?: ThinkLevel;
extraSystemPrompt?: string;
ownerNumbers?: string[];
reasoningTagHint?: boolean;
runtimeInfo?: {
host?: string;
os?: string;
@@ -26,6 +27,9 @@ export function buildAgentSystemPromptAppend(params: {
ownerNumbers.length > 0
? `Owner numbers: ${ownerNumbers.join(", ")}. Treat messages from these numbers as the user (Peter).`
: undefined;
const reasoningHint = params.reasoningTagHint
? "If you must think, put all reasoning inside <think>...</think> only, and never include analysis outside those tags."
: undefined;
const runtimeInfo = params.runtimeInfo;
const runtimeLines: string[] = [];
if (runtimeInfo?.host) runtimeLines.push(`Host: ${runtimeInfo.host}`);
@@ -72,6 +76,9 @@ export function buildAgentSystemPromptAppend(params: {
if (extraSystemPrompt) {
lines.push("## Group Chat Context", extraSystemPrompt, "");
}
if (reasoningHint) {
lines.push("## Reasoning Format", reasoningHint, "");
}
lines.push(
"## Heartbeats",