{"record":{"id":"8301911683fc916e","repo":"datawhalechina/hello-agents","slug":"llm-e2","errorCode":null,"errorMessage":"LLM调用完全失败: {e2}","messagePattern":"LLM调用完全失败: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Co-creation-projects/CC1227871-StockInsightAgent/llm_client.py","lineNumber":57,"sourceCode":"            print()\n            result = \"\".join(collected)\n            return result\n        except Exception as e:\n            print(f\"[ERR] LLM 调用失败: {e}\")\n            # 尝试非流式重试\n            try:\n                print(\"  尝试非流式重试...\")\n                response = self.client.chat.completions.create(\n                    model=self.model, messages=messages,\n                    temperature=temperature, stream=False,\n                )\n                content = response.choices[0].message.content or \"\"\n                clean = content.encode(\"utf-8\", errors=\"surrogateescape\").decode(\"utf-8\", errors=\"replace\")\n                print(clean)\n                return clean\n            except Exception as e2:\n                print(f\"[ERR] 非流式也失败: {e2}\")\n                raise RuntimeError(f\"LLM调用完全失败: {e2}\")\n","sourceCodeStart":39,"sourceCodeEnd":58,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/CC1227871-StockInsightAgent/llm_client.py#L39-L58","documentation":"think() first tries a streaming chat completion; on failure it retries once with stream=False, and only if that also fails does it raise RuntimeError('LLM调用完全失败: ...') wrapping the second exception. Reaching this error means both the streaming and non-streaming attempts against the OpenAI-compatible endpoint failed, so the underlying cause is almost always transport/auth/model configuration rather than streaming support.","triggerScenarios":"Wrong LLM_BASE_URL (unreachable host, missing /v1 suffix), invalid LLM_API_KEY (401), model id not served by the endpoint (404/400), network outage, or a proxy/firewall blocking HTTPS — every call raises, the non-streaming retry raises too, and this RuntimeError surfaces.","commonSituations":"Base URL pointing at a provider that does not expose the OpenAI-compatible path; rotated/revoked API keys; self-hosted model server down; corporate proxy rejecting the request; model name deprecated and removed server-side.","solutions":["Reproduce with a minimal curl against $LLM_BASE_URL/chat/completions with the same key and model to see the real status code.","Verify LLM_API_KEY is valid and LLM_MODEL_ID exists on that endpoint (many providers need exact model slugs).","Check LLM_BASE_URL formatting (scheme included, correct port, /v1 present if required) and network/proxy reachability.","Increase LLM_TIMEOUT if the failure is a read timeout rather than connection error."],"exampleFix":"# before\nLLM_BASE_URL=https://my-proxy.example.com   # missing path\n\n# after\nLLM_BASE_URL=https://my-proxy.example.com/v1  # verify with:\n# curl -sS -o /dev/null -w '%{http_code}' \"$LLM_BASE_URL/chat/completions\" \\\n#   -H \"Authorization: Bearer $LLM_API_KEY\" -H 'Content-Type: application/json' \\\n#   -d '{\"model\":\"'$LLM_MODEL_ID'\",\"messages\":[{\"role\":\"user\",\"content\":\"hi\"}]}'","handlingStrategy":"retry","validationCode":"import os, socket\nfrom urllib.parse import urlparse\nu = urlparse(os.getenv('LLM_BASE_URL', ''))\nassert u.scheme in ('http', 'https') and u.netloc, 'LLM_BASE_URL malformed'\nsocket.getaddrinfo(u.hostname, u.port or (443 if u.scheme == 'https' else 80))  # DNS reachable","typeGuard":null,"tryCatchPattern":"for attempt in range(3):\n    try:\n        return client.think(messages)\n    except RuntimeError as e:\n        if 'LLM调用完全失败' not in str(e) or attempt == 2:\n            raise\n        time.sleep(2 ** attempt)  # back off, then retry both stream+non-stream path","preventionTips":["Smoke-test the endpoint with one direct API call at startup and alert on failure.","Keep base URL, key and model in one validated config object instead of three loose env vars.","Log the inner exception (e2) — the RuntimeError text is the only place it survives."],"tags":["network","llm-client","api-key","openai-compatible"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}