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): drop task on the auto+bare-agent predict_long path

Aashishd3b231761b67
diff --git a/laya/mcp/tools.py b/laya/mcp/tools.py
index 63aa0f20..0e870869 100644
--- a/laya/mcp/tools.py
+++ b/laya/mcp/tools.py
@@ -893,10 +893,14 @@ def laya_predict_long(
if agent is None:
raise ToolError("models_not_ready", "Router is not loaded (auto mode)")
# An Agent answers but does not route: run it directly and report
- # a null model below, instead of echoing 'auto' (#444).
+ # a null model below, instead of echoing 'auto' (#444). `Agent.predict_long`
+ # has no `task` parameter -- only a Router routes between checkpoints -- so the
+ # keyword is dropped here exactly as `laya_predict` drops it (`tools.py:415`);
+ # forwarding it would surface as a raw TypeError, not an actionable refusal.
nonlocal auto_without_router
auto_without_router = True
- return _scan(agent, state_d, questions_d, **scan)
+ return _scan(agent, state_d, questions_d,
+ **{k: v for k, v in scan.items() if k != "task"})
return _scan(router, state_d, questions_d, **scan)
if agent is not None:
return _scan(agent, state_d, questions_d, **scan)
diff --git a/tests/test_mcp.py b/tests/test_mcp.py
index 5df5f798..3e2e6406 100644
--- a/tests/test_mcp.py
+++ b/tests/test_mcp.py
@@ -1462,8 +1462,17 @@ class LongAgent:
def __init__(self):
self.seen = None
- def predict_long(self, state, questions, **kwargs):
- self.seen = kwargs
+ def predict_long(self, state, questions, window=None, stride=None, aggregate=None,
+ batch_size=None, lang=None, hooks=None, on_predict_start=None,
+ on_predict_end=None, hooks_raise=None, hooks_timeout=None):
+ # The exact real `Agent.predict_long` signature, with no `**kwargs` and no `task`:
+ # an Agent answers but never routes, so a forwarded `task` must raise rather than be
+ # silently absorbed. Recording only the non-None controls keeps the "unset stays absent"
+ # assertion while letting a wrongly-forwarded keyword reach the tool as a TypeError.
+ self.seen = {k: v for k, v in (
+ ("window", window), ("stride", stride), ("aggregate", aggregate),
+ ("batch_size", batch_size), ("lang", lang),
+ ) if v is not None}
return {"answers": {"refund": {"noul": 0.8, "confidence": 0.7,
"window": {"index": 0, "token_start": 0,
"token_end": 10, "count": 3}}},
@@ -1577,6 +1586,15 @@ def test_predict_long():
repr(out["routing"]))
ok("long/bare_agent_no_device", "device" not in out, repr(out))
+ # Auto + a bare agent + a task: the Agent cannot route between checkpoints, so `task` must be
+ # dropped before the scan. `Agent.predict_long` has no such parameter -- forwarding it surfaces
+ # as a raw TypeError (an opaque internal_error over the tool boundary) instead of an answer.
+ # This is the branch the pinned-model guard at the top of the tool never reaches.
+ agent = LongAgent()
+ out = laya_predict_long(STATE, LONG_QUESTIONS, task="typed_decisions", agent=agent)
+ ok("long/bare_agent_task_dropped", "task" not in agent.seen, repr(agent.seen))
+ ok("long/bare_agent_task_answers", out["answers"]["refund"]["noul"] == 0.8, repr(out))
+
# --- per-call controls: task / lang / max_len / head_max_len -------------------
diff --git a/tests/test_mcp_local_e2e.py b/tests/test_mcp_local_e2e.py
index c5dce6e6..1857e81f 100644
--- a/tests/test_mcp_local_e2e.py
+++ b/tests/test_mcp_local_e2e.py
@@ -2,8 +2,8 @@
Launches ``python -m laya.mcp.server`` as a subprocess and speaks MCP over
stdin/stdout (newline-delimited JSON-RPC), exactly like a real MCP client.
-Exercises laya_predict, laya_predict_batch, laya_route, laya_route_batch, laya_decide,
-laya_preset, laya_shortlist and laya_status against the
+Exercises laya_predict, laya_predict_batch, laya_predict_long, laya_route,
+laya_route_batch, laya_decide, laya_preset, laya_shortlist and laya_status against the
live checkpoints (downloaded via huggingface_hub on first run, cached
afterwards).
@@ -117,8 +117,9 @@ def main():
tools = client.request("tools/list", {})
names = sorted(t["name"] for t in tools.get("tools", []))
ok("e2e/tool_names", names == ["laya_decide", "laya_predict", "laya_predict_batch",
- "laya_preset", "laya_route", "laya_route_batch",
- "laya_shortlist", "laya_status"], repr(names))
+ "laya_predict_long", "laya_preset", "laya_route",
+ "laya_route_batch", "laya_shortlist", "laya_status"],
+ repr(names))
ticket = {
"state": {