Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Use supported reasoning effort for compaction and judging (#1355)

Regan Bell8ff4f7ae4ac6
diff --git a/src/harness/history-summary.ts b/src/harness/history-summary.ts
index 696a830a2..8dfcd2304 100644
--- a/src/harness/history-summary.ts
+++ b/src/harness/history-summary.ts
@@ -37,7 +37,7 @@ export async function summarizeHistory(
undefined,
SUMMARY_INSTRUCTIONS,
previousSummary?.text,
- "off",
+ "low",
async (summaryModel, context, options) => {
const stream = await streamFn(summaryModel, context, options);
const result = await stream.result();
diff --git a/src/harness/pi-harness.ts b/src/harness/pi-harness.ts
index 220c6a614..eb0eaf081 100644
--- a/src/harness/pi-harness.ts
+++ b/src/harness/pi-harness.ts
@@ -2442,7 +2442,7 @@ export function createPiHarness(opts?: PiHarnessOptions): Harness {
return oneShot("pi-judge", model, providerKeys, systemPrompt, prompt, {
modelGateway,
signal,
- thinkingLevel: "off",
+ thinkingLevel: "low",
});
},
diff --git a/test/history-summary.test.ts b/test/history-summary.test.ts
index 1573b780d..14ca24e97 100644
--- a/test/history-summary.test.ts
+++ b/test/history-summary.test.ts
@@ -1,5 +1,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
+import { zstdDecompressSync } from "node:zlib";
+import { buildModelRuntime } from "../src/harness/pi-harness.ts";
import { contentText, createAssistantMessageEventStream, type StopReason } from "@earendil-works/pi-ai";
import { summarizeHistory } from "../src/harness/history-summary.ts";
import { getRequiredModel } from "../src/model/pi-models.ts";
@@ -105,3 +107,45 @@ test("compaction propagates transport failures and rejects empty output", async
/empty summary/,
);
});
+
+for (const modelId of ["gpt-6-astra", "claude-opus-5", "gpt-4.1"]) {
+ test(`compaction enables low reasoning only when supported by ${modelId}`, async () => {
+ const summaryModel = getRequiredModel(modelId);
+ await summarizeHistory([], summaryModel, (_model, _context, options) => {
+ assert.equal(options?.reasoning, summaryModel.reasoning ? "low" : undefined);
+ return response();
+ });
+ });
+}
+
+test("Astra compaction serializes a supported reasoning effort through the provider adapter", async (t) => {
+ const runtime = await buildModelRuntime({ openai: "sk-offline-test-key" });
+ const originalFetch = globalThis.fetch;
+ t.after(() => {
+ globalThis.fetch = originalFetch;
+ });
+ let request: { model?: string; reasoning?: { effort?: string } } | undefined;
+ globalThis.fetch = (async (_url: string | URL | Request, init?: RequestInit) => {
+ const encoded = new Headers(init?.headers).get("content-encoding") === "zstd";
+ const text = encoded ? zstdDecompressSync(init?.body as Uint8Array).toString() : String(init?.body);
+ request = JSON.parse(text);
+ if (request?.reasoning?.effort !== "low") {
+ return new Response(JSON.stringify({ error: { message: "unsupported reasoning effort" } }), { status: 400 });
+ }
+ const events = [
+ { type: "response.output_item.added", output_index: 0, item: { type: "message", id: "msg_summary" } },
+ { type: "response.output_text.delta", output_index: 0, delta: summary },
+ { type: "response.completed", response: { id: "resp_summary", status: "completed", output: [] } },
+ ];
+ return new Response(events.map((event) => `data: ${JSON.stringify(event)}\n\n`).join(""), {
+ headers: { "content-type": "text/event-stream" },
+ });
+ }) as typeof fetch;
+ const result = await summarizeHistory([], getRequiredModel("gpt-6-astra"), (model, context, options) =>
+ runtime.streamSimple(model, context, { ...options, transport: "sse", maxRetries: 0 }),
+ );
+ assert.equal(result, summary);
+ assert.ok(request, "compaction must reach the provider's HTTP transport");
+ assert.equal(request.model, "gpt-6-astra");
+ assert.equal(request.reasoning?.effort, "low");
+});
diff --git a/test/pi-harness-oneshot.test.ts b/test/pi-harness-oneshot.test.ts
index 82db1e714..b6bc7319e 100644
--- a/test/pi-harness-oneshot.test.ts
+++ b/test/pi-harness-oneshot.test.ts
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
import { readdirSync } from "node:fs";
import { createServer } from "node:http";
import { tmpdir } from "node:os";
+import { zstdDecompressSync } from "node:zlib";
import { getBuiltinModel } from "@earendil-works/pi-ai/providers/all";
import {
buildDetectionPrompt,
@@ -877,3 +878,25 @@ test("resolveConfiguredModelId: an unresolvable default is rejected too, so auxi
getRequiredModel(auxiliaryModelFor(resolveConfiguredModelId(undefined, "anthropic/claude-sonnet-4-5"))),
);
});
+
+test("Pi judge uses supported reasoning effort when configured with Astra", async (t) => {
+ const originalFetch = globalThis.fetch;
+ t.after(() => {
+ globalThis.fetch = originalFetch;
+ });
+ let request: { model?: string; reasoning?: { effort?: string } } | undefined;
+ globalThis.fetch = (async (_url: string | URL | Request, init?: RequestInit) => {
+ const encoded = new Headers(init?.headers).get("content-encoding") === "zstd";
+ const text = encoded ? zstdDecompressSync(init?.body as Uint8Array).toString() : String(init?.body);
+ request = JSON.parse(text);
+ return new Response(JSON.stringify({ error: { message: "offline judge test" } }), { status: 400 });
+ }) as typeof fetch;
+ const harness = createPiHarness({
+ judgeModelId: "gpt-6-astra",
+ resolveProviderKeys: async () => ({ openai: "sk-offline-test-key" }),
+ });
+ await assert.rejects(harness.models.judge!("Judge the answer.", "answer"), /offline judge test/);
+ assert.ok(request);
+ assert.equal(request.model, "gpt-6-astra");
+ assert.equal(request.reasoning?.effort, "low");
+});