Skip to content

fix(laya-ts): forward maxLen / headMaxLen through Router.predict - #1338

Merged
NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
thread3d:fix/laya-ts-router-budget
Oct 24, 2026
Merged

NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
thread3d:fix/laya-ts-router-budget

Conversation

@thread3d

Copy link
Copy Markdown
Contributor

What

The per-call token-budget options seed the PredictContext (so a start hook can read and rewrite them) and the values left there are forwarded to the agent, as Python's Router.predict does with ctx.max_len / ctx.head_max_len.

Why

PredictOptions documents per-call budget overrides and Agent.systemOne honours them, but Router.predict never read them -- agentOpts carried only lang and minConfidence -- so the documented per-call budget, and the documented "a start hook may also set them", did nothing on the primary entry point. A caller raising the window on a long state got the checkpoint default and the truncation they were trying to avoid; decide(router, ...) inherited it silently.

How it was verified

cd laya-ts && npx vitest run tests/maxlen.test.ts

Checklist

  • Focused on one change (split unrelated work into another PR)
  • Rebased on the latest main (branch cut from upstream/main at 0.4.14)
  • Tests pass locally
  • Docs or examples updated when the public API changed

PredictOptions documents per-call token-budget overrides and Agent.systemOne honours them,
but Router.predict never read them: the PredictContext was built without maxLen/headMaxLen
and agentOpts carried only lang and minConfidence. So the documented per-call budget -- and
the documented "a start hook may also set them" -- did nothing on the primary entry point,
while Agent.predict honoured both; a caller raising the window on a long state got the
checkpoint default and the truncation they were trying to avoid, and decide(router, ...)
inherited that silently.

The options now seed the context (so a start hook can read and rewrite them, exactly as it
can states/questions) and the values left on the context are forwarded to the agent, which
is what Python's Router.predict does with ctx.max_len / ctx.head_max_len. Nothing is passed
when neither is set, so the agent's own configured budget still applies.
@NandhaKishorM
NandhaKishorM merged commit bba03bc into NandhaKishorM:main Oct 24, 2026
46 of 50 checks passed
NandhaKishorM added a commit that referenced this pull request Oct 24, 2026
33 PRs. Server hardening (#1331, #1332, #1333), TypeScript parity
(#1330, #1336, #1337, #1338, #1339, #1340, #1341, #1342, #1343),
fail-closed input handling in evals and the integrations (#1317, #1318,
#1319, #1320, #1321, #1322, #1326, #1335), exact and faster script
detection (#1334, #1349), JVM and .NET resource handling (#1327, #1328,
#1329, #1346), port goldens and clipping (#1324 excluded, #1325, #1344,
#1345), CI (#1323, #1347, #1348).

Verified before tagging: all 92 suites pass, 610 tests. ruff clean on
both lists. laya-ts 1247 tests across 44 files, tsc --noEmit clean.
Version agrees across pyproject.toml, laya.__version__ and nix/package.nix.
README carries 0.4.15 only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@thread3d
thread3d deleted the fix/laya-ts-router-budget branch October 28, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants