{"record":{"id":"1c54b16e13d4108a","repo":"alibaba/spring-ai-alibaba","slug":"invalid-agent-dsl-type-agent-class-and-name-a","errorCode":null,"errorMessage":"invalid agent dsl: 'type/agent_class' and 'name' are required","messagePattern":"invalid agent dsl: 'type/agent_class' and 'name' are required","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/generator/service/dsl/adapters/AgentDSLAdapter.java","lineNumber":134,"sourceCode":"\t\t\t}\n\t\t\tagent.setSubAgents(subs);\n\t\t}\n\n\t\treturn new App(metadata, agent);\n\t}\n\n\tprivate void validateDSLData(Map<String, Object> dslData) {\n\t\tif (dslData == null) {\n\t\t\tthrow new IllegalArgumentException(\"invalid agent dsl: data is null\");\n\t\t}\n\t\tMap<String, Object> root = getAgentRoot(dslData);\n\t\tif (root == null) {\n\t\t\tthrow new IllegalArgumentException(\"invalid agent dsl: missing 'agent' object or flat agent fields\");\n\t\t}\n\t\tString type = firstNonBlank((String) root.get(\"type\"), (String) root.get(\"agent_class\"));\n\t\tString name = (String) root.get(\"name\");\n\t\tif (isBlank(type) || isBlank(name)) {\n\t\t\tthrow new IllegalArgumentException(\"invalid agent dsl: 'type/agent_class' and 'name' are required\");\n\t\t}\n\t\t// 针对不同 Agent 类型的校验\n\t\tvalidateAgentTypeSpecificConstraints(type, root);\n\t}\n\n\tprivate void validateAgentTypeSpecificConstraints(String type, Map<String, Object> root) {\n\t\tif (type == null || root == null) {\n\t\t\treturn;\n\t\t}\n\n\t\t// 使用 AgentTypeProvider 进行校验\n\t\tAgentTypeProvider provider = providerRegistry.get(type);\n\t\tif (provider != null) {\n\t\t\tprovider.validateDSL(root);\n\t\t}\n\t}\n\n\tprivate AppMetadata mapToMetadata(Map<String, Object> data) {","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/generator/service/dsl/adapters/AgentDSLAdapter.java#L116-L152","documentation":"Thrown by AgentDSLAdapter.validateDSLData when the agent root object was found but is missing either a non-blank type ('type' or 'agent_class') or a non-blank 'name'. Both fields are mandatory to identify which agent implementation to instantiate and how to register it. After this check, type-specific constraints are validated by validateAgentTypeSpecificConstraints.","triggerScenarios":"Importing a DSL whose agent object has a name but no type/agent_class; an agent object with type but a blank or missing name; firstNonBlank of (\"type\",\"agent_class\") yields null/empty string; whitespace-only values.","commonSituations":"Template DSL files with placeholder fields left empty; migration scripts that drop 'agent_class' from older DSL versions; programmatic DSL construction where the builder skipped required fields; renaming an agent and accidentally clearing the name field.","solutions":["Add a non-blank 'type' (or legacy 'agent_class') and 'name' to the agent object in the DSL","Check for whitespace-only values — isBlank() treats them as missing","Compare against a known-good exported DSL for the same agent type to confirm required fields","Confirm the agent type string matches a supported type in validateAgentTypeSpecificConstraints"],"exampleFix":"// before\n{\"agent\": {\"name\": \"\"}}\n\n// after\n{\"agent\": {\"type\": \"SimpleAgent\", \"name\": \"my-agent\"}}","handlingStrategy":"validation","validationCode":"Map<String,Object> agent = (Map<String,Object>) dslData.get(\"agent\");\nString type = agent != null ? (String) agent.getOrDefault(\"type\", (String) agent.get(\"agent_class\")) : null;\nString name = agent != null ? (String) agent.get(\"name\") : null;\nif (type == null || type.isBlank() || name == null || name.isBlank()) throw new IllegalArgumentException(\"agent type and name are required\");","typeGuard":"boolean hasRequiredAgentFields(Map<String,Object> agent) { return agent != null && Optional.ofNullable((String) agent.get(\"type\")).or(() -> Optional.ofNullable((String) agent.get(\"agent_class\"))).map(s -> !s.isBlank()).orElse(false) && Optional.ofNullable((String) agent.get(\"name\")).map(s -> !s.isBlank()).orElse(false); }","tryCatchPattern":"try { adapter.importDSL(dslData); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"type/agent_class\")) { log.error(\"Missing agent type/name in DSL\"); } throw e; }","preventionTips":["Validate type/agent_class and name are non-blank before calling importDSL","Use templates that pre-fill required agent fields","Watch for whitespace-only values — they count as blank","Keep agent_class populated when migrating older DSL versions"],"tags":["dsl","validation","required-fields"],"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"}