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(integrations): give the agno wrapper the two Router-only controls

Nandakishorc65b3221ca55
diff --git a/laya/integrations/agno.py b/laya/integrations/agno.py
index 1d121c6a..81c5ca4e 100644
--- a/laya/integrations/agno.py
+++ b/laya/integrations/agno.py
@@ -86,6 +86,9 @@ except ImportError:
from ._controls import budget_kwargs as _budget_kwargs, hook_kwargs as _hook_kwargs # noqa: E402
from ._controls import decision_kwargs as _decision_kwargs # noqa: E402
from ._controls import predict_kwargs as _predict_kwargs, reject_remote_hooks as _reject_remote_hooks # noqa: E402
+from ._controls import reject_remote_lang_guess as _reject_remote_lang_guess # noqa: E402
+from ._controls import require_router_controls as _require_router_controls # noqa: E402
+from ._controls import router_kwargs as _router_kwargs # noqa: E402
from ._guard import score_violation_probability as _score_violation_probability # noqa: E402
from ..confidence import _gate_confidence # noqa: E402
@@ -351,6 +354,8 @@ def _execute_decision(
head_max_len: Optional[int] = None,
lang: Optional[str] = None,
min_confidence: Optional[float] = None,
+ task: Optional[str] = None,
+ lang_guess: Optional[Any] = None,
hooks: Optional[Any] = None,
on_predict_start: Optional[Any] = None,
on_predict_end: Optional[Any] = None,
@@ -364,14 +369,17 @@ def _execute_decision(
``predict`` call and the same request body.
"""
hook_kwargs = _hook_kwargs(hooks, on_predict_start, on_predict_end, hooks_raise, hooks_timeout)
+ router_kwargs = _router_kwargs(task, lang_guess)
if base_url:
_reject_remote_hooks(hook_kwargs, base_url)
+ _reject_remote_lang_guess(router_kwargs, base_url)
budget = _budget_kwargs(max_len, head_max_len)
decision = _decision_kwargs(lang, min_confidence)
return _call_remote(base_url, state, questions, api_key=api_key, model=model,
- **budget, **decision)
+ **budget, **decision, **router_kwargs)
runner = agent if agent is not None else _get_default_router()
kwargs = _predict_kwargs(model, max_len, head_max_len, lang, min_confidence)
+ kwargs.update(_require_router_controls(runner, "predict", router_kwargs))
kwargs.update(hook_kwargs)
return runner.predict(state, questions, **kwargs)
@@ -434,6 +442,8 @@ class LayaAgnoRouter:
head_max_len: Optional[int] = None,
lang: Optional[str] = None,
min_confidence: Optional[float] = None,
+ task: Optional[str] = None,
+ lang_guess: Optional[Any] = None,
hooks: Optional[Any] = None,
on_predict_start: Optional[Any] = None,
on_predict_end: Optional[Any] = None,
@@ -452,6 +462,8 @@ class LayaAgnoRouter:
self.head_max_len = head_max_len
self.lang = lang
self.min_confidence = min_confidence
+ self.task = task
+ self.lang_guess = lang_guess
self.hooks = hooks
self.on_predict_start = on_predict_start
self.on_predict_end = on_predict_end
@@ -510,6 +522,8 @@ class LayaAgnoRouter:
head_max_len=self.head_max_len,
lang=self.lang,
min_confidence=self.min_confidence,
+ task=self.task,
+ lang_guess=self.lang_guess,
hooks=self.hooks,
on_predict_start=self.on_predict_start,
on_predict_end=self.on_predict_end,
@@ -702,6 +716,8 @@ class LayaAgnoGuardrail:
head_max_len: Optional[int] = None,
lang: Optional[str] = None,
min_confidence: Optional[float] = None,
+ task: Optional[str] = None,
+ lang_guess: Optional[Any] = None,
hooks: Optional[Any] = None,
on_predict_start: Optional[Any] = None,
on_predict_end: Optional[Any] = None,
@@ -722,6 +738,8 @@ class LayaAgnoGuardrail:
self.head_max_len = head_max_len
self.lang = lang
self.min_confidence = min_confidence
+ self.task = task
+ self.lang_guess = lang_guess
self.hooks = hooks
self.on_predict_start = on_predict_start
self.on_predict_end = on_predict_end
@@ -761,6 +779,8 @@ class LayaAgnoGuardrail:
head_max_len=self.head_max_len,
lang=self.lang,
min_confidence=self.min_confidence,
+ task=self.task,
+ lang_guess=self.lang_guess,
hooks=self.hooks,
on_predict_start=self.on_predict_start,
on_predict_end=self.on_predict_end,
diff --git a/tests/test_agno.py b/tests/test_agno.py
index a5509078..0d9a4bfe 100644
--- a/tests/test_agno.py
+++ b/tests/test_agno.py
@@ -494,6 +494,12 @@ CONTROLS = (
+ tuple(_controls.HOOK_CONTROLS)
)
+# `task` and `lang_guess` are kept out of `CONTROLS` on purpose: the checks below assert that
+# every name in it is read by `Agent.system_one` AND `Router.predict`, and these two are read by
+# the Router alone. They still have to reach this wrapper, so the signature checks use the union.
+ROUTER_CONTROLS = tuple(_controls.ROUTER_ONLY_CONTROLS)
+EVERY_CONTROL = CONTROLS + ROUTER_CONTROLS
+
def _params(fn):
return set(inspect.signature(fn).parameters)
@@ -516,14 +522,14 @@ for _c in CONTROLS:
# Both public classes must accept all controls in __init__.
for cls in (LayaAgnoRouter, LayaAgnoGuardrail):
- for _c in CONTROLS:
+ for _c in EVERY_CONTROL:
check_true("controls/%s takes %s" % (cls.__name__, _c), _c in _params(cls.__init__))
# The agno _execute_decision must accept exactly the same set as the other integrations.
check("controls/_execute_decision takes every control",
set(_params(agno_module._execute_decision)) - {"state", "questions", "agent",
"base_url", "api_key", "model"},
- set(CONTROLS))
+ set(EVERY_CONTROL))
# All four integrations must agree on the _execute_decision signature.
for _mod in (langchain_module, llamaindex_module, crewai_module):