Heuristic:24mlight A Share investment Agent Agent Fallback Neutral Signal
| Knowledge Sources | |
|---|---|
| Domains | Debugging, Finance |
| Last Updated | 2026-10-10 14:00 GMT |
Overview
When an agent's output is missing, unparseable, or an error occurs, fall back to a neutral signal with default confidence rather than crashing the entire workflow.
Description
Throughout the multi-agent workflow, each agent is designed to degrade gracefully when its inputs are missing or its analysis fails. Instead of raising an exception that would halt the entire LangGraph DAG, agents return a neutral signal ("neutral") with low confidence (0.0-0.5) and include error information in the reasoning field. This ensures the portfolio manager always receives inputs from all agents, even if some agents failed, allowing the system to make a conservative (hold/neutral) decision rather than crashing.
Usage
Use this heuristic when:
- An agent's upstream dependency (e.g., market data, news) is unavailable
- LLM response parsing fails after all fallback attempts
- A required message from another agent is missing in the state
- You want the system to continue operating with partial information rather than fail completely
The Insight (Rule of Thumb)
- Action: Wrap agent logic in try/except; on failure, emit
{"signal": "neutral", "confidence": 0.0, "reasoning": "error details"}. - Value: Default neutral signal:
signal="neutral",confidence=0.0-0.5,score=0.0. - Trade-off: Failed agents contribute no useful signal, but the pipeline continues; the portfolio manager sees neutral signals and leans toward hold/reduce.
- Compatibility: Applies to all agents using the
agent_endpointdecorator pattern.
Reasoning
In a 12-agent LangGraph DAG, any single agent crash would halt the entire workflow, making the system unusable in production. By falling back to neutral signals, the system maintains operability even when:
- AkShare/BaoStock API is down (market data agent returns empty data)
- Tavily API keys are exhausted (sentiment agent returns neutral)
- Gemini API is rate-limited (LLM-dependent agents return neutral)
- Upstream agent messages are missing (portfolio manager uses dummy messages)
The portfolio manager and risk manager are specifically designed to handle neutral/low-confidence signals by leaning toward "hold" decisions, ensuring that degraded inputs lead to conservative (safe) trading decisions rather than erratic ones.
Code Evidence
Researcher bull fallback from src/agents/researcher_bull.py:23-29:
logger.warning(
"...")
logger.warning("Missing %s output, falling back to neutral signal", agent_name)
Risk manager missing debate message from src/agents/risk_manager.py:32-44:
try:
debate_message = next(
msg for msg in state["messages"] if msg.name == "debate_room_agent")
except StopIteration:
logger.error("❌ 找不到 debate_room_agent 的结果,使用中性假设")
debate_message = HumanMessage(
content=json.dumps({
"signal": "neutral",
"confidence": 0.0,
"bull_confidence": 0.0,
"bear_confidence": 0.0,
}),
name="debate_room_agent",
)
Sentiment agent fallback from src/agents/sentiment.py:92-103:
if sentiment_result is None:
signal = "error"
confidence = "0%"
reasoning_text = (
f"无法基于 {len(recent_news)} 条新闻得到情绪得分,错误信息:{sentiment_error or '未知'}"
)
sentiment_value = "error"
Portfolio manager missing message fallback from src/agents/portfolio_manager.py:20-29:
def get_latest_message_by_name(messages: list, name: str, *, log_missing: bool = True):
for msg in reversed(messages):
if msg.name == name:
return msg
if log_missing:
logger.warning(f"Message from agent '{name}' not found in portfolio_management_agent.")
return HumanMessage(content=json.dumps({"signal": "error", "details": f"Message from {name} not found"}), name=name)
Related Pages
- Implementation:24mlight_A_Share_investment_Agent_researcher_bull_agent
- Implementation:24mlight_A_Share_investment_Agent_researcher_bear_agent
- Implementation:24mlight_A_Share_investment_Agent_risk_management_agent
- Implementation:24mlight_A_Share_investment_Agent_sentiment_agent
- Implementation:24mlight_A_Share_investment_Agent_portfolio_management_agent
- Principle:24mlight_A_Share_investment_Agent_Portfolio_Decision_Synthesis
- Principle:24mlight_A_Share_investment_Agent_Risk_Management_and_Position_Sizing