{"record":{"id":"954c8980ae8cf1a1","repo":"datawhalechina/hello-agents","slug":"llm-954c89","errorCode":null,"errorMessage":"LLM思考超时","messagePattern":"LLM思考超时","errorType":"exception","errorClass":"TimeoutException","httpStatus":null,"severity":"error","filePath":"Co-creation-projects/Shawnxyxy-HealthRecordAgent/backend/agents/base.py","lineNumber":143,"sourceCode":"\n            self.trace(\"LLM TTHINKING TIME\",\n                {\n                    \"duration_sec\": duration,\n                    \"prompt_tokens\": len(full_prompt),\n                }\n            )\n            \n            response_text = response.content if hasattr(response, 'content') else str(response)\n            \n            self.trace(\"LLM RESPONSE\", response_text)\n\n            self._add_to_history(f\"LLM prompt: {prompt}\")\n            self._add_to_history(f\"LLM response: {response_text}\")\n            \n            return response_text\n            \n        except asyncio.TimeoutError:\n            raise TimeoutException(f\"LLM思考超时\")\n        except Exception as e:\n            raise AgentException(f\"LLM思考失败: {str(e)}\")\n    # ========== Tool 机制 ==========\n    def add_tool(self, tool_name: str, tool_func: Callable, description: str = \"\"):\n        \"\"\"添加工具\"\"\"\n        self.tools[tool_name] = {\n            \"function\": tool_func,\n            \"description\": description\n        }\n    \n    def get_tools_description(self) -> str:\n        \"\"\"获取工具描述\"\"\"\n        if not self.tools:\n            return \"暂无可用工具\"\n        \n        descriptions = []\n        for name, tool_info in self.tools.items():\n            descriptions.append(f\"- {name}: {tool_info['description']}\")","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/Shawnxyxy-HealthRecordAgent/backend/agents/base.py#L125-L161","documentation":"BaseAgent.think wraps self.llm.ainvoke(full_prompt) in asyncio.wait_for(..., timeout=self.timeout); asyncio.TimeoutError is re-raised as a custom TimeoutException('LLM思考超时'). It means the LLM call did not complete within the agent's configured timeout (default set on the agent, often 60s), not that the model returned an error.","triggerScenarios":"Long prompts or slow reasoning models exceeding self.timeout; streaming disabled so the whole completion must land inside the window; provider under heavy load; the event loop being blocked elsewhere so the coroutine never progresses.","commonSituations":"Large health-record contexts producing multi-thousand-token prompts; tight timeouts copied from quick smoke tests; degraded LLM provider latency at peak hours.","solutions":["Raise the agent's timeout (constructor/config) to comfortably exceed worst-case generation time.","Shrink the prompt: trim history, summarize context, or cap tool output fed back into think().","Catch TimeoutException at the call site and retry once — transient provider slowness often clears.","If it persists, check provider status/latency and whether the base_url is reachable quickly."],"exampleFix":"# before\nagent = SymptomCheckAgent(timeout=30)  # too tight for long prompts\n\n# after\nagent = SymptomCheckAgent(timeout=180)\ntry:\n    out = await agent.think(prompt)\nexcept TimeoutException:\n    out = await agent.think(shortened_prompt)  # retry with trimmed context","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    out = await agent.think(prompt)\nexcept TimeoutException:\n    await asyncio.sleep(2)\n    out = await agent.think(trim(prompt))  # retry once with a shorter prompt","preventionTips":["Size self.timeout to p99 generation time for your model, not the happy path.","Trim history/context before every think() so prompt growth does not silently cross the timeout.","Instrument think() duration; a rising trend predicts future timeouts."],"tags":["asyncio","timeout","llm","agent"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}