{"record":{"id":"48cd536144e0dfbe","repo":"alibaba/spring-ai-alibaba","slug":"instruction-is-empty-and-sharestate-is-false","errorCode":null,"errorMessage":"Instruction is empty and shareState is false","messagePattern":"Instruction is empty and shareState is false","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/a2a/A2aNodeActionWithConfig.java","lineNumber":761,"sourceCode":"\t\troot.put(\"id\", id);\n\t\troot.put(\"jsonrpc\", \"2.0\");\n\t\troot.put(\"method\", \"message/stream\");\n\t\troot.put(\"params\", params);\n\n\t\ttry {\n\t\t\treturn objectMapper.writeValueAsString(root);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new IllegalStateException(\"Failed to build JSON-RPC streaming payload\", e);\n\t\t}\n\t}\n\n\tprivate String getEffectiveInstruction(OverAllState state) {\n\t\tif (StringUtils.hasLength(this.instruction)) {\n\t\t\tPromptTemplate template = PromptTemplate.builder().template(this.instruction).build();\n\t\t\treturn template.render(state.data());\n\t\t} else if (!shareState || (shareState && state.value(\"messages\").isEmpty())) {\n\t\t\tthrow new IllegalStateException(\"Instruction is empty and shareState is false\");\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Send the request to the remote A2A server and return the non-streaming response.\n\t * @param agentCard Agent card (source for server URL/metadata)\n\t * @param requestPayload JSON string payload built by buildSendMessageRequest\n\t * @return Response body as string\n\t */\n\tprivate String sendMessageToServer(AgentCardWrapper agentCard, String requestPayload) throws Exception {\n\t\tString baseUrl = resolveAgentBaseUrl(agentCard);\n\t\tSystem.out.println(baseUrl);\n\t\tSystem.out.println(requestPayload);\n\t\tif (baseUrl == null || baseUrl.isBlank()) {\n\t\t\tthrow new IllegalStateException(\"AgentCard.url is empty\");\n\t\t}\n","sourceCodeStart":743,"sourceCodeEnd":779,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/a2a/A2aNodeActionWithConfig.java#L743-L779","documentation":"getEffectiveInstruction resolves the prompt instruction sent to the remote A2A agent. If no instruction was configured and shareState is false (or shareState is true but state has no \"messages\"), there is nothing to send, so it throws this IllegalStateException.","triggerScenarios":"Creating an A2aNodeActionWithConfig (via its builder) without calling instruction(...) while shareState is false; or with shareState true but the parent OverAllState has an empty/absent \"messages\" key at execution time.","commonSituations":"Forgetting to set the instruction on the A2A node builder; upstream node never wrote messages into shared state (wrong state key, upstream agent failed silently); wiring an A2A node as the first node in a graph with no user input yet.","solutions":["Set an instruction on the A2A node builder: A2aNodeActionWithConfig.builder().instruction(\"...\")...","Enable shareState so the node renders the prompt from the parent state's messages","Make sure an upstream node populates state key \"messages\" before the A2A node runs","Pre-check the graph wiring: the A2A node should not be the entry point when it depends on shared messages"],"exampleFix":"// before\nA2aNodeActionWithConfig node = A2aNodeActionWithConfig.builder()\n    .agentCard(card)\n    .shareState(false)\n    .build();\n// after\nA2aNodeActionWithConfig node = A2aNodeActionWithConfig.builder()\n    .agentCard(card)\n    .instruction(\"Summarize the user request\")\n    .shareState(false)\n    .build();","handlingStrategy":"validation","validationCode":"boolean ready = StringUtils.hasLength(instruction)\n    || (shareState && state.value(\"messages\") != null && !state.value(\"messages\").isEmpty());\nif (!ready) throw new IllegalArgumentException(\"A2A node needs an instruction or shared messages\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set .instruction(...) on A2A node builders unless shareState is intended","Ensure an upstream node writes \"messages\" into state before the A2A node","Don't place a shareState-dependent A2A node as the graph entry point"],"tags":["a2a","configuration","prompt","state"],"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"}