openzoo 0.48.56 → 0.48.58

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.
Files changed (2) hide show
  1. package/lib/proxy.js +40 -8
  2. package/package.json +1 -1
package/lib/proxy.js CHANGED
@@ -406,10 +406,36 @@ async function spillTranscript(body, log, req) {
406
406
  // saving — a bigger tail is a bigger `sent` — and that is the correct trade:
407
407
  // measured 8.13x on the fleet leaves room to spend some of it on an agent
408
408
  // that remembers its own last few moves.
409
- const minTurns = Number(process.env.OPENZOO_TAIL_MIN_TURNS || 12);
410
- if (msgs.length - cut < minTurns) {
411
- for (let i = Math.max(firstSpillable + 1, msgs.length - minTurns); i > firstSpillable; i--) {
412
- if (severable(i)) { cut = i; break; }
409
+ // 12 was set while the model was ALSO missing its own last turn to a brief
410
+ // spliced in behind it (fixed in 0.48.56), so part of that floor was paying
411
+ // for a bug rather than for coherence. 6 turns still covers "what did I just
412
+ // do" the case retrieval cannot answer, because the model does not know to
413
+ // query for it — and hands the rest back as saving.
414
+ // COUNT CONVERSATION TURNS, NOT MESSAGES.
415
+ //
416
+ // A tool round trip is TWO messages (assistant tool_call + tool result), so a
417
+ // floor of 6 messages is three tool calls and nothing else — the agent loses
418
+ // the human turn that started the run and every decision it made along the
419
+ // way. OBSERVED: "it's when he calls a bunch of tools, he gets lost."
420
+ //
421
+ // So the floor is measured in user/assistant turns and tool traffic rides
422
+ // along for free. A tool-heavy stretch therefore widens the window instead of
423
+ // consuming it, which is the opposite of the old behaviour and the whole
424
+ // point: what the agent needs verbatim is what it DID, and doing things is
425
+ // exactly what fills the window with tool messages.
426
+ const minTurns = Number(process.env.OPENZOO_TAIL_MIN_TURNS || 6);
427
+ const realTurns = (from) => {
428
+ let n = 0;
429
+ for (let i = from; i < msgs.length; i++) {
430
+ const r = msgs[i]?.role;
431
+ if (r === 'user' || r === 'assistant') n += 1;
432
+ }
433
+ return n;
434
+ };
435
+ if (realTurns(cut) < minTurns) {
436
+ for (let i = cut - 1; i > firstSpillable; i--) {
437
+ if (severable(i) && realTurns(i) >= minTurns) { cut = i; break; }
438
+ if (i === firstSpillable + 1) { if (severable(i)) cut = i; break; }
413
439
  }
414
440
  }
415
441
 
@@ -534,12 +560,18 @@ async function spillTranscript(body, log, req) {
534
560
  // far less context than a detailed one — and is clamped so a huge ask cannot
535
561
  // drag the whole corpus back in.
536
562
  const askChars = msgText(msgs[msgs.length - 1] || {}).length;
563
+ // BREADTH IS THE LEVER, AND MORE OF IT IS WORSE. MEASURED on a 56,265-token
564
+ // corpus: top_k 32 handed back 9,990 tokens and scored 2.45x, top_k 8 handed
565
+ // back 2,574 and scored 4.73x — same question, same answer, nearly double the
566
+ // saving. Spilling 34k tokens to recall 22k of them back is a round trip, not
567
+ // a saving. So budget the recall tighter and cap k where the measurement says
568
+ // the value is, rather than at the largest number that still fits.
537
569
  const budget = Math.min(
538
- Number(process.env.OPENZOO_RECALL_MAX_TOKENS || 6000),
539
- Math.max(Number(process.env.OPENZOO_RECALL_MIN_TOKENS || 1500),
540
- Math.round(askChars / 2)),
570
+ Number(process.env.OPENZOO_RECALL_MAX_TOKENS || 3000),
571
+ Math.max(Number(process.env.OPENZOO_RECALL_MIN_TOKENS || 1200),
572
+ Math.round(askChars / 3)),
541
573
  );
542
- const topK = Math.max(4, Math.min(32, Math.round(budget / 320)));
574
+ const topK = Math.max(4, Math.min(12, Math.round(budget / 320)));
543
575
 
544
576
  return {
545
577
  body: Buffer.from(JSON.stringify({ ...body, messages: [...head, ...msgs.slice(cut)] })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openzoo",
3
- "version": "0.48.56",
3
+ "version": "0.48.58",
4
4
  "description": "Local x402-paying proxy + MCP server for openzoo.fun — point any OpenAI-compatible harness (Cursor, Claude Code, aider, SDKs) at localhost and it pays per call from a local burner wallet. Solana and Base rails live; Robinhood experimental.",
5
5
  "license": "MIT",
6
6
  "type": "module",