|
|
@@ -20,6 +20,7 @@ Pattern 数据查询工具
|
|
|
【重要】所有作为 Agent tool 注册的函数,必须包含完整的 docstring 签名。
|
|
|
"""
|
|
|
import json
|
|
|
+import os
|
|
|
from typing import Any
|
|
|
|
|
|
from agent import tool
|
|
|
@@ -78,6 +79,33 @@ def _normalize_itemset_ids(itemset_ids: Any) -> list[int]:
|
|
|
return []
|
|
|
|
|
|
|
|
|
+def _env_int(name: str, default: int) -> int:
|
|
|
+ try:
|
|
|
+ return int(os.getenv(name, str(default)))
|
|
|
+ except ValueError:
|
|
|
+ return default
|
|
|
+
|
|
|
+
|
|
|
+def _is_mysql_demand_content_entrypoint() -> bool:
|
|
|
+ return os.getenv("DEMAND_MYSQL_ENTRYPOINT") == "run_existing_execution_mysql"
|
|
|
+
|
|
|
+
|
|
|
+def _compact_itemset_detail_for_mysql(data: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
|
+ if not _is_mysql_demand_content_entrypoint():
|
|
|
+ return data
|
|
|
+ max_post_ids = max(_env_int("DEMAND_ITEMSET_DETAIL_MAX_POST_IDS", 20), 1)
|
|
|
+ compacted: list[dict[str, Any]] = []
|
|
|
+ for raw_itemset in data:
|
|
|
+ itemset = dict(raw_itemset)
|
|
|
+ for key in ("post_ids", "matched_post_ids"):
|
|
|
+ post_ids = itemset.get(key)
|
|
|
+ if isinstance(post_ids, list) and len(post_ids) > max_post_ids:
|
|
|
+ itemset[f"{key}_total"] = len(post_ids)
|
|
|
+ itemset[key] = post_ids[:max_post_ids]
|
|
|
+ compacted.append(itemset)
|
|
|
+ return compacted
|
|
|
+
|
|
|
+
|
|
|
# ============================================================================
|
|
|
# 执行 & 配置 & 分类树
|
|
|
# ============================================================================
|
|
|
@@ -197,6 +225,9 @@ def get_itemset_detail(itemset_ids) -> str:
|
|
|
项集详情列表的JSON字符串,每项含 id, dimension_mode, target_depth, items, post_ids, absolute_support。
|
|
|
"""
|
|
|
itemset_ids = _normalize_itemset_ids(itemset_ids)
|
|
|
+ if _is_mysql_demand_content_entrypoint():
|
|
|
+ max_ids = max(_env_int("DEMAND_ITEMSET_DETAIL_MAX_IDS", 12), 1)
|
|
|
+ itemset_ids = itemset_ids[:max_ids]
|
|
|
params = {"itemset_ids": itemset_ids}
|
|
|
_log_tool_input("get_itemset_detail", params)
|
|
|
|
|
|
@@ -208,7 +239,7 @@ def get_itemset_detail(itemset_ids) -> str:
|
|
|
if not data:
|
|
|
return _log_tool_output("get_itemset_detail", f"未找到 itemset_ids={itemset_ids} 的项集")
|
|
|
|
|
|
- result = json.dumps(data, ensure_ascii=False, indent=2)
|
|
|
+ result = json.dumps(_compact_itemset_detail_for_mysql(data), ensure_ascii=False, indent=2)
|
|
|
return _log_tool_output("get_itemset_detail", result)
|
|
|
|
|
|
|