Skip to content

armgit / laya

Public Imported from GitHub
0

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.

fix(mcp): preserve supported question fields

dakjdakdd0776d7b30c9
diff --git a/laya/mcp/server.py b/laya/mcp/server.py
index eea0847a..2d691c24 100644
--- a/laya/mcp/server.py
+++ b/laya/mcp/server.py
@@ -180,6 +180,7 @@ def laya_route_tool(state: dict, questions: dict) -> str:
description=(
"Answer typed questions (choice/score/noul) over any state in one forward pass. "
"questions: {name: {type: 'choice'|'score'|'noul', instructions: str, criteria?: object|array}}. "
+ "For noul, optional labels: {false: str, true: str} changes the model-facing option text. "
"Returns answers with confidence, routing metadata and, when it can be read, the real "
"device of the checkpoint that answered. "
+ _GUARDRAILS
diff --git a/laya/mcp/tools.py b/laya/mcp/tools.py
index b3fc6b74..8b9a3366 100644
--- a/laya/mcp/tools.py
+++ b/laya/mcp/tools.py
@@ -63,14 +63,14 @@ def validate_questions(questions: Any) -> dict:
"invalid_questions",
f"questions[{name}].criteria must be a non-empty object of label -> description",
)
- entry["criteria"] = {str(k): str(v) for k, v in criteria.items()}
+ entry["criteria"] = {str(k): v for k, v in criteria.items()}
elif qtype == "score":
if not isinstance(criteria, list) or not criteria:
raise ToolError(
"invalid_questions",
f"questions[{name}].criteria must be a non-empty list of rubric levels",
)
- entry["criteria"] = [str(x) for x in criteria]
+ entry["criteria"] = list(criteria)
else: # noul
if criteria is not None:
if not isinstance(criteria, dict):
@@ -78,7 +78,9 @@ def validate_questions(questions: Any) -> dict:
"invalid_questions",
f"questions[{name}].criteria must be an object when present (noul)",
)
- entry["criteria"] = {str(k): str(v) for k, v in criteria.items()}
+ entry["criteria"] = {str(k): v for k, v in criteria.items()}
+ if "labels" in spec:
+ entry["labels"] = spec["labels"]
cleaned[name] = entry
return cleaned
diff --git a/tests/test_mcp.py b/tests/test_mcp.py
index b290fec6..5e9411e4 100644
--- a/tests/test_mcp.py
+++ b/tests/test_mcp.py
@@ -225,6 +225,33 @@ def test_shape():
"invalid_questions")
+def test_question_forwarding():
+ questions = {
+ "intent": {"type": "choice", "instructions": "Which intent?",
+ "criteria": {"A": None, "B": {"desc": "billing"}}},
+ "urgency": {"type": "score", "instructions": "How urgent?",
+ "criteria": ["low", {"desc": "blocking"}]},
+ "positive": {"type": "noul", "instructions": "Is this positive?",
+ "criteria": {"false": None, "true": "yes"},
+ "labels": {"false": "B", "true": "A"}},
+ }
+
+ class CapturingRouter(FakeRouter):
+ def predict(self, state, received, **kwargs):
+ self.predicted_questions = received
+ return super().predict(state, received, **kwargs)
+
+ def route(self, state, received):
+ self.routed_questions = received
+ return super().route(state, received)
+
+ router = CapturingRouter()
+ laya_predict(STATE, questions, router=router)
+ laya_route(STATE, questions, router=router)
+ ok("questions/predict_preserves_supported_values", router.predicted_questions == questions)
+ ok("questions/route_preserves_supported_values", router.routed_questions == questions)
+
+
def test_real_device():
# agent_device: the real device read from a loaded agent (no weights).
ok("device/agent_str", agent_device(FakeAgent()) == "cpu")
@@ -344,6 +371,8 @@ def test_server_registration():
# laya_status reports instead of deciding.
if t.name in decision:
ok("server/desc_%s_guardrail" % t.name, "do not use" in desc)
+ if t.name == "laya_predict":
+ ok("server/desc_noul_labels", "optional labels" in desc)
test_device()
@@ -351,6 +380,7 @@ test_real_device()
test_private_contract()
test_schema()
test_shape()
+test_question_forwarding()
test_timeout_removed()
test_models_from_env()
test_server_registration()