{"record":{"id":"d23ab95b560a514b","repo":"datawhalechina/hello-agents","slug":"coach-agent-str-e","errorCode":null,"errorMessage":"Coach Agent执行失败: {str(e)}","messagePattern":"Coach Agent执行失败: (.+?)","errorType":"exception","errorClass":"AgentException","httpStatus":500,"severity":"error","filePath":"Co-creation-projects/Apricity-InnocoreAI/agents/coach.py","lineNumber":66,"sourceCode":"                result = await self._handle_mimic_task(user_id, content, context)\n            elif task_type == \"suggest\":\n                result = await self._handle_suggest_task(user_id, content, context)\n            else:\n                raise AgentException(f\"不支持的任务类型: {task_type}\")\n            \n            self.set_state(\"completed\")\n            \n            return {\n                \"status\": \"success\",\n                \"task_type\": task_type,\n                \"user_id\": user_id,\n                \"result\": result,\n                \"timestamp\": datetime.now().isoformat()\n            }\n            \n        except Exception as e:\n            self.set_state(\"error\")\n            raise AgentException(f\"Coach Agent执行失败: {str(e)}\")\n    \n    def get_required_fields(self) -> List[str]:\n        \"\"\"获取必需的输入字段\"\"\"\n        return [\"user_id\", \"task_type\", \"content\"]\n    \n    async def _handle_explain_task(self, user_id: str, content: str, context: Dict) -> Dict[str, Any]:\n        \"\"\"处理解释任务\"\"\"\n        try:\n            # 获取用户的历史论文作为上下文\n            user_context = await self._get_user_context(user_id)\n            \n            explain_prompt = f\"\"\"\n            请用通俗易懂的语言解释以下内容：\n            \n            需要解释的内容：\n            {content}\n            \n            上下文信息：","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/Apricity-InnocoreAI/agents/coach.py#L48-L84","documentation":"Outer catch-all in CoachAgent.run: any exception from the four task handlers (_handle_explain_task etc.), from think()/call_tool() inside them, or from _get_user_context is re-wrapped as AgentException with the original message preserved in the suffix. State is set to 'error' before raising. The real cause is always in the appended text; this wrapper adds one layer but no information.","triggerScenarios":"think() raising TimeoutException('LLM思考超时') during prompt polish; _get_user_context hitting a database error for an unknown user_id; an inner handler's own except re-raising AgentException, which gets double-wrapped as \"Coach Agent执行失败: Coach Agent执行失败: ...\" style nesting when handlers follow the same pattern.","commonSituations":"LLM key/quota problems; DB connection not initialized before coach runs; nested double-wrapping making messages recursive; handlers assuming optional context keys exist.","solutions":["Parse the trailing original message — it identifies whether the failure is LLM, DB, or tool.","Re-raise AgentException/TimeoutException unchanged (except (AgentException, TimeoutException): raise) to avoid nested wrappers.","Add raise ... from e to keep the traceback intact.","Fix the root cause in the named handler; this wrapper itself needs no code change once the inner error is resolved."],"exampleFix":"# before\nexcept Exception as e:\n    self.set_state(\"error\")\n    raise AgentException(f\"Coach Agent执行失败: {str(e)}\")\n\n# after\nexcept (AgentException, TimeoutException):\n    self.set_state(\"error\")\n    raise\nexcept Exception as e:\n    self.set_state(\"error\")\n    raise AgentException(f\"Coach Agent执行失败: {e}\") from e","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = await coach.run(input_data)\nexcept AgentException as e:\n    root = str(e).replace(\"Coach Agent执行失败: \", \"\")\n    logger.error(\"coach failed: %s\", root, exc_info=True)\n    # classify: LLM/auth errors are ops issues; task-type/field errors are client issues\n    raise","preventionTips":["Always diagnose the suffixed inner error, not the 'Coach Agent执行失败' prefix.","Re-raise typed exceptions unchanged in wrappers to avoid nested double-prefixes.","Patch wrappers to 'raise ... from e' so the chain is preserved."],"tags":["python","agent","error-wrapping","orchestration"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}