datawhalechina/hello-agents · error · AgentException

缺少健康指标分析结果

Error message

缺少健康指标分析结果

What it means

Raised by RiskAssessmentAgent.run when the 'indicator_results' key in input_data is missing, empty, or falsy. This is a pipeline precondition check: the risk-assessment agent refuses to run without the upstream health-indicator analysis output. It is thrown before any state transition to 'running', so no LLM call is wasted.

Source

Thrown at Co-creation-projects/Shawnxyxy-HealthRecordAgent/backend/agents/risk_assess.py:17

"""
健康风险评估 Agent
"""
import json
from typing import Dict, Any, List
from agents.base import BaseAgent
from core.exceptions import AgentException

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}

请你完成以下任务:

View on GitHub (pinned to 606a07d341)

Solutions

  1. Inspect the orchestrator/pipeline code that builds input_data and confirm the upstream agent's output dict uses the exact key 'indicator_results'.
  2. Check the upstream IndicatorAgent for silent empty returns (JSON parse failures often yield {}); log its raw output.
  3. Add a guard before dispatch: only run RiskAssessmentAgent when indicator_results is non-empty, and route to an error state otherwise.
  4. Note that the bare except at line 26 will re-wrap this as 'RiskAssessmentAgent 执行失败: 缺少健康指标分析结果' — read the inner message for the real cause.

Example fix

// before
result = await risk_agent.run({})  # KeyError-free but empty -> raises

// after
indicator_results = upstream.get('indicator_results')
if not indicator_results:
    raise AgentException('upstream indicator analysis missing; run IndicatorAgent first')
result = await risk_agent.run({'indicator_results': indicator_results})
Defensive patterns

Strategy: validation

Validate before calling

def has_indicator_results(input_data: dict) -> bool:
    return bool(isinstance(input_data, dict) and input_data.get("indicator_results"))

Type guard

from typing import Dict, Any

def is_valid_risk_input(input_data: Dict[str, Any]) -> bool:
    """Narrows input to the shape RiskAssessmentAgent.run requires."""
    return (
        isinstance(input_data, dict)
        and isinstance(input_data.get("indicator_results"), (dict, list))
        and len(input_data["indicator_results"]) > 0
    )

Try / catch

try:
    result = await risk_agent.run(input_data)
except AgentException as e:
    if "缺少健康指标分析结果" in str(e):
        # upstream produced nothing; do not retry with same input
        log.warning("indicator stage empty; routing to error flow")
    else:
        raise

Prevention

When it happens

Trigger: Calling RiskAssessmentAgent.run(input_data) where input_data lacks the 'indicator_results' key, or where its value is an empty dict/list, None, or empty string. Typically happens when the upstream IndicatorAgent failed or its output key name doesn't match ('indicator_results' vs e.g. 'result').

Common situations: Multi-agent pipeline wiring mistakes (upstream agent returns {'result': ...} but downstream expects 'indicator_results'); upstream agent silently returned an empty result on parse failure; orchestrator passes the wrong dict.

Related errors


AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14). Data as JSON: /api/errors/b9c65e0be70dcd62. Report an issue: GitHub.