diff --git a/packages/coding-agent/src/core/compaction/branch-summarization.ts b/packages/coding-agent/src/core/compaction/branch-summarization.ts index f1db25e14..69bd75133 100644 --- a/packages/coding-agent/src/core/compaction/branch-summarization.ts +++ b/packages/coding-agent/src/core/compaction/branch-summarization.ts @@ -5,7 +5,7 @@ * a summary of the branch being left so context isn't lost. */ -import type { AgentMessage, StreamFn } from "@earendil-works/pi-agent-core"; +import type { AgentMessage, StreamFn, ThinkingLevel } from "@earendil-works/pi-agent-core"; import type { RetryCallbacks, RetryPolicy } from "@earendil-works/pi-ai"; import { contentText, normalizeContext } from "@earendil-works/pi-ai"; import type { Model, SimpleStreamOptions, Usage } from "@earendil-works/pi-ai/compat"; @@ -75,6 +75,8 @@ export interface GenerateBranchSummaryOptions { env?: Record; /** Abort signal for cancellation */ signal: AbortSignal; + /** Thinking level for reasoning-capable models */ + thinkingLevel?: ThinkingLevel; /** Optional custom instructions for summarization */ customInstructions?: string; /** If true, customInstructions replaces the default prompt instead of being appended */ @@ -300,6 +302,7 @@ export async function generateBranchSummary( headers, env, signal, + thinkingLevel, customInstructions, replaceInstructions, reserveTokens = 16384, @@ -348,6 +351,9 @@ export async function generateBranchSummary( // so transient stream drops reuse the configured retry policy. const context = normalizeContext({ systemPrompt: SUMMARIZATION_SYSTEM_PROMPT, messages: summarizationMessages }); const requestOptions: SimpleStreamOptions = { apiKey, headers, env, signal }; + if (model.reasoning && thinkingLevel && thinkingLevel !== "off") { + requestOptions.reasoning = thinkingLevel; + } const response = await completeSummarization(model, context, requestOptions, streamFn, retry, callbacks); // Check if aborted or errored diff --git a/packages/coding-agent/test/branch-summarization.test.ts b/packages/coding-agent/test/branch-summarization.test.ts index 7018e969f..ade25dbfd 100644 --- a/packages/coding-agent/test/branch-summarization.test.ts +++ b/packages/coding-agent/test/branch-summarization.test.ts @@ -44,6 +44,26 @@ function response(content: AssistantMessage["content"]): AssistantMessage { } describe("branch summarization", () => { + it("passes the thinking level only for reasoning-capable models", async () => { + const seen: Array = []; + const streamFn: StreamFn = (_model, _context, options) => { + seen.push(options?.reasoning); + const stream = createAssistantMessageEventStream(); + queueMicrotask(() => + stream.push({ type: "done", reason: "stop", message: response([{ type: "text", text: "summary" }]) }), + ); + return stream; + }; + const reasoningModel = { ...model, reasoning: true }; + const signal = new AbortController().signal; + + await generateBranchSummary(entries, { model: reasoningModel, signal, streamFn, thinkingLevel: "xhigh" }); + await generateBranchSummary(entries, { model: reasoningModel, signal, streamFn, thinkingLevel: "off" }); + await generateBranchSummary(entries, { model, signal, streamFn, thinkingLevel: "high" }); + + expect(seen).toEqual(["xhigh", undefined, undefined]); + }); + it("does not override tool choice for branch summaries", async () => { let requestOptions: SimpleStreamOptions | undefined; const streamFn: StreamFn = (_model, _context, options) => {