{"record":{"id":"7ce8a44dbc716b62","repo":"alibaba/spring-ai-alibaba","slug":"emulator-model-is-required","errorCode":null,"errorMessage":"Emulator model is required","messagePattern":"Emulator model is required","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/interceptor/toolemulator/ToolEmulatorInterceptor.java","lineNumber":193,"sourceCode":"\t\t\tthis.emulateAll = emulateAll;\n\t\t\treturn this;\n\t\t}\n\n\t\t/**\n\t\t * Set a custom prompt template for emulation.\n\t\t * The template should accept 3 string format arguments:\n\t\t * 1. Tool name\n\t\t * 2. Tool description\n\t\t * 3. Tool arguments (JSON)\n\t\t */\n\t\tpublic Builder promptTemplate(String template) {\n\t\t\tthis.promptTemplate = template;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic ToolEmulatorInterceptor build() {\n\t\t\tif (emulatorModel == null) {\n\t\t\t\tthrow new IllegalStateException(\"Emulator model is required\");\n\t\t\t}\n\t\t\treturn new ToolEmulatorInterceptor(this);\n\t\t}\n\t}\n}\n\n","sourceCodeStart":175,"sourceCodeEnd":200,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/interceptor/toolemulator/ToolEmulatorInterceptor.java#L175-L200","documentation":"ToolEmulatorInterceptor.Builder.build() requires an emulator ChatModel; without it there is nothing to generate the emulated tool responses. It throws IllegalStateException at build time rather than failing later mid-execution.","triggerScenarios":"Calling ToolEmulatorInterceptor.Builder.build() without ever calling the setter that supplies emulatorModel, or setting it to null conditionally.","commonSituations":"Copying builder code and omitting the model line; wiring the emulator in tests where a real model bean was not injected; a nullable model property resolved from config that was absent.","solutions":["Call .emulatorModel(chatModel) with a ChatModel instance before build()","Inject a model bean (e.g. DashScope/OpenAI ChatModel) in the test/app context","Assert the model is configured before building the interceptor"],"exampleFix":"// before\nToolEmulatorInterceptor.builder().build();\n// after\nToolEmulatorInterceptor.builder().emulatorModel(chatModel).build();","handlingStrategy":"validation","validationCode":"if (chatModel == null) { throw new IllegalStateException(\"Provide a ChatModel for the tool emulator\"); }\nToolEmulatorInterceptor.builder().emulatorModel(chatModel).build();","typeGuard":"boolean isModelConfigured(ChatModel m) { return m != null; }","tryCatchPattern":"try { interceptor = builder.build(); } catch (IllegalStateException e) { interceptor = builder.emulatorModel(defaultChatModel).build(); }","preventionTips":["Inject the ChatModel bean rather than constructing inline","Verify model bean availability in test setup before building interceptors","Build interceptors in a @Configuration with constructor-injected model"],"tags":["builder","missing-dependency","initialization","tool-emulator"],"backgroundTag":"missing-required-argument","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"}