Просмотр исходного кода

fix(tools): 数据采集工具使用配置的窗口天数而非硬编码默认值

- fetch_creative_data 和 merge_creative_data 的 days 参数改为从 config.DATA_WINDOW_DAYS 读取
- 移除硬编码的 days=7 默认值,改为 days=None 时自动使用配置值
- 确保 Agent 调用工具时使用正确的 14 天数据窗口

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
刘立冬 1 месяц назад
Родитель
Сommit
b84bea7a93
1 измененных файлов с 18 добавлено и 4 удалено
  1. 18 4
      examples/auto_put_ad_mini/tools/data_query.py

+ 18 - 4
examples/auto_put_ad_mini/tools/data_query.py

@@ -32,6 +32,12 @@ _RAW_DIR = _MINI_DIR / "outputs" / "raw"
 _AD_STATUS_DIR = _MINI_DIR / "outputs" / "ad_status"
 _MERGED_DIR = _MINI_DIR / "outputs" / "merged"
 
+# 从 config 读取数据窗口配置
+import sys
+if str(_MINI_DIR) not in sys.path:
+    sys.path.insert(0, str(_MINI_DIR))
+from config import DATA_WINDOW_DAYS
+
 
 # ===== ODPS 客户端(懒加载) =====
 
@@ -295,22 +301,26 @@ def _fetch_ad_status(bizdate: str) -> Optional[pd.DataFrame]:
 
 # ===== V3 工具:30 天增量采集 =====
 
-@tool(description="拉取 30 天创意级别数据(增量,已有 CSV 的日期跳过)")
+@tool(description="拉取创意级别数据(增量,已有 CSV 的日期跳过)")
 async def fetch_creative_data(
     ctx: ToolContext = None,
-    days: int = 7,
+    days: int = None,
     end_date: str = "yesterday"
 ) -> ToolResult:
     """
     拉取创意级别明细数据(V3)。
 
     Args:
-        days: 回溯天数(默认 30
+        days: 回溯天数(默认使用 config.DATA_WINDOW_DAYS
         end_date: 结束日期(默认 yesterday,格式 YYYYMMDD 或 YYYY-MM-DD)
 
     Returns:
         ToolResult 包含采集摘要
     """
+    # 使用配置的默认值
+    if days is None:
+        days = DATA_WINDOW_DAYS
+
     _RAW_DIR.mkdir(parents=True, exist_ok=True)
     _AD_STATUS_DIR.mkdir(parents=True, exist_ok=True)
 
@@ -547,7 +557,7 @@ def _merge_single_day(biz: str) -> Optional[pd.DataFrame]:
 @tool(description="合并创意数据与广告状态(批量)")
 async def merge_creative_data(
     ctx: ToolContext = None,
-    days: int = 7,
+    days: int = None,
     force: bool = False,
 ) -> ToolResult:
     """
@@ -568,6 +578,10 @@ async def merge_creative_data(
         合并结果摘要
     """
     try:
+        # 使用配置的默认值
+        if days is None:
+            days = DATA_WINDOW_DAYS
+
         # 确定日期范围
         end_dt = datetime.now() - timedelta(days=1)
         dates_to_merge = []