diff --git a/templates/admin/agent_orchestration.html b/templates/admin/agent_orchestration.html index c4f4d23..32b45f9 100644 --- a/templates/admin/agent_orchestration.html +++ b/templates/admin/agent_orchestration.html @@ -1,257 +1,28 @@ {% extends "ewoooc_base.html" %} -{% block title %}Agent 編排矩陣{% endblock %} +{% block title %}Agent 指揮矩陣{% endblock %} {% block ewooo_content %} + +
-

Agent 編排矩陣 - {{ hours }}h 內 4 Agent × Ollama × Gemini × MCP × RAG 協作全景 -

+
Agent Command Matrix · {{ hours }}h Window

Agent 指揮矩陣

這頁回答 AI 中樞如何分工:誰在用 Ollama、誰還在吃付費 LLM、哪些 Agent 有 RAG 命中、哪些工作流已經接上 MCP。這不是列表,是指揮官視角。

{% if overall %}
Total Calls
{{ "{:,}".format(overall.total_calls) }}{{ "{:,}".format(overall.total_tokens) }} tokens
Ollama Share
{{ "%.0f"|format(overall.local_pct) }}%{{ "{:,}".format(overall.local_calls) }} local calls
Paid Cost
${{ "%.2f"|format(overall.total_cost) }}{{ "{:,}".format(overall.paid_calls) }} paid calls
RAG Rate
{{ "%.0f"|format(overall.rag_rate) }}%{{ "{:,}".format(overall.rag_hits) }} hits
{% endif %}
+ {% if error %}
{{ error }}
{% endif %} - {% if error %} -
{{ error }}
- {% endif %} +
+
+
4 Agent Matrix

LLM × MCP × RAG 編排矩陣

{% for ag in agent_matrix %}{% endfor %}
Agent呼叫成本Ollama付費MCPRAG錯誤耗時
{{ ag.label }}{{ ag.desc }}{% if ag.calls > 0 %}{{ "{:,}".format(ag.calls) }}{{ "{:,}".format(ag.tokens) }} tk{% else %}{% endif %}{% if ag.calls > 0 %}${{ "%.2f"|format(ag.cost) }}{% else %}{% endif %}{% if ag.calls > 0 %}{{ "%.0f"|format(ag.ollama_pct) }}%A {{ ag.ollama_gcp_a }} · B {{ ag.ollama_gcp_b }} · 111 {{ ag.ollama_111 }}{% else %}{% endif %}{% if ag.calls > 0 %}{{ "%.0f"|format(ag.paid_pct) }}%Gemini {{ ag.gemini }}{% if ag.other_paid %} · 其他 {{ ag.other_paid }}{% endif %}{% else %}{% endif %}{% if ag.calls > 0 %}{{ "%.1f"|format(ag.mcp_rate) }}%{{ ag.mcp_calls }}{% else %}{% endif %}{% if ag.calls > 0 %}{{ "%.1f"|format(ag.rag_rate) }}%{{ ag.rag_hits }}{% else %}{% endif %}{% if ag.calls > 0 %}{{ "%.1f"|format(ag.error_rate) }}%{{ ag.errors }}{% else %}{% endif %}{% if ag.calls > 0 %}{{ ag.avg_ms }} ms{% else %}{% endif %}
+
+ +
- -
-
- -
-
- - - {% if overall %} -
-
-
-
- 總呼叫 -

{{ "{:,}".format(overall.total_calls) }}

- Token:{{ "{:,}".format(overall.total_tokens) }} -
-
-
-
-
-
- 本地 Ollama 比例 -

{{ "%.0f"|format(overall.local_pct) }}%

- {{ "{:,}".format(overall.local_calls) }} 呼叫 -
-
-
-
-
-
- 付費 LLM 成本 -

${{ "%.2f"|format(overall.total_cost) }}

- {{ "{:,}".format(overall.paid_calls) }} 付費呼叫({{ "%.0f"|format(overall.paid_pct) }}%) -
-
-
-
-
-
- RAG 命中率 -

{{ "%.0f"|format(overall.rag_rate) }}%

