{"record":{"id":"9f967f7b94f80b87","repo":"iflytek/astron-agent","slug":"codeconvert-sparklinkcode-code-response-json-get-header-get","errorCode":"CodeConvert.sparkLinkCode(code)","errorMessage":"{response_json.get(\"header\", {}).get(\"message\", \"\")}","messagePattern":"(.+?)\\)\\.get\\(\"message\", \"\"\\)\\}","errorType":"error_code","errorClass":"CustomException","httpStatus":null,"severity":"error","filePath":"core/workflow/engine/nodes/util/frame_processor.py","lineNumber":76,"sourceCode":"\n    :param tool_calls: List of tool call dictionaries\n    :return: Formatted string containing all tool call contents\n    :raises CustomException: When tool execution returns error code\n    \"\"\"\n    final_content = []\n    for tool in tool_calls:\n        type_value = str(tool.get(\"type\") or \"\")\n        reason_value = str(tool.get(\"reason\") or \"\")\n        function = cast(Dict[str, Any], tool.get(\"function\") or {})\n        response_json_str = function.get(\"response\") or \"{}\"\n        response_json = json.loads(response_json_str)\n        if type_value == ToolType.TOOL.value:\n            if response_json.get(\"header\"):\n                # Handle tool type response\n                code = response_json.get(\"header\", {}).get(\"code\")\n                if code != 0:\n                    err_msg = response_json.get(\"header\", {}).get(\"message\", \"\")\n                    raise CustomException(\n                        err_code=CodeConvert.sparkLinkCode(code), err_msg=err_msg\n                    )\n                payload = response_json.get(\"payload\", {})\n                response = payload.get(\"text\", {}).get(\"text\", \"\")\n                response_dict = json.loads(response) if response else {}\n            else:\n                # Handle MCP (Model Context Protocol) type response\n                response_dict = response_json.get(\"data\", {}).get(\"content\", [])\n        elif type_value == ToolType.KNOWLEDGE.value:\n            response_dict = response_json.get(\"metadata_list\", [])\n        # response = function.get(\"response\")\n        function_name = str(function.get(\"name\") or \"\")\n        function_arguments = str(function.get(\"arguments\") or \"\")\n        final_content.append(\n            generate_agent_output_optimize(\n                type_value,\n                reason_value,\n                response_dict,","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/engine/nodes/util/frame_processor.py#L58-L94","documentation":"While processing a SparkLink-format tool response frame, `extract_tool_calls_content` checks the envelope's `header.code`; a non-zero code means the SparkLink tool backend rejected the request. The node raises CustomException with the backend's message and converts the upstream code via `CodeConvert.sparkLinkCode(code)` into a workflow error code.","triggerScenarios":"process_frame or _process_stream_response -> extract_tool_calls_content on a TOOL-type response containing a `header` with `code != 0` — the SparkLink tool/service returned a business error (auth failure, invalid params, service error, rate limit, etc.).","commonSituations":"SparkLink app/API key invalid or expired (auth code); malformed tool request parameters; SparkLink service degraded or rate-limited; plugin configured against the wrong SparkLink endpoint or version whose codes changed; quota exhausted on the SparkLink account.","solutions":["Read header.message in the error to identify the SparkLink-reported cause and fix the tool request parameters or configuration.","Verify the plugin's SparkLink credentials (app id/secret, API key) are valid and not expired.","Check SparkLink service status/quota if the code indicates rate limiting or server error.","Map the returned sparkLinkCode to its documented meaning to apply the right fix (auth vs params vs availability)."],"exampleFix":"// before: no pre-check of credentials\ncall_sparklink_tool(params)\n\n// after: validate config before invocation\nif not plugin_config.api_key:\n    raise ConfigError(\"SparkLink API key missing in plugin settings\")\nif not plugin_config.api_key_valid():\n    refresh_credentials()\ncall_sparklink_tool(params)","handlingStrategy":"validation","validationCode":"def sparklink_config_ok(cfg: dict) -> bool:\n    return bool(cfg.get(\"app_id\")) and bool(cfg.get(\"api_key\")) and bool(cfg.get(\"endpoint\"))\n\nif not sparklink_config_ok(plugin_config):\n    raise ConfigError(\"SparkLink plugin credentials/endpoint incomplete\")","typeGuard":"def header_indicates_error(frame: dict) -> bool:\n    return bool(frame.get(\"header\")) and frame.get(\"header\", {}).get(\"code\", 0) != 0","tryCatchPattern":"try:\n    result = await run_tool_node(...)\nexcept CustomException as e:\n    logger.error(f\"SparkLink tool failed: {e.err_msg} (code={e.err_code})\")\n    if is_auth_code(e.err_code):\n        refresh_sparklink_credentials(); result = await retry_once(run_tool_node)\n    else:\n        raise","preventionTips":["Validate SparkLink app id/secret and endpoint in plugin settings before invoking.","Rotate SparkLink credentials before expiry.","Map and document sparkLinkCode values so failures are diagnosable.","Watch SparkLink service status and rate limits for the account."],"tags":["sparklink","tool-call","upstream-error","plugin"],"backgroundTag":"api-error-response","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}