fix(telegram): 修正 EA 通知格式與 Agent 名稱問題
All checks were successful
CD Pipeline / deploy (push) Successful in 1m14s

- 禁止 Gemini 音譯 Agent 名稱(赫瑪斯→Hermes, 內莫特朗→NemoTron)
- _AGENT_ZH 改為 _AGENT_LABEL,保留英文原名
- orchestrator system/user prompt 強制 reasoning 必須含具體數字
- _notify_telegram_executed 改為直接組裝訊息,顯示效益/依據/步驟
- _escalate_to_human 使用 _AGENT_LABEL 替換 _AGENT_ZH

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ogt
2026-04-21 13:03:49 +08:00
parent a62b83f488
commit 784a3135c1
2 changed files with 49 additions and 28 deletions

View File

@@ -80,20 +80,27 @@ _TRIGGER_ZH = {
"weekly_insight": "全景電商洞察分析",
}
_AGENT_ZH = {
"hermes": "Hermes 分析師",
"nemotron": "NemoTron 監控",
"openclaw": "OpenClaw 策略師",
"scheduler": "排程器",
"?": "未知模組",
# Agent 名稱保留英文,僅補上角色說明(禁止音譯)
_AGENT_LABEL = {
"hermes": "Hermes",
"nemotron": "NemoTron",
"openclaw": "OpenClaw",
"elephant_alpha": "Elephant Alpha",
"scheduler": "Scheduler",
}
_ACTION_ZH = {
"analyze_price_competition": "競品價格分析",
"dispatch_alert": "派送告警通知",
"generate_strategic_analysis": "產出策略分析報告",
"adjust_price": "調整定價",
"send_alert": "發送告警",
"analyze_price_competition": "競品價格分析",
"dispatch_alert": "派送告警通知",
"dispatch_price_updates": "派送定價更新",
"dispatch_price_update": "派送定價更新",
"generate_strategic_analysis": "產出策略分析",
"generate_weekly_strategy": "產出全景週報",
"generate_market_analysis": "市場分析",
"generate_pricing_strategy": "定價策略建議",
"generate_meta_analysis": "AI 系統自我審視",
"adjust_price": "調整定價",
"send_alert": "發送告警",
}
@@ -102,9 +109,13 @@ def _zh_trigger(trigger_type: str) -> str:
def _zh_step(step: dict) -> str:
agent = _AGENT_ZH.get(step.get("agent", "?"), step.get("agent", "?"))
action = _ACTION_ZH.get(step.get("action", ""), step.get("action", "?"))
return f"[{agent}] {action}"
agent_key = step.get("agent", "?").lower()
agent = _AGENT_LABEL.get(agent_key, step.get("agent", "?"))
action = _ACTION_ZH.get(step.get("action", ""), step.get("action", ""))
desc = step.get("description", "")
# 優先用 descriptionGemini 生成的繁中說明),其次用 action 中文對照
detail = desc if desc else action
return f"[{agent}] {detail}"
@dataclass
@@ -563,17 +574,23 @@ class ElephantAlphaAutonomousEngine:
trigger: AutonomousTrigger,
) -> None:
try:
from services.telegram_templates import triaged_alert, _send_telegram_raw
msg, keyboard = triaged_alert(
base_event={
"event_type": trigger.trigger_type,
"title": f"🐘 EA 自主執行完畢 · {_zh_trigger(trigger.trigger_type)}",
"summary": decision.expected_outcome or "EA 完成自主決策",
"id": f"ea_{trigger.trigger_type}_{int(datetime.now().timestamp())}",
},
tier_label="🐘 Elephant Alpha · 自主執行",
ai_summary=(decision.reasoning or "")[:300],
ai_executed=[_zh_step(s) for s in decision.execution_plan[:5]] or ["(無具體執行計畫)"],
from services.telegram_templates import _send_telegram_raw
trigger_zh = _zh_trigger(trigger.trigger_type)
steps = [_zh_step(s) for s in decision.execution_plan[:5]] or ["(無執行步驟)"]
steps_text = "\n".join(f"{s}" for s in steps)
# reasoning 必須含數據;若只是空泛摘要則標記為「待補充」
reasoning = (decision.reasoning or "").strip()
if len(reasoning) < 30:
reasoning = "AI 推理未提供足夠細節)"
msg = (
f"<b>⚡ 🐘 Elephant Alpha · 自主執行 · {trigger.trigger_type}</b>\n"
f"📌 <b>{trigger_zh}</b>\n\n"
f"🔍 <b>預期效益:</b>{(decision.expected_outcome or '').strip()}\n\n"
f"🧠 <b>決策依據:</b>{reasoning[:400]}\n\n"
f"✅ <b>已執行(信心 {decision.confidence:.0%}</b>\n{steps_text}"
)
await self._run_with_timeout(_send_telegram_raw, msg, timeout=10)
self._log.info("Telegram audit sent: %s", trigger.trigger_type)
@@ -633,7 +650,7 @@ class ElephantAlphaAutonomousEngine:
ai_cause=(
f"觸發類型:{_zh_trigger(trigger.trigger_type)} | "
f"信心度:{decision.confidence:.2f} | "
f"參與模組:{', '.join(_AGENT_ZH.get(a, a) for a in decision.agents_required)}"
f"參與模組:{', '.join(_AGENT_LABEL.get(a.lower(), a) for a in decision.agents_required)}"
),
ai_actions=[
f"步驟 {s.get('step', i+1)}{_zh_step(s)}"