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(agno): address reviewer contract mismatches before merge
VinayChaudhari1996be86d4ae8cb7
diff --git a/docs/agno.md b/docs/agno.mdindex 2603a011..39c27f67 100644--- a/docs/agno.md+++ b/docs/agno.md@@ -17,6 +17,8 @@ Supports both **local in-process inference** (`Agent` or `Router`) and **remotepip install "laya[agno]"```+Requires **`agno>=1.0.0`** (the version that introduced `Team(members=..., mode=TeamMode.route)`).+---## 1. Sub-35ms Agent & Team Routing (`LayaAgnoRouter`)@@ -26,6 +28,7 @@ In Agno multi-agent teams configured with `Team(mode="route")`, a leader LLM eva```pythonfrom agno.agent import Agentfrom agno.team import Team+from agno.team.mode import TeamModefrom laya.integrations.agno import LayaAgnoRouter# Define specialized worker agents@@ -56,11 +59,11 @@ router = LayaAgnoRouter(query = "Write a Python function to reverse a linked list and handle edge cases."# Route and select agent in ~33ms:-decision = router.route(query, agents)+decision = router.route(query, agents) # or equivalently: router.run(query, agents)print(f"Routed to: {decision.name} (Role: {decision.role}, Confidence: {decision.confidence:.3f})")-# Direct Agno Team helper:-team = Team(agents=agents, mode="route")+# Direct Agno Team helper — note: current Agno uses members=, not agents=:+team = Team(members=agents, mode=TeamMode.route)team_decision = router.route_team(query, team)print(f"Team decision: {team_decision.name}")```diff --git a/examples/agno_quickstart.py b/examples/agno_quickstart.pyindex cb46e581..9919d081 100644--- a/examples/agno_quickstart.py+++ b/examples/agno_quickstart.py@@ -124,7 +124,7 @@ print(f"Reason: {decision.reason}")# Directly pass an Agno Team instance with specialist agents:team = AgnoTeam(- agents=[financial_agent, coder_agent, writer_agent],+ members=[financial_agent, coder_agent, writer_agent],mode="route",)diff --git a/laya/integrations/agno.py b/laya/integrations/agno.pyindex 050606f6..bef9021e 100644--- a/laya/integrations/agno.py+++ b/laya/integrations/agno.py@@ -62,13 +62,19 @@ except ImportError:@dataclassclass AgnoTeam: # type: ignore[no-redef]- """Lightweight shim when ``agno`` is not installed."""- agents: List[Any] = None # type: ignore[assignment]+ """Lightweight shim when ``agno`` is not installed.++ Uses ``members`` to match the current Agno ``Team`` contract+ (``Team(members=[...], mode=TeamMode.route)``). The legacy field+ name ``agents`` is accepted in :meth:`route_team` for compatibility+ with older hand-crafted dicts or mocked objects.+ """+ members: List[Any] = None # type: ignore[assignment]mode: str = "route"def __post_init__(self):- if self.agents is None:- self.agents = []+ if self.members is None:+ self.members = []# ---------------------------------------------------------------------------@@ -583,20 +589,47 @@ class LayaAgnoRouter:message: Any,team: AgnoTeam,) -> AgnoRouteDecision:- """Convenience wrapper: route *message* using agents from an ``AgnoTeam``.+ """Convenience wrapper: route *message* using members from an ``AgnoTeam``.- This is a thin call through to :meth:`route` using ``team.agents``.- If *team* carries no agents a :exc:`ValueError` is raised.+ Reads ``team.members`` (the current Agno ``Team`` contract, ``agno>=1.0.0``)+ with a compat fallback to ``team.agents`` for hand-crafted mocks or test+ objects using the old attribute name. Members may also be a callable factory+ (Agno supports dynamic member lists); it is called with no arguments.Args:message: The message to route.- team: An ``AgnoTeam`` instance whose ``.agents`` list is used as the- candidate pool.+ team: An ``AgnoTeam`` instance (``Team(members=[...], mode=TeamMode.route)``).Returns::class:`AgnoRouteDecision` with the selected agent and confidence."""- agents = getattr(team, "agents", None) or []+ # Primary: current Agno Team API (>=1.0.0) uses .members+ members = getattr(team, "members", None)+ if not members:+ # Compat fallback for hand-crafted dicts / mocks using the old .agents attribute+ members = getattr(team, "agents", None) or []+ # Agno supports a callable factory for dynamic member lists+ if callable(members):+ members = members()+ return self.route(message, members)++ def run(+ self,+ message: Any,+ agents: Sequence[Union[AgnoAgent, Dict[str, Any], str, Any]],+ ) -> AgnoRouteDecision:+ """Route *message* and return the selected :class:`AgnoRouteDecision`.++ Alias for :meth:`route`; provided so that ``LayaAgnoRouter`` follows+ the ``agent.run()`` calling convention used throughout Agno.+ """+ return self.route(message, agents)++ def __call__(+ self,+ message: Any,+ agents: Sequence[Union[AgnoAgent, Dict[str, Any], str, Any]],+ ) -> AgnoRouteDecision:return self.route(message, agents)async def aroute(@@ -612,9 +645,21 @@ class LayaAgnoRouter:message: Any,team: AgnoTeam,) -> AgnoRouteDecision:- """Asynchronously route *message* using agents from an ``AgnoTeam``."""+ """Asynchronously route *message* using members from an ``AgnoTeam``."""return await asyncio.to_thread(self.route_team, message, team)+ async def arun(+ self,+ message: Any,+ agents: Sequence[Union[AgnoAgent, Dict[str, Any], str, Any]],+ ) -> AgnoRouteDecision:+ """Asynchronously route *message* without blocking the event loop.++ Alias for :meth:`aroute`; provided to match Agno's ``agent.arun()``+ calling convention.+ """+ return await asyncio.to_thread(self.route, message, agents)+class LayaAgnoGuardrail:"""Sub-40ms inline content guardrail for Agno agent messages.diff --git a/pyproject.toml b/pyproject.tomlindex a1f5d612..e59608a3 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -78,7 +78,7 @@ crewai = [# `pip install laya[agno]` adds the Agno multi-agent team routing and guardrail integration (laya.integrations).agno = [- "agno>=0.7.0",+ "agno>=1.0.0,<2",][project.scripts]diff --git a/tests/test_agno.py b/tests/test_agno.pyindex 7041042a..87e10b6b 100644--- a/tests/test_agno.py+++ b/tests/test_agno.py@@ -192,12 +192,34 @@ check("router/name_2", dec2.name, "Coder")dec1 = router.route("Draft a blog post about machine learning", agents)check("router/agent_index_1", dec1.agent_index, 1)-# route_team convenience method-team_obj = AgnoTeam(agents=agents, mode="route")+# route_team convenience method — current Agno API: members= (agno>=1.0.0)+team_obj = AgnoTeam(members=agents, mode="route")dec_team = router.route_team("Find recent research papers on LLMs", team_obj)check("router/route_team_index", dec_team.agent_index, 0)check("router/route_team_name", dec_team.name, "Researcher")+# route_team compat: older mocked objects may use .agents fallback+class _OldStyleTeam:+ def __init__(self, a):+ self.agents = a+ self.mode = "route"+_old_team = _OldStyleTeam(agents)+dec_old = router.route_team("Find recent research papers on LLMs", _old_team)+check("router/route_team_compat_index", dec_old.agent_index, 0)+check("router/route_team_compat_name", dec_old.name, "Researcher")++# route_team with callable factory for dynamic member lists+class _CallableTeam:+ def __init__(self, a):+ self._members = a+ self.mode = "route"+ @property+ def members(self):+ return lambda: self._members # callable factory+_callable_team = _CallableTeam(agents)+dec_callable = router.route_team("Find recent research papers on LLMs", _callable_team)+check("router/route_team_callable_index", dec_callable.agent_index, 0)+# Empty agents validationtry:router.route("any message", [])@@ -205,9 +227,9 @@ try:except ValueError:check("router/empty_agents", True, True)-# route_team with empty agents list+# route_team with empty members listtry:- router.route_team("message", AgnoTeam(agents=[], mode="route"))+ router.route_team("message", AgnoTeam(members=[], mode="route"))check("router/route_team_empty", False, True)except ValueError:check("router/route_team_empty", True, True)@@ -215,6 +237,11 @@ except ValueError:# last_decision is setcheck_true("router/last_decision_set", router.last_decision is not None)+# run() is an alias for route()+dec_run = router.run("Research the latest AI papers", agents)+check("router/run_index", dec_run.agent_index, 0)+check("router/run_name", dec_run.name, "Researcher")+# Confidence threshold with fallback agentfallback_router = LayaAgnoRouter(agent=mock_agent,@@ -251,6 +278,11 @@ async def run_async_router():dec_async_team = await router.aroute_team("Write documentation", team_obj)check("router/async_team_index", dec_async_team.agent_index, 1)+ # arun() is an alias for aroute()+ dec_arun = await router.arun("Research the latest AI papers", agents)+ check("router/arun_index", dec_arun.agent_index, 0)+ check("router/arun_name", dec_arun.name, "Researcher")+asyncio.run(run_async_router())