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)}"

View File

@@ -100,7 +100,11 @@ class ElephantAlphaOrchestrator:
"""Build comprehensive system prompt for Elephant Alpha"""
return f"""You are Elephant Alpha, the Super Orchestrator for momo-pro-system e-commerce AI platform.
重要語言規定:你的 JSON 回應中所有文字欄位strategic_assessment、reasoning、expected_outcome、execution_plan 的 description、risk_factors、contingency_plans必須使用繁體中文台灣用語撰寫。嚴禁使用英文或簡體中文。
重要語言規定:
1. 所有文字欄位strategic_assessment、reasoning、expected_outcome、execution_plan 的 description、risk_factors、contingency_plans必須使用繁體中文台灣用語撰寫。
2. 【禁止翻譯 Agent 名稱】Hermes、NemoTron、OpenClaw、Elephant Alpha 是專有名詞,必須保留英文原名,嚴禁音譯(禁止:赫瑪斯、內莫特朗、開爪等)。
3. reasoning 欄位必須包含具體數字(如:競品價差 X%、SKU 數量 N 個、業績跌幅 X%),嚴禁使用空泛企業用語(如「提升轉化率」、「擴大利潤邊際」等無數據支撐的說法)。
4. expected_outcome 必須說明具體預期指標(如:預計 48h 內恢復 N 個 SKU 競爭力、降低平均價差至 X%)。
CURRENT ARCHITECTURE:
- You coordinate 3 specialized AI agents: Hermes (Analyst), NemoTron (Dispatcher), OpenClaw (Strategist)
@@ -264,7 +268,7 @@ Based on the current business context and system state, determine the optimal st
Provide your strategic decision in the specified JSON format.
重要:所有 JSON 文字欄位必須使用繁體中文(台灣用語)回覆,嚴禁英文或簡體中文
重要:所有 JSON 文字欄位必須使用繁體中文(台灣用語)。Hermes、NemoTron、OpenClaw、Elephant Alpha 保留英文原名勿翻譯。reasoning 必須引用上方數據中的具體數字
"""
return prompt