Skip to content

feat(integrations): forward lang and min_confidence through the framework wrappers - #798

Merged
NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
aashish254:feat-integrations-routing-controls
Oct 1, 2026
Merged

NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
aashish254:feat-integrations-routing-controls

Conversation

@aashish254

Copy link
Copy Markdown
Contributor

What

Threads core's lang and min_confidence per-request controls through the LangChain, CrewAI and LlamaIndex wrappers, on both the local predict path and the laya-serve request body.

  • laya/integrations/_controls.py gains DECISION_CONTROLS = ("lang", "min_confidence") and a decision_kwargs(...) builder; predict_kwargs(...) now accepts and forwards both.
  • Every wrapper class (LayaRouter, LayaGuardrail, LayaTriage, LayaEvaluator, LayaCrewRouter, LayaTaskGuard, LayaSingleSelector, LayaMultiSelector, LayaQueryRouter), its _execute_decision and its _call_remote now carry both.

Why

The three wrappers already forwarded the two token budgets and the five hook arguments, but silently dropped lang and min_confidence. So a graph node could not pin the language it routes and answers in (selecting the answering checkpoint's per-language calibration rather than built-in detection), nor honor core's abstention gate on a decision it is not confident about.

Both controls are read by Agent.predict/system_one and Router.predict, and both are laya-serve BODY_CONTROLS, so -- unlike the Router-only task / lang_guess keywords -- the same kwargs are safe on the local and the remote path. An unset value is omitted rather than sent as None so it cannot shadow the checkpoint's own default, while a real falsy value (min_confidence=0.0, lang="") is forwarded as given.

Scope is the per-decision path. Batch is left unchanged because Router.predict_batch takes no per-request min_confidence.

How it was verified

python tests/test_crewai.py      # PASS: 113  FAIL: 0
python tests/test_llamaindex.py  # PASS: 142  FAIL: 0
python tests/test_langchain.py   # PASS: 258  FAIL: 0
ruff check laya/ --select=E9,F63,F7,F82,F401,F811 --line-length=120   # All checks passed
python -m compileall laya/integrations/

The guard suites enumerate every control out of _controls and read the forwarding back off a recording runner and a mocked urllib body, so a control added to the shared module without reaching a wrapper fails that wrapper's suite. A 5-mutant check (drop the executor's local forward on each of the three integrations, drop the remote **decision, drop the min_confidence body write, and weaken decision_kwargs' is not None to truthiness) produced a named FAIL in each owning suite.

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

Fixes #

…work wrappers

The LangChain, CrewAI and LlamaIndex wrappers forwarded the token budgets
and hook controls but dropped core's `lang` and `min_confidence`, so a node
could not pin the routing/answering language or honor the abstention gate.

Both are read by Agent.predict/system_one AND Router.predict, and both are
laya-serve BODY_CONTROLS, so they are safe on the local and remote path
alike (unlike the Router-only task/lang_guess keywords). Add them to the
shared _controls module as DECISION_CONTROLS + decision_kwargs, wire them
through every wrapper class, _execute_decision and _call_remote, omitting an
unset value so it never shadows the checkpoint's default while a real falsy
value (min_confidence=0.0, lang="") survives.

Scope is the per-decision path; batch is left as-is because
Router.predict_batch takes no per-request min_confidence.

Tests: test_crewai 113, test_llamaindex 142, test_langchain 258 pass; ruff
CI select and compileall clean; 5/5 mutation checks killed with named fails.
@NandhaKishorM
NandhaKishorM merged commit 3b0ea92 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