Repository navigation
fix(integrations): a delegation choice naming no agent is refused, not indexed - #1416
Conversation
…, not indexed `chosen_key` is remote JSON and `agents`/`choices` is the caller's list, but `agent_N` was parsed straight into `agents[N]`. `agent_9` for a two-agent crew raised a bare IndexError out of the routing decision, and `agent_-1` wrapped to the LAST agent -- a route no caller asked for and nothing in the decision names. `tools.py` already answers an unknown decision by name instead of raising; the three routers now check the index against the candidates they built `criteria` from.
|
Merged in 0.4.18. The negative index is the reason this is more than an error-message improvement, and it deserves stating plainly:
Your justification is the right one: Fixing all three integrations in one change is right for the same reason as the BOM work: For the record, since the automated boundary scan flagged it and someone may re-run that scan later: the Verified: 706 tests across 93 suites. |
Twelve pull requests: #1364, #1409, #1410, #1412, #1413, #1414, #1415, #1416, #1417, #1418, #1419, #1420. Test suites: 706 passing across 93 suites, up from 640 across 92. laya-cpp registers 423 ctest tests, up from 213, and its MIN_TESTS floor is raised to match. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
What
LayaCrewRouter.route,LayaAgnoRouter.routeandLayaSingleSelector._selectparse the remotechoicestring (agent_N/choice_N) into an index and use it directly on the caller's list. Theynow check that index against the candidates before indexing, and raise the same
Malformed decision responseRuntimeErrorthe package already raises for achoiceof the wrongtype.
laya/integrations/crewai.py:412laya/integrations/agno.py:594laya/integrations/llamaindex.py:402Why
chosen_keyis arbitrary JSON from a Laya server (or any local runner'spredictreturn) andagents/choicesis the caller's list, so the two have no reason to agree. Nothing connected them:Two failure modes from one unvalidated parse. Past the end,
agents[chosen_idx](
crewai.py:441,agno.py:625,llamaindex.py:422) raises a bareIndexErrorout of the path whosejob is to fail closed -- and it is a leak, not a check: the line above it already refuses a
choicethat is not a string by name. Below zero, Python's negative indexing wraps, so
agent_-1silentlydelegates to the last agent and the decision carries
agent_index=-1, which is wrong for thecaller too.
tools.py:478/:493already handles the same shape in the sibling adapter -- it checksmembership in the candidate lookup and answers with
Unknown or missing tool decision ... not in candidate tools-- andLayaQueryRouter.routeinllamaindex.py:703treats a name outside itsengines as no match. These three routers were the only ones that indexed instead.
The
criteriadict is built from exactly the list being indexed (_format_agent_criteria,_format_choices_criteriaboth keyagent_{i}/choice_{i}overenumerate(agents)), so "the parsedindex is outside the list" is precisely "the decision named a candidate that does not exist".
After:
The highest real index still routes (a range check, not a rejection of
agent_3), which is assertedas a control in each suite.
How it was verified
Each adapter's suite grows by the same 13 checks -- 4 bad indices x (raises / names the choice / names
the count / is a
RuntimeError) plus the last-index control. Totals were read out of the suite's ownPASS/FAILlists withrunpy, because the file prints itsPASS:summary before these sections:The guard itself is what those checks test -- with the three
if not 0 <= ...blocks removed (baselaya/integrations/*.pydropped back in), every suite exits non-zero and names the leak, so no checkis a no-op:
The files were then restored byte-identically (
cmpagainst the saved copies) and the suites re-runfrom disk.
No port fixture or golden moves: the generators that could pin this (
laya-dotnet/tools/*_cases.py,laya-rust/tools/,laya-java/scripts/gen_fixtures.py,laya-go/scripts/gen_go_fixtures.py,laya-ts/scripts/option_stability_fixtures.py) contain nocrewai/agno/llamaindexdecision case,and
Malformed decision responseappears in no port fixture -- the same sweep that let #1335 and#1403 through.
Checklist
mainsignatures, return types and existing error family are untouched, and
docs/crewai.md,docs/agno.mdand
docs/llamaindex.mddo not enumerate the malformed-decision refusals this joins, so there is nolist to add it to
Fixes #