Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.
Python calibrationclassificationdecision-modelhuggingfacejevmodernbertmultilingualnlppythonpytorchroutingtyped-decisionszero-shot
fix(mcp): reject broken tournament winners before another pass
Rishit Sharma02782b3ec747
diff --git a/docs/cli-mcp.md b/docs/cli-mcp.mdindex 9efbc614..0eeefb43 100644--- a/docs/cli-mcp.md+++ b/docs/cli-mcp.md@@ -192,6 +192,8 @@ pass answers all three groups; their winners meet in a final pass that also answof the request. Larger sets can take more elimination rounds. The checkpoint is selected fromthe original request and pinned for every round, keeping routing controls and detected-languagecalibration consistent. Token budgets and `min_confidence` reach every pass.+A missing or out-of-group winner returns `internal_error` before another pass, so a broken+round cannot silently advance a label the model did not select from that group.The result has the usual `answers`, `routing`, `latency_ms` and readable `device`, plus`tournament` metadata for each choice: `labels` are the finalists in criteria order, `n` is thediff --git a/laya/mcp/server.py b/laya/mcp/server.pyindex f7baa03c..f2139760 100644--- a/laya/mcp/server.py+++ b/laya/mcp/server.py@@ -451,8 +451,9 @@ def laya_shortlist_tool("Answer large choice questions by balanced elimination with the decision model, without ""embeddings. group_size: integer at least 2, default 16. All groups share one forward ""pass per round; their winners advance until they fit, then one final pass answers the "- "complete request. Small choices and non-choice questions pass through. Returns answers, "- "routing, total latency_ms, the answering device when readable, and tournament metadata "+ "complete request. Small choices and non-choice questions pass through. "+ "A missing or out-of-group winner stops the call as internal_error before another pass. "+ "Returns answers, routing, total latency_ms, the answering device when readable, and tournament metadata ""per choice: labels (finalists in criteria order), n (original option count), rounds ""(elimination rounds, zero on passthrough). Probabilities and confidence are over the ""finalists only; thresholds fitted on a full option set do not transfer. A narrowed "diff --git a/laya/mcp/tools.py b/laya/mcp/tools.pyindex 6da68225..d079a58d 100644--- a/laya/mcp/tools.py+++ b/laya/mcp/tools.py@@ -929,8 +929,17 @@ def laya_tournament(class Predictor:def predict(self, round_state, round_questions):- return laya_predict(round_state, round_questions, model=model_name,- router=router, agent=predict_agent, **forward)+ result = laya_predict(round_state, round_questions, model=model_name,+ router=router, agent=predict_agent, **forward)+ for name, spec in round_questions.items():+ if spec["type"] != "choice":+ continue+ answer = result["answers"].get(name)+ if (not isinstance(answer, dict) or not isinstance(answer.get("choice"), str)+ or answer["choice"] not in spec["criteria"]):+ raise ToolError("internal_error",+ f"tournament prediction for question {name!r} must return a choice from its criteria")+ return resultout = predict_tournament(Predictor(), state_d, questions_d, group_size=group_size)if routing is not None:diff --git a/tests/test_mcp.py b/tests/test_mcp.pyindex ad79529d..60bca110 100644--- a/tests/test_mcp.py+++ b/tests/test_mcp.py@@ -1107,6 +1107,39 @@ def test_tournament():ok("tournament/non_choice_one_call", len(agent.calls) == 1 and out["tournament"] == {})+def test_tournament_rejects_broken_winners():+ for bad in (None, {}, {"choice": "opt39"}, {"choice": "unknown"},+ {"choice": ["opt39"]}, {"choice": 39}):+ class BrokenAgent(TournamentAgent):+ def predict(self, state, questions, **kwargs):+ result = super().predict(state, questions, **kwargs)+ if len(self.calls) == 1:+ if bad is None:+ del result["answers"]["0"]+ else:+ result["answers"]["0"] = bad+ return result++ agent = BrokenAgent()+ expect_tool_error("tournament/broken_winner_%r" % bad,+ lambda: laya_tournament(STATE, tournament_questions(40),+ model="english", agent=agent), "internal_error")+ ok("tournament/broken_winner_stops_round_%r" % bad, len(agent.calls) == 1)++ class BrokenRecursiveAgent(TournamentAgent):+ def predict(self, state, questions, **kwargs):+ result = super().predict(state, questions, **kwargs)+ if len(self.calls) == 2:+ result["answers"]["0"]["choice"] = "opt256"+ return result++ agent = BrokenRecursiveAgent()+ expect_tool_error("tournament/recursive_out_of_group_winner",+ lambda: laya_tournament(STATE, tournament_questions(257),+ model="english", agent=agent), "internal_error")+ ok("tournament/recursive_broken_winner_stops_round", len(agent.calls) == 2)++def test_tournament_routing_and_validation():questions = tournament_questions(40)for detection in ({"language": "de"}, SimpleNamespace(language="de")):@@ -3120,6 +3153,7 @@ test_question_forwarding()test_option_order_forwarding()test_shortlist()test_tournament()+test_tournament_rejects_broken_winners()test_tournament_routing_and_validation()test_batch_validation()test_batch_predict()