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): run agent in auto mode when no router is loaded

soumojit-D4809ab974a83ff
diff --git a/laya/mcp/tools.py b/laya/mcp/tools.py
index 0f9bea6c..7d55cc6d 100644
--- a/laya/mcp/tools.py
+++ b/laya/mcp/tools.py
@@ -133,9 +133,13 @@ def laya_predict(
def _run() -> Any:
if model_name == "auto":
- if router is None:
- raise ToolError("models_not_ready", "Router is not loaded (auto mode)")
- return router.predict(state_d, questions_d)
+ if router is not None:
+ return router.predict(state_d, questions_d)
+ if agent is not None:
+ # Agent-only auto: no router to resolve the directive, so the
+ # agent answers and the routing fallback reports model None.
+ return agent.predict(state_d, questions_d)
+ raise ToolError("models_not_ready", "Router is not loaded (auto mode)")
if agent is not None:
return agent.predict(state_d, questions_d)
if router is None:
@@ -164,7 +168,7 @@ def laya_predict(
# silent GPU -> CPU fallback. Omitted when it cannot be read, rather than
# guessed.
device = None
- if model_name != "auto" and agent is not None:
+ if agent is not None and (model_name != "auto" or router is None):
device = agent_device(agent)
else:
model_used = routing.get("model")
diff --git a/tests/test_mcp.py b/tests/test_mcp.py
index b290fec6..a9073d80 100644
--- a/tests/test_mcp.py
+++ b/tests/test_mcp.py
@@ -13,6 +13,7 @@ import asyncio
import os
import sys
from pathlib import Path
+from types import SimpleNamespace
os.environ.setdefault("USE_TF", "0")
os.environ.setdefault("USE_TORCH", "1")
@@ -224,6 +225,15 @@ def test_shape():
lambda: laya_predict(STATE, {}, model="auto", router=FakeRouter()),
"invalid_questions")
+ # model="auto" with an Agent and no Router runs the agent and reports no
+ # checkpoint instead of the "auto" routing directive as the model.
+ auto_agent = SimpleNamespace(predict=lambda state, questions: {"answers": {}})
+ out = laya_predict(STATE, QUESTIONS, model="auto", agent=auto_agent)
+ ok("shape/predict_auto_agent_routing",
+ out["routing"] == {"model": None, "repo": None, "reason": "auto routing without router"},
+ repr(out["routing"]))
+ ok("shape/predict_auto_agent_answers", out["answers"] == {}, repr(out["answers"]))
+
def test_real_device():
# agent_device: the real device read from a loaded agent (no weights).