datawhalechina/hello-agents · error · AgentException
RiskAssessmentAgent 执行失败: {str(e)}
Error message
RiskAssessmentAgent 执行失败: {str(e)} What it means
This is the catch-all wrapper thrown by RiskAssessmentAgent.run's except block. Any exception inside run() — including the empty-indicator AgentException, LLM failures inside _assess_risk, or prompt formatting errors — is caught, agent state is set to 'error', and a new AgentException is raised with the prefixed message. The original exception text is embedded via str(e) but the traceback chain is lost because it is re-raised as a new exception without 'from e'.
Source
Thrown at Co-creation-projects/Shawnxyxy-HealthRecordAgent/backend/agents/risk_assess.py:26
class RiskAssessmentAgent(BaseAgent):
def __init__(self, task_id=None, llm=None):
super().__init__(name="RiskAssessment", task_id=task_id, llm=llm)
async def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
try:
indicator_results = input_data["indicator_results"]
if not indicator_results:
raise AgentException("缺少健康指标分析结果")
self.set_state("running")
result = await self._assess_risk(indicator_results)
self.set_state("completed")
return result
except Exception as e:
self.set_state("error")
raise AgentException(f"RiskAssessmentAgent 执行失败: {str(e)}")
async def _assess_risk(self, indicator_results: Dict[str, Any]) -> Dict[str, Any]:
risk_prompt = f"""
你是一名专业的健康风险评估专家。
以下是某用户的健康指标分析结果(已由其他智能体完成分析):
{indicator_results}
请你完成以下任务:
1. 综合判断用户的整体健康风险等级(low / medium / high)
2. 列出主要风险因素(不超过 5 条)
3. 推测可能存在的潜在健康风险或疾病方向
4. 给出你评估的置信度(0~1 之间的小数)
请以 JSON 格式返回,例如:
{{
"overall_risk_level": "medium",
"risk_factors": ["高胆固醇", "睡眠不足"],View on GitHub (pinned to 606a07d341)
Solutions
- Read the suffix of the message after 'RiskAssessmentAgent 执行失败: ' — that is str(e) of the original exception and identifies the real failure.
- If it is '缺少健康指标分析结果', fix the upstream input (see the empty-indicator error).
- If it mentions network/timeout/auth, fix the LLM configuration (api_key, base_url, model name in config).
- Improve the code: use 'raise AgentException(...) from e' and catch AgentException separately so precondition errors are not double-wrapped.
Example fix
# before
except Exception as e:
self.set_state("error")
raise AgentException(f"RiskAssessmentAgent 执行失败: {str(e)}")
# after
except AgentException:
self.set_state("error")
raise
except Exception as e:
self.set_state("error")
raise AgentException(f"RiskAssessmentAgent 执行失败: {str(e)}") from e Defensive patterns
Strategy: try-catch
Try / catch
try:
result = await risk_agent.run(input_data)
except AgentException as e:
msg = str(e).removeprefix("RiskAssessmentAgent 执行失败: ")
log.error("risk agent failed: %s", msg, exc_info=True)
# classify by inner message; do not blind-retry LLM/auth failures
raise Prevention
- Always read the inner message after the wrapper prefix — it carries the root cause.
- Patch the agent to re-raise with 'from e' so tracebacks stay intact.
- Log agent state transitions (running/error) to correlate with pipeline monitoring.
When it happens
Trigger: Any failure inside run(): empty indicator_results (error 140), exceptions from self._assess_risk (LLM timeout, API auth failure, malformed JSON in the model response), or AttributeError from unexpected input shapes.
Common situations: LLM API key/quota problems surfacing through the agent; upstream output shape drift; retry loops that see only the wrapper message and can't classify the root cause.
Related errors
AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14).
Data as JSON: /api/errors/c43be3955a7bea16.
Report an issue: GitHub.