datawhalechina/hello-agents · error · AgentException
Coach Agent执行失败: {str(e)}
Error message
Coach Agent执行失败: {str(e)} What it means
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.
Source
Thrown at Co-creation-projects/Apricity-InnocoreAI/agents/coach.py:66
result = await self._handle_mimic_task(user_id, content, context)
elif task_type == "suggest":
result = await self._handle_suggest_task(user_id, content, context)
else:
raise AgentException(f"不支持的任务类型: {task_type}")
self.set_state("completed")
return {
"status": "success",
"task_type": task_type,
"user_id": user_id,
"result": result,
"timestamp": datetime.now().isoformat()
}
except Exception as e:
self.set_state("error")
raise AgentException(f"Coach Agent执行失败: {str(e)}")
def get_required_fields(self) -> List[str]:
"""获取必需的输入字段"""
return ["user_id", "task_type", "content"]
async def _handle_explain_task(self, user_id: str, content: str, context: Dict) -> Dict[str, Any]:
"""处理解释任务"""
try:
# 获取用户的历史论文作为上下文
user_context = await self._get_user_context(user_id)
explain_prompt = f"""
请用通俗易懂的语言解释以下内容:
需要解释的内容:
{content}
上下文信息:View on GitHub (pinned to 606a07d341)
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.
Example fix
# before
except Exception as e:
self.set_state("error")
raise AgentException(f"Coach Agent执行失败: {str(e)}")
# after
except (AgentException, TimeoutException):
self.set_state("error")
raise
except Exception as e:
self.set_state("error")
raise AgentException(f"Coach Agent执行失败: {e}") from e Defensive patterns
Strategy: try-catch
Try / catch
try:
result = await coach.run(input_data)
except AgentException as e:
root = str(e).replace("Coach Agent执行失败: ", "")
logger.error("coach failed: %s", root, exc_info=True)
# classify: LLM/auth errors are ops issues; task-type/field errors are client issues
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: LLM key/quota problems; DB connection not initialized before coach runs; nested double-wrapping making messages recursive; handlers assuming optional context keys exist.
Related errors
- 工具 '{tool_name}' 执行失败: {str(e)}
- 任务执行失败: {str(e)}
- Hunter Agent执行失败: {str(e)}
- Miner Agent执行失败: {str(e)}
- Validator Agent执行失败: {str(e)}
AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14).
Data as JSON: /api/errors/d23ab95b560a514b.
Report an issue: GitHub.