@apo-ai/sdk 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1307,6 +1307,13 @@ type JudgeConfig = {
1307
1307
  * dual behavior (second judge as parallel, evidence-only shadow).
1308
1308
  */
1309
1309
  mode?: "cascade";
1310
+ /**
1311
+ * Sampling temperature for `t.judge` requests (not `t.agent`, whose session
1312
+ * stays at 0). Unset falls back to `APO_JUDGE_TEMPERATURE`, then `0`. Some
1313
+ * reasoning models recommend a non-zero value (DeepSeek: 0.6) to avoid
1314
+ * repetition at greedy decoding. Recorded on the check's judge metadata.
1315
+ */
1316
+ temperature?: number;
1310
1317
  };
1311
1318
  /**
1312
1319
  * What a check knows about its scope when it invokes the judge — the
@@ -1262,6 +1262,16 @@ function runWithSharedPrefix(key, task2) {
1262
1262
  };
1263
1263
  return lane.warmed.then(acquire).then(() => task2().finally(release));
1264
1264
  }
1265
+ function judgeTemperature(configured) {
1266
+ const raw = process.env.APO_JUDGE_TEMPERATURE?.trim();
1267
+ const fromEnv = raw ? Number(raw) : void 0;
1268
+ const value = configured ?? fromEnv ?? 0;
1269
+ if (!Number.isFinite(value) || value < 0 || value > 2) {
1270
+ const source = configured !== void 0 ? "judge.temperature" : "APO_JUDGE_TEMPERATURE";
1271
+ throw new Error(`${source} must be a number between 0 and 2, got ${configured ?? raw}`);
1272
+ }
1273
+ return value;
1274
+ }
1265
1275
  function defaultJudgeBaseURL(baseURL) {
1266
1276
  return baseURL ?? process.env.OPENROUTER_BASE_URL ?? "https://openrouter.ai/api/v1";
1267
1277
  }
@@ -1271,6 +1281,7 @@ function defaultJudgeAPIKey(apiKey) {
1271
1281
  async function callJudge(args) {
1272
1282
  const baseURL = defaultJudgeBaseURL(args.baseURL);
1273
1283
  const apiKey = defaultJudgeAPIKey(args.apiKey);
1284
+ const temperature = judgeTemperature(args.temperature);
1274
1285
  const { briefingText, instructionText, systemPromptText, deliverableText, secondJudgeState, secondJudgeProjected } = buildJudgePromptParts({
1275
1286
  values: args.values,
1276
1287
  instruction: args.instruction,
@@ -1304,7 +1315,7 @@ async function callJudge(args) {
1304
1315
  },
1305
1316
  { role: "user", content: instructionText }
1306
1317
  ],
1307
- temperature: 0,
1318
+ temperature,
1308
1319
  response_format: schema ? judgeResponseFormat() : JSON_OBJECT_FORMAT,
1309
1320
  ...stream ? { stream: true, stream_options: { include_usage: true } } : {}
1310
1321
  });
@@ -1427,6 +1438,7 @@ async function callJudge(args) {
1427
1438
  }
1428
1439
  const judgeMetadata = async (completion) => ({
1429
1440
  model: args.model,
1441
+ temperature,
1430
1442
  contract: judgeContractInUse(),
1431
1443
  prompt: { system: systemPromptText, user: instructionText },
1432
1444
  ...completion ? { response: completion.text, tokens: parseJudgeUsage(completion.usage) } : {},
@@ -2541,7 +2553,8 @@ function resolveJudgeConfig(judgeConfig, override) {
2541
2553
  baseURL: override?.baseURL ?? judgeConfig?.baseURL,
2542
2554
  apiKey: override?.apiKey ?? judgeConfig?.apiKey,
2543
2555
  prompt: override?.prompt ?? judgeConfig?.prompt,
2544
- mode: override?.mode ?? judgeConfig?.mode
2556
+ mode: override?.mode ?? judgeConfig?.mode,
2557
+ temperature: override?.temperature ?? judgeConfig?.temperature
2545
2558
  };
2546
2559
  }
2547
2560
  var TEST_METHOD_NAMES = [
@@ -2650,6 +2663,18 @@ function createJudgeMethod(rec, judgeConfig, judgeScope, judgeTracer) {
2650
2663
  );
2651
2664
  return;
2652
2665
  }
2666
+ try {
2667
+ judgeTemperature(effective.temperature);
2668
+ } catch (error) {
2669
+ rec.record(label, false, `judge failed: ${error instanceof Error ? error.message : String(error)}`, {
2670
+ evaluator_type: "llm",
2671
+ expected: instruction,
2672
+ received: valueArray.length === 1 ? valueArray[0] : valueArray,
2673
+ location,
2674
+ outcome: "error"
2675
+ });
2676
+ return;
2677
+ }
2653
2678
  const context2 = judgeScopeToContext(judgeScope);
2654
2679
  const judgeServing = servingHostFromBaseURL(effective.baseURL);
2655
2680
  const secondJudgeValue = opts?.secondJudgeValue;
@@ -2706,6 +2731,7 @@ function createJudgeMethod(rec, judgeConfig, judgeScope, judgeTracer) {
2706
2731
  baseURL: effective.baseURL,
2707
2732
  apiKey: effective.apiKey,
2708
2733
  prompt: effective.prompt,
2734
+ ...effective.temperature !== void 0 ? { temperature: effective.temperature } : {},
2709
2735
  ...context2 ? { context: context2 } : {},
2710
2736
  ...prefetchedSecondJudge ? { prefetchedSecondJudge } : {},
2711
2737
  ...secondJudgeValue !== void 0 ? {