{"record":{"id":"1be64f9818734313","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-get-valid-decision-after-d-retries-las-1be64f","errorCode":null,"errorMessage":"Failed to get valid decision after %d retries. Last invalid decision: %s","messagePattern":"Failed to get valid decision after (.+?) retries\\. Last invalid decision: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-boot-starters/spring-ai-alibaba-starter-agentscope/src/main/java/com/alibaba/cloud/ai/agent/agentscope/flow/AgentScopeRoutingNode.java","lineNumber":195,"sourceCode":"\t\t\t\t\t\tif (attempt > 0) {\n\t\t\t\t\t\t\tlogger.info(\"AgentScopeRoutingAgent {} succeeded on retry attempt {}. Routed to: {}\",\n\t\t\t\t\t\t\t\t\trootAgent.name(), attempt, String.join(\", \", decisionValues));\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn decision;\n\t\t\t\t\t}\n\t\t\t\t\tlastInvalidDecision = decisionValues;\n\t\t\t\t} else {\n\t\t\t\t\tlastInvalidDecision = Collections.emptyList();\n\t\t\t\t}\n\t\t\t} catch (Exception e) {\n\t\t\t\tif (attempt == maxRetries) {\n\t\t\t\t\tlogger.error(\"AgentScopeRoutingAgent {} failed on final attempt {}/{}\", rootAgent.name(), attempt, maxRetries, e);\n\t\t\t\t\tthrow e;\n\t\t\t\t}\n\t\t\t\tlogger.warn(\"AgentScopeRoutingAgent {} attempt {}/{} encountered an error, will retry\", rootAgent.name(), attempt, maxRetries, e);\n\t\t\t}\n\t\t}\n\t\tthrow new IllegalStateException(\n\t\t\t\tString.format(\"Failed to get valid decision after %d retries. Last invalid decision: %s\", maxRetries, lastInvalidDecision));\n\t}\n\n\tprivate static RoutingNode.RoutingDecision toRoutingDecision(RoutingDecisionSchema schema) {\n\t\tList<RoutingNode.AgentRouting> list = new ArrayList<>();\n\t\tfor (RoutingDecisionSchema.AgentRoutingSchema e : schema.agents) {\n\t\t\tif (e != null && StringUtils.hasText(e.agent)) {\n\t\t\t\tlist.add(new RoutingNode.AgentRouting(e.agent, e.query != null ? e.query : \"\"));\n\t\t\t}\n\t\t}\n\t\treturn new RoutingNode.RoutingDecision(list);\n\t}\n}\n","sourceCodeStart":177,"sourceCodeEnd":209,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-boot-starters/spring-ai-alibaba-starter-agentscope/src/main/java/com/alibaba/cloud/ai/agent/agentscope/flow/AgentScopeRoutingNode.java#L177-L209","documentation":"AgentScopeRoutingNode.getDecisionWithRetry throws this IllegalStateException after maxRetries attempts where each decision either failed or was invalid; lastInvalidDecision records the final rejected decision. Called from decision(), it is the retry-exhaustion path for obtaining a structured routing decision from the LLM.","triggerScenarios":"Every LLM call within getDecisionWithRetry either throws (parse errors, API errors) or returns a RoutingDecisionSchema that fails validation, until the retry budget is exhausted.","commonSituations":"Model output not conforming to the structured routing schema (malformed JSON); transient model API failures across all attempts; maxRetries set too low (e.g. 1) for a flaky model; prompt too ambiguous so decisions keep referencing unknown agents.","solutions":["Increase maxRetries for the routing node","Inspect lastInvalidDecision in the message to fix the recurring schema/prompt problem","Verify the model supports structured output matching RoutingDecisionSchema","Add a fallback route in caller code instead of letting the exception propagate"],"exampleFix":"// before\nAgentScopeRoutingNode node = AgentScopeRoutingNode.builder().maxRetries(1).build();\n// after\nAgentScopeRoutingNode node = AgentScopeRoutingNode.builder().maxRetries(3).build();","handlingStrategy":"retry","validationCode":"if (maxRetries < 2) throw new ConfigException(\"routing needs retries >= 2 for flaky models\");","typeGuard":null,"tryCatchPattern":"try {\n    decision = routingNode.decision(messages);\n} catch (IllegalStateException e) {\n    logger.error(\"Retries exhausted: {}\", e.getMessage());\n    return fallbackRouting(state);\n}","preventionTips":["Configure maxRetries >= 3 for LLM-driven decisions","Parse lastInvalidDecision from the message to fix systematic schema issues","Prefer models certified for structured output over free-form text parsing"],"tags":["agentscope","retry-exhausted","llm-decision","structured-output"],"backgroundTag":"retry-limit-exceeded","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}