Skip to content

feat(mcp): forward Router lang_guess through the single-request tools - #797

Merged
NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
aashish254:feat-mcp-lang-guess
Oct 1, 2026
Merged

NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
aashish254:feat-mcp-lang-guess

Conversation

@aashish254

Copy link
Copy Markdown
Contributor

What

laya_predict, laya_route, laya_shortlist and laya_preset now accept and forward core's soft language hint, lang_guess, and the MCP tool schemas / descriptions advertise it. A validate_lang_guess is added at the JSON boundary, mirroring validate_lang.

Why

lang_guess is already reachable from every other surface that routes:

Only the single-request MCP tools did not, so a client scoring one state over MCP could nudge the checkpoint with a probable-but-uncertain language only by sending a batch of one. This closes that forwarding gap.

lang_guess is routing-only, so it is treated exactly like task:

  • forwarded to a router call (a soft hint, checked after lang and before built-in detection),
  • refused on a pinned model — there is nothing to route, same as the existing task refusal,
  • stripped on the direct-agent path — Agent.predict does not accept the keyword, so Router.route/predict take it and Agent.predict does not.

validate_lang_guess passes a code string through verbatim and refuses a non-string (including a callable, which core accepts but an MCP client cannot send as JSON).

How it was verified

python tests/test_mcp.py
ruff check laya/ --select=E9,F63,F7,F82,F401,F811 --line-length=120
python -m compileall -q laya/ tests/
  • tests/test_mcp.py: 835 passed, 0 failed. A new test_lang_guess_control suite pins: the validator (verbatim codes, non-string/callable refused as invalid_lang_guess); predict forwards when set / omits when unset / forwards alongside task / keeps lang and lang_guess as distinct keywords; predict and route refuse a pinned model + lang_guess before touching core; the direct-agent path strips it while keeping lang; shortlist sends it to the route and drops it from the answering pass; preset threads it through; and a cross-surface drift guard asserting lang_guess is in serve.BODY_CONTROLS and BATCH_ITEM_OVERRIDES and accepted by Router.route/predict. test_controls_signature_and_schema now also checks the four single tools expose lang_guess as a nullable, defaulted, non-required schema field documented in the description.
  • Mutation check: 6 faithful mutants (agent-no-strip, drop-pinned-refusal, predict-does-not-forward, route-does-not-forward, shortlist-keeps-in-predict, server-drops-param) — 6 killed, 0 survived, each against a named red.

Checklist

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

Note on overlap

This edits laya/mcp/tools.py and laya/mcp/server.py, which my open #766/#770 (batch hooks_timeout/min_confidence/sort_by_length) also touch, at different lines and for different controls — orthogonal, but a rebase may be needed depending on merge order. Related umbrella: #489.

The batch surface, laya-serve and the CLI all forward core's soft language
hint (lang_guess), but the single-request MCP tools did not: a client scoring
one state over MCP could nudge the checkpoint with a probable language only by
sending a batch of one.

lang_guess is routing-only, so it is treated exactly like task: forwarded to a
router call, refused on a pinned model (nothing left to route), and stripped on
the direct-agent path (Agent.predict does not accept it). laya_predict,
laya_route, laya_shortlist and laya_preset now take it, with validate_lang_guess
mirroring validate_lang at the JSON boundary.
@NandhaKishorM
NandhaKishorM merged commit 6e06bba into NandhaKishorM:main Oct 1, 2026
24 of 25 checks passed
@NandhaKishorM

Copy link
Copy Markdown
Owner

Merged for 0.3.23.

Verified on the integrated branch, not on the PR in isolation: every suite in the ci.yml test lane plus the pytest lane green, compileall clean, and a decision diff against main on the real english and multilingual checkpoints (72 answers over choice, score and noul, short and long states, budgeted and predict_long) showing zero decision flips and a max probability delta of 0.000000.

Thank you.

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