- {{ "{:,}".format(overall.rag_hits) }} hits -
-
-
-
- {% endif %} - - -
-
- 4 Agent × LLM × MCP × RAG 矩陣 - 資料來源:ai_calls × mcp_calls × rag_query_log(caller 自動分組) -
-
- - - - - - - - - - - - - - - - {% for ag in agent_matrix %} - - - - - - - - - - - - {% endfor %} - -
Agent呼叫成本本地 Ollama付費 LLMMCP 編排RAG 命中錯誤率耗時
- {{ ag.label }} - {{ ag.desc }} - - {% if ag.calls > 0 %} - {{ "{:,}".format(ag.calls) }} - {{ "{:,}".format(ag.tokens) }} tk - {% else %} - - {% endif %} - - {% if ag.calls > 0 %} - ${{ "%.2f"|format(ag.cost) }} - {% else %} - - {% endif %} - - {% if ag.calls > 0 %} - {{ "%.0f"|format(ag.ollama_pct) }}% - - GCP-A {{ ag.ollama_gcp_a }} · - GCP-B {{ ag.ollama_gcp_b }} · - 111 {{ ag.ollama_111 }} - - {% else %} - - {% endif %} - - {% if ag.calls > 0 %} - - {{ "%.0f"|format(ag.paid_pct) }}% - - - Gemini {{ ag.gemini }}{% if ag.other_paid %} · 其他 {{ ag.other_paid }}{% endif %} - - {% else %} - - {% endif %} - - {% if ag.calls > 0 %} - - {{ "%.1f"|format(ag.mcp_rate) }}% - - {{ ag.mcp_calls }} request_id - {% else %} - - {% endif %} - - {% if ag.calls > 0 %} - {{ "%.1f"|format(ag.rag_rate) }}% - {{ ag.rag_hits }} hits - {% else %} - - {% endif %} - - {% if ag.calls > 0 %} - - {{ "%.1f"|format(ag.error_rate) }}% - - {{ ag.errors }} 次 - {% else %} - - {% endif %} - - {% if ag.calls > 0 %}{{ ag.avg_ms }} ms{% else %}{% endif %} -
-
- -
- - - {% if recommendations %} -
-
- 編排策略自動建議 - — rule-based 規則引擎,5 條判斷 -
-
-
    - {% for r in recommendations %} -
  • - {{ r.severity|upper }} - {{ r.agent }} -
    - 發現:{{ r.finding }} -
    -
    - 建議:{{ r.suggestion }} -
    -
  • - {% endfor %} -
-
-
- {% endif %} - - - {% if mcp_matrix %} -
-
- MCP server × caller 工作量明細 - 資料來源:mcp_calls(過去 {{ hours }}h,前 30 筆) -
-
- - - - - - - - - - - - - {% for m in mcp_matrix %} - - - - - - - - - {% endfor %} - -
MCP Server呼叫端 (caller)tool 呼叫cache 命中cache 率成本
{{ m.server }}{{ m.caller }}{{ "{:,}".format(m.calls) }}{{ m.cache_hits }} - - {{ "%.0f"|format(m.cache_rate) }}% - - ${{ "%.4f"|format(m.cost) }}
-
-
- {% endif %} - -

- Operation Ollama-First v5.0 / Phase 46 — Agent 編排矩陣 - (8 表跨 JOIN:ai_calls × mcp_calls × rag_query_log × ai_insights × learning_episodes - × incidents × heal_logs × host_health_probes) -

+ {% if recommendations %}
Rules

編排策略自動建議

{% for r in recommendations %}
{{ r.severity|upper }}{{ r.agent }}
發現:{{ r.finding }}
建議:{{ r.suggestion }}
{% endfor %}
{% endif %} + {% if mcp_matrix %}
MCP Detail

MCP server × caller 工作量

{% for m in mcp_matrix %}{% endfor %}
MCP ServerCallertool 呼叫cachecache 率成本
{{ m.server }}{{ m.caller }}{{ "{:,}".format(m.calls) }}{{ m.cache_hits }}{{ "%.0f"|format(m.cache_rate) }}%${{ "%.4f"|format(m.cost) }}
{% endif %} +

Operation Ollama-First v5.0 — Agent 指揮矩陣

{% endblock %} diff --git a/templates/admin/business_intel.html b/templates/admin/business_intel.html index bf0d33a..eac109e 100644 --- a/templates/admin/business_intel.html +++ b/templates/admin/business_intel.html @@ -1,375 +1,682 @@ {% extends "ewoooc_base.html" %} +{% set active_page = 'obs_business' %} +{% block title %}商業 AI 戰果室{% endblock %} -{% block title %}商業面 × AI 編排{% endblock %} +{% block extra_head %} + +{% endblock %} + +{% block content %} +{% set rec_total = rec_by_strategy|sum(attribute='count') if rec_by_strategy else 0 %} +{% set ns = namespace(conf_total=0, effective=0, backfired=0, neutral=0, verdict_total=0) %} +{% for r in rec_by_strategy %} + {% set ns.conf_total = ns.conf_total + ((r.avg_confidence or 0) * (r.count or 0)) %} +{% endfor %} +{% for v in verdict_stats %} + {% set label = v.verdict or 'unknown' %} + {% set ns.verdict_total = ns.verdict_total + (v.count or 0) %} + {% if label == 'effective' or label == 'success' or label == 'positive' %} + {% set ns.effective = ns.effective + (v.count or 0) %} + {% elif label == 'backfired' or label == 'negative' or label == 'failed' %} + {% set ns.backfired = ns.backfired + (v.count or 0) %} + {% else %} + {% set ns.neutral = ns.neutral + (v.count or 0) %} + {% endif %} +{% endfor %} +{% set avg_conf = (ns.conf_total / rec_total) if rec_total else 0 %} +{% set effective_rate = ((ns.effective / ns.verdict_total) * 100) if ns.verdict_total else 0 %} + +
+
+
+ Business Intelligence +

