Jelajahi Sumber

refactor(auto_put_ad_mini): 加入portfolio_metrics到pipeline+重命名ABC分类

- execute_once.py/run.py: 导入calculate_portfolio_summary工具,
  pipeline新增"人群包基线计算"步骤
- 所有"A/B/C类"描述替换为语义化名称:
  零消耗待关停 / 待评估(候选) / 正常运行
- analyze_snapshot.py: case_A/B/C/D → pass/tune_prompt/deep_judge/refine_tier

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
刘立冬 3 minggu lalu
induk
melakukan
0c6cb229f8

+ 6 - 6
examples/auto_put_ad_mini/analyze_snapshot.py

@@ -19,7 +19,7 @@ V4 决策快照分析 — 实测观测用
   6. 信号健康度(decay/bid_down/bid_up 分布)
   6. 信号健康度(decay/bid_down/bid_up 分布)
   7. 同桶决策一致性(抽样熵)
   7. 同桶决策一致性(抽样熵)
   8. 上下文规模估算
   8. 上下文规模估算
-  9. A/B/C/D 判定
+  9. 质量评级判定
 """
 """
 import argparse
 import argparse
 import json
 import json
@@ -302,7 +302,7 @@ def build_report(snapshot: Dict) -> Dict:
 
 
 
 
 def assess(report: Dict) -> Tuple[str, List[str]]:
 def assess(report: Dict) -> Tuple[str, List[str]]:
-    """A/B/C/D 判定"""
+    """决策质量评级判定"""
     flags: List[str] = []
     flags: List[str] = []
 
 
     # bid_down 多样性
     # bid_down 多样性
@@ -340,14 +340,14 @@ def assess(report: Dict) -> Tuple[str, List[str]]:
 
 
     # 分支判定
     # 分支判定
     if not flags:
     if not flags:
-        return "case_A: V4 架构够用,可进入后验采集下一 plan", flags
+        return "pass: 架构够用,可进入后验采集下一 plan", flags
     for f in flags:
     for f in flags:
         if "token" in f:
         if "token" in f:
-            return "case_D: tier 细分桶 / signal_scores 精简", flags
+            return "refine_tier: tier 细分桶 / signal_scores 精简", flags
     for f in flags:
     for f in flags:
         if "决策熵" in f:
         if "决策熵" in f:
-            return "case_C: 考虑对边缘案例单条深判", flags
-    return "case_B: 调 prompt 或 DECAY_WEIGHTS", flags
+            return "deep_judge: 考虑对边缘案例单条深判", flags
+    return "tune_prompt: 调 prompt 或 DECAY_WEIGHTS", flags
 
 
 
 
 # ═══════════════════════════════════════════
 # ═══════════════════════════════════════════

+ 9 - 2
examples/auto_put_ad_mini/execute_once.py

