{"record":{"id":"7fdf5dc4456a7353","repo":"alibaba/spring-ai-alibaba","slug":"routing-flow-requires-a-chatmodel-for-decision-mak","errorCode":null,"errorMessage":"Routing flow requires a ChatModel for decision making","messagePattern":"Routing flow requires a ChatModel for decision making","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/flow/strategy/RoutingGraphBuildingStrategy.java","lineNumber":155,"sourceCode":"\n\t@Override\n\tpublic void validateConfig(FlowGraphBuilder.FlowGraphConfig config) {\n\t\tsuper.validateConfig(config);\n\t\tvalidateRoutingConfig(config);\n\t}\n\n\t/**\n\t * Validates routing-specific configuration requirements.\n\t * @param config the configuration to validate\n\t * @throws IllegalArgumentException if validation fails\n\t */\n\tprivate void validateRoutingConfig(FlowGraphBuilder.FlowGraphConfig config) {\n\t\tif (config.getSubAgents() == null || config.getSubAgents().isEmpty()) {\n\t\t\tthrow new IllegalArgumentException(\"Routing flow requires at least one sub-agent\");\n\t\t}\n\n\t\tif (config.getChatModel() == null) {\n\t\t\tthrow new IllegalArgumentException(\"Routing flow requires a ChatModel for decision making\");\n\t\t}\n\n\t\t// Ensure root agent is a FlowAgent for input key access\n\t\tif (!(config.getRootAgent() instanceof FlowAgent)) {\n\t\t\tthrow new IllegalArgumentException(\"Routing flow requires root agent to be a FlowAgent\");\n\t\t}\n\t}\n\n}\n","sourceCodeStart":137,"sourceCodeEnd":165,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/flow/strategy/RoutingGraphBuildingStrategy.java#L137-L165","documentation":"validateRoutingConfig in RoutingGraphBuildingStrategy requires config.getChatModel() to be non-null: the routing agent uses an LLM to decide which sub-agent to invoke, so a missing ChatModel makes the flow unbuildable.","triggerScenarios":"Building a routing flow without calling .chatModel(...) / without a model configured on the root agent, so getChatModel() returns null at validation time.","commonSituations":"Forgot to wire the DashScope/OpenAI model into the routing builder; model bean not injected (null autowire); copying a non-routing agent template that has no model.","solutions":["Pass a ChatModel to the routing agent builder (.chatModel(model))","Verify the model bean is properly injected and not null","Construct a DashScopeChatModel/OpenAiChatModel instance if none is configured"],"exampleFix":"// before\nRoutingAgent.builder().subAgents(a, b).build();\n// after\nRoutingAgent.builder().chatModel(new DashScopeChatModel(apiKey)).subAgents(a, b).build();","handlingStrategy":"validation","validationCode":"if (chatModel == null) {\n    throw new IllegalArgumentException(\"Routing requires a ChatModel; configure it via .chatModel(...)\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Wire the ChatModel into the routing builder explicitly","Verify Spring bean injection of the model is not null","Follow routing examples in the repo that always set a model"],"tags":["java","agent-framework","routing","missing-config"],"backgroundTag":"missing-required-config-field","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}