فهرست منبع

feat(budget): 优化数据传递 - 输出包含JSON数据块

- compute_bid_adjustment 输出增加 JSON 数据块(```json格式)
- bid_adjustment_execute 参数改为 adjustment_plan_json (str)
- 支持解析 {"adjustment_plan": [...]} 或直接数组格式
- 运营确认后,执行Agent可直接复制JSON传递给执行工具
刘立冬 1 ماه پیش
والد
کامیت
a6c1a267c1
1فایلهای تغییر یافته به همراه26 افزوده شده و 2 حذف شده
  1. 26 2
      examples/auto_put_ad/tools/budget_calc.py

+ 26 - 2
examples/auto_put_ad/tools/budget_calc.py

@@ -604,6 +604,13 @@ async def compute_bid_adjustment(
         summary_parts = [f"{label}:{action_counts.get(act, 0)}" for act, label in action_labels]
         summary_parts = [f"{label}:{action_counts.get(act, 0)}" for act, label in action_labels]
         lines.append(f"合计: {' / '.join(summary_parts)} / 冷启动保护:{cold_start_count}")
         lines.append(f"合计: {' / '.join(summary_parts)} / 冷启动保护:{cold_start_count}")
 
 
+        # 添加 JSON 数据块供执行 Agent 使用
+        lines.append("\n" + "=" * 60)
+        lines.append("执行数据(JSON格式,供执行Agent使用):")
+        lines.append("```json")
+        lines.append(json.dumps({"adjustment_plan": results}, ensure_ascii=False, indent=2))
+        lines.append("```")
+
         return ToolResult(
         return ToolResult(
             title=f"出价调整方案({len(results)}条,{strategy})",
             title=f"出价调整方案({len(results)}条,{strategy})",
             output="\n".join(lines),
             output="\n".join(lines),
@@ -632,7 +639,7 @@ async def compute_bid_adjustment(
 
 
 @tool(description="执行出价调整方案,批量调用 API 修改出价")
 @tool(description="执行出价调整方案,批量调用 API 修改出价")
 async def bid_adjustment_execute(
 async def bid_adjustment_execute(
-    adjustment_plan: List[Dict],
+    adjustment_plan_json: str,
     account_id: int,
     account_id: int,
     context: Optional[ToolContext] = None,
     context: Optional[ToolContext] = None,
 ) -> ToolResult:
 ) -> ToolResult:
@@ -640,9 +647,26 @@ async def bid_adjustment_execute(
     批量执行出价调整。
     批量执行出价调整。
 
 
     Args:
     Args:
-        adjustment_plan: 调整方案列表,每项包含 ad_id, new_bid, action
+        adjustment_plan_json: 调整方案 JSON 字符串或列表,每项包含 ad_id, new_bid, action
         account_id: 账户ID
         account_id: 账户ID
     """
     """
+    # 解析 JSON(支持字符串或已解析的列表)
+    if isinstance(adjustment_plan_json, str):
+        try:
+            data = json.loads(adjustment_plan_json)
+            # 如果是 {"adjustment_plan": [...]} 格式,提取列表
+            if isinstance(data, dict) and "adjustment_plan" in data:
+                adjustment_plan = data["adjustment_plan"]
+            else:
+                adjustment_plan = data
+        except json.JSONDecodeError as e:
+            return ToolResult(
+                title="执行失败",
+                output=f"JSON 解析失败: {e}",
+                error=str(e),
+            )
+    else:
+        adjustment_plan = adjustment_plan_json
     success_count = 0
     success_count = 0
     failed_count = 0
     failed_count = 0
     errors = []
     errors = []