商業 AI
戰果室

+

+ 這一頁不再只是資料列表,而是把價格建議、未跟進警示、閉環學習與競品監測收成一個商業決策控制台。 + 先看 AI 是否真的推動結果,再往下追每一筆策略與市場訊號。 +

+
+ 近 {{ days }} 天 + {{ rec_total }} 筆價格建議 + {{ ns.verdict_total }} 筆閉環結果 +
+
+ + +
+ + {% if error %} +
{{ error }}
+ {% endif %} + +
+
+
高信心未跟進
+
{{ unfollowed_count }}
+
confidence >= 0.8 且仍未轉 action_plan
+
+
+
平均信心分
+
{{ '%.0f'|format(avg_conf * 100) }}%
+
依策略建議量加權
+
+
+
有效率
+
{{ '%.0f'|format(effective_rate) }}%
+
effective / 已回收 verdict
+
+
+
競品監測
+
{{ recent_competitor_prices|length }}
+
近 24h 價格變動樣本
+
+
+ + {% if unfollowed_count > 0 %} +
+
{{ unfollowed_count }} 筆高信心 AI 價格建議尚未跟進,建議優先轉為 action_plan 或標記原因。
+ 需人工決策 +
+ {% endif %} + +
+
+
+
+
+

策略族群雷達

+

把 AI 價格建議依 strategy 聚合,快速判斷目前主攻降價、防守或毛利修復。

+
+ {{ rec_by_strategy|length }} 類策略 +
+
+ {% if rec_by_strategy %} +
+ {% for r in rec_by_strategy %} +
+
{{ r.strategy or 'unknown' }}
+
+
{{ r.count }}建議數
+
{{ '%.0f'|format((r.avg_confidence or 0) * 100) }}%信心
+
{{ '%.1f'|format(r.avg_gap_pct or 0) }}%價差
+
+
平均銷量變化 {{ '%.1f'|format(r.avg_sales_delta or 0) }}
+
+ {% endfor %} +
+ {% else %} +
目前觀測窗口沒有策略建議。
+ {% endif %} +
+
+ +
+
+
+

最近 AI 價格建議

+

保留決策原因與競品價差,方便直接追到 SKU 層級。

+
+ Latest 20 +
+
+ {% if latest_recommendations %} + + + + + + + + + + + + + + {% for r in latest_recommendations %} + + + + + + + + + + {% endfor %} + +
時間SKU商品策略信心momo / PChome原因
{{ r.created_at.strftime('%m-%d %H:%M') if r.created_at else '-' }}{{ r.sku }}{{ r.name or '-' }}{{ r.strategy or '-' }}{{ '%.0f'|format((r.confidence or 0) * 100) }}%{{ r.momo_price or '-' }} / {{ r.pchome_price or '-' }}
gap {{ '%.1f'|format(r.gap_pct or 0) }}%
{{ r.reason or '-' }}
+ {% else %} +
目前沒有最新價格建議。
+ {% endif %} +
+
+ +
+
+
+

閉環學習紀錄

+

追蹤 action_plan 到 outcome 的真實效果,這是 AI 能不能變聰明的核心證據。

+
+ {{ loop_records|length }} records +
+
+ {% if loop_records %} + + + + + + + + + + + + + + {% for r in loop_records %} + + + + + + + + + + {% endfor %} + +
PlanSKU狀態建立 / 執行Verdict指標變化
#{{ r.plan_id }}
{{ r.plan_type or '-' }}
{{ r.sku }}{{ r.status or '-' }}{{ r.created_at.strftime('%m-%d') if r.created_at else '-' }} / {{ r.executed_at.strftime('%m-%d') if r.executed_at else '-' }}{{ r.verdict or '-' }}{{ r.metric_type or '-' }}
{{ r.before or '-' }} → {{ r.after or '-' }}
{{ '%.1f'|format(r.change_pct or 0) }}%
+ {% else %} +
尚未形成 action_plan → outcome 閉環紀錄。
+ {% endif %} +
+
+
+ + +
+ +
資料來源:ai_price_recommendations / action_plans / action_outcomes / competitor_match_attempts / competitor_price_history
{% endblock %} + +{% block extra_scripts %} + + +{% endblock %}