@@ -28,6 +28,7 @@ from examples.auto_put_ad_mini.config import (
 # 导入自定义工具
 # 导入自定义工具
 from examples.auto_put_ad_mini.tools.data_query import fetch_creative_data, merge_creative_data
 from examples.auto_put_ad_mini.tools.data_query import fetch_creative_data, merge_creative_data
 from examples.auto_put_ad_mini.tools.roi_calculator import calculate_roi_metrics
 from examples.auto_put_ad_mini.tools.roi_calculator import calculate_roi_metrics
+from examples.auto_put_ad_mini.tools.portfolio_metrics import calculate_portfolio_summary
 from examples.auto_put_ad_mini.tools.ad_decision import get_ads_for_review, apply_decisions, query_ad_detail, modify_decisions
 from examples.auto_put_ad_mini.tools.ad_decision import get_ads_for_review, apply_decisions, query_ad_detail, modify_decisions
 from examples.auto_put_ad_mini.tools.report_generator import generate_report
 from examples.auto_put_ad_mini.tools.report_generator import generate_report
 from examples.auto_put_ad_mini.tools.guardrails import validate_decisions
 from examples.auto_put_ad_mini.tools.guardrails import validate_decisions
@@ -77,7 +78,7 @@ async def main():
     print("🚀 自动执行:分析广告")
     print("🚀 自动执行:分析广告")
     print()
     print()
     print("=" * 70)
     print("=" * 70)
-    print("  流程:数据拉取 → ROI计算 → 分类(A/B/C) → AI推理 → 保存决策 → 护栏验证 → 生成报告")
+    print("  流程:数据拉取 → ROI计算 → 人群包基线 → 候选筛选 → AI推理 → 保存决策 → 护栏验证 → 生成报告")
     print("=" * 70)
     print("=" * 70)
     print()
     print()
 
 
@@ -121,10 +122,16 @@ async def main():
                             print(f"📌 步骤 {step_count}: ROI 计算")
                             print(f"📌 步骤 {step_count}: ROI 计算")
                             print(f"{'='*70}")
                             print(f"{'='*70}")
 
 
+                        elif tool_name == "calculate_portfolio_summary":
+                            step_count += 1
+                            print(f"\n{'='*70}")
+                            print(f"📌 步骤 {step_count}: 人群包基线计算")
+                            print(f"{'='*70}")
+
                         elif tool_name == "get_ads_for_review":
                         elif tool_name == "get_ads_for_review":
                             step_count += 1
                             step_count += 1
                             print(f"\n{'='*70}")
                             print(f"\n{'='*70}")
-                            print(f"📌 步骤 {step_count}: 广告分类(A/B/C)")
+                            print(f"📌 步骤 {step_count}: 候选筛选(零消耗/待评估/正常运行)")
                             print(f"{'='*70}")
                             print(f"{'='*70}")
 
 
                         elif tool_name == "apply_decisions":
                         elif tool_name == "apply_decisions":

+ 6 - 6
examples/auto_put_ad_mini/quick_analysis.py

@@ -62,14 +62,14 @@ async def main():
     if json_match:
     if json_match:
         review_data = json.loads(json_match.group(1))
         review_data = json.loads(json_match.group(1))
         print(f"✅ 分类完成:")
         print(f"✅ 分类完成:")
-        print(f"   A类(极端差): {review_data.get('a_count', 0)} 个")
-        print(f"   B类(边缘): {review_data.get('b_count', 0)} 个")
-        print(f"   C类(正常): {review_data.get('c_count', 0)} 个")
+        print(f"   零消耗待关停: {review_data.get('a_count', 0)} 个")
+        print(f"   待评估(候选): {review_data.get('b_count', 0)} 个")
+        print(f"   正常运行: {review_data.get('c_count', 0)} 个")
         print(f"   📊 全局统计: ROI均值={review_data.get('roi_mean_all', 0):.2f}")
         print(f"   📊 全局统计: ROI均值={review_data.get('roi_mean_all', 0):.2f}")
 
 
-        # 展示B类广告样例
+        # 展示待评估广告样例
         if 'b_ads' in review_data and len(review_data['b_ads']) > 0:
         if 'b_ads' in review_data and len(review_data['b_ads']) > 0:
-            print(f"\n📋 B类广告样例(需AI推理):")
+            print(f"\n📋 待评估广告样例(需AI推理):")
             for i, ad in enumerate(review_data['b_ads'][:3], 1):
             for i, ad in enumerate(review_data['b_ads'][:3], 1):
                 print(f"\n  {i}. 广告 {ad.get('ad_id')}")
                 print(f"\n  {i}. 广告 {ad.get('ad_id')}")
                 print(f"     ROI: {ad.get('动态ROI_7日均值', 0):.2f}  消耗: {ad.get('cost_7d_avg', 0):.0f}元/天")
                 print(f"     ROI: {ad.get('动态ROI_7日均值', 0):.2f}  消耗: {ad.get('cost_7d_avg', 0):.0f}元/天")
@@ -79,7 +79,7 @@ async def main():
 
 
     print()
     print()
     print("=" * 70)
     print("=" * 70)
-    print("✅ 分析完成 — 现在可以让Agent基于B类广告进行AI推理决策")
+    print("✅ 分析完成 — 现在可以让Agent基于待评估广告进行AI推理决策")
     print("=" * 70)
     print("=" * 70)
 
 
 
 

+ 9 - 2
examples/auto_put_ad_mini/run.py

@@ -34,6 +34,7 @@ from examples.auto_put_ad_mini.config import (
 # 导入自定义工具(触发 @tool 注册)
 # 导入自定义工具(触发 @tool 注册)
 from examples.auto_put_ad_mini.tools.data_query import fetch_creative_data, merge_creative_data
 from examples.auto_put_ad_mini.tools.data_query import fetch_creative_data, merge_creative_data
 from examples.auto_put_ad_mini.tools.roi_calculator import calculate_roi_metrics
 from examples.auto_put_ad_mini.tools.roi_calculator import calculate_roi_metrics
+from examples.auto_put_ad_mini.tools.portfolio_metrics import calculate_portfolio_summary
 from examples.auto_put_ad_mini.tools.ad_decision import (
 from examples.auto_put_ad_mini.tools.ad_decision import (
     get_ads_for_review, apply_decisions,
     get_ads_for_review, apply_decisions,
     query_ad_detail, modify_decisions,
     query_ad_detail, modify_decisions,
@@ -135,7 +136,7 @@ async def main():
 
 
             print(f"\n🚀 执行: {user_input}")
             print(f"\n🚀 执行: {user_input}")
             print("=" * 70)
             print("=" * 70)
-            print("  流程:数据拉取 → ROI计算 → 分类(A/B/C) → AI推理 → 保存决策 → 护栏验证 → 生成报告")
+            print("  流程:数据拉取 → ROI计算 → 人群包基线 → 候选筛选 → AI推理 → 保存决策 → 护栏验证 → 生成报告")
             print("=" * 70)
             print("=" * 70)
             print()
             print()
 
 
@@ -177,10 +178,16 @@ async def main():
                                 print(f"📌 步骤 {step_count}: ROI 计算")
                                 print(f"📌 步骤 {step_count}: ROI 计算")
                                 print(f"{'='*70}")
                                 print(f"{'='*70}")
 
 
+                            elif tool_name == "calculate_portfolio_summary":
+                                step_count += 1
+                                print(f"\n{'='*70}")
+                                print(f"📌 步骤 {step_count}: 人群包基线计算")
+                                print(f"{'='*70}")
+
                             elif tool_name == "get_ads_for_review":
                             elif tool_name == "get_ads_for_review":
                                 step_count += 1
                                 step_count += 1
                                 print(f"\n{'='*70}")
                                 print(f"\n{'='*70}")
-                                print(f"📌 步骤 {step_count}: 广告分类(A/B/C)")
+                                print(f"📌 步骤 {step_count}: 候选筛选(零消耗/待评估/正常运行)")
                                 print(f"{'='*70}")
                                 print(f"{'='*70}")
 
 
                             elif tool_name == "query_ad_detail":
                             elif tool_name == "query_ad_detail":

+ 1 - 1
examples/auto_put_ad_mini/tools/ad_decision.py

@@ -729,7 +729,7 @@ async def get_ads_for_review(
 # ═══════════════════════════════════════════
 # ═══════════════════════════════════════════
 
 
 
 
-@tool(description="智能引擎:接收LLM的决策列表,合并A/C类自动决策,保存为结构化结果")
+@tool(description="智能引擎:接收LLM的决策列表,合并零消耗/正常运行类自动决策,保存为结构化结果")
 async def apply_decisions(
 async def apply_decisions(
     ctx: ToolContext,
     ctx: ToolContext,
     decisions: str,
     decisions: str,