"""
运行配置 — 自动化投放 Agent 系统
"""
from pathlib import Path
from agent.core.runner import RunConfig, KnowledgeConfig

# ===== 工具白名单 =====
# 只暴露业务工具，避免 LLM 误调 IM/知识库/浏览器等非业务工具
ANALYSIS_TOOLS = [
    # 数据查询
    "data_query",
    "data_aggregate",
    "get_ad_current_status",
    # 广告 API（只读）
    "account_get_info",
    "ad_get_list",
    "ad_get_report",
    "creative_get_report",
    "asset_get_list",
    "audience_get_list",
    # 人群定向
    "audience_build_targeting",
    "audience_recommend_targeting",
    # 监控
    "monitor_check_metrics",
]

EXECUTION_TOOLS = ANALYSIS_TOOLS + [
    # 执行类工具（仅执行 Agent 使用）
    "bid_adjustment_execute",
    "ad_create",
    "ad_update",
    "ad_batch_update_status",
    "creative_create",
    "creative_update",
    "monitor_circuit_break",
]

# ===== Main Agent 配置（统一入口） =====
MAIN_CONFIG = RunConfig(
    model="qwen/qwen3.5-plus-02-15",
    temperature=0.3,
    max_iterations=50,
    name="投放决策中枢",
    tools=ANALYSIS_TOOLS + ["agent"],  # 加入 agent 工具用于调度子 Agent
    skills=["planning", "ad_domain"],   # Main Agent 只需要通用知识
    extra_llm_params={"extra_body": {"enable_thinking": True}},
    knowledge=KnowledgeConfig(
        enable_extraction=False,
        enable_completion_extraction=False,
        enable_injection=False,
        owner="ad_placement_team",
    ),
)

# ===== Budget Agent 配置 =====
BUDGET_CONFIG = RunConfig(
    model="qwen/qwen3.5-plus-02-15",
    temperature=0.3,
    max_iterations=30,
    name="预算出价Agent",
    tools=[
        # 配置层
        "load_strategy_config", "update_strategy_config", "get_config_history",
        # 数据获取
        "get_ad_performance", "get_account_summary", "data_query",
        # 计算
        "compute_budget_thresholds", "classify_ads", "compute_bid_adjustment",
        # 只读 API
        "ad_get_list", "ad_get_report",
    ],
    skills=["ad_domain", "budget_strategy"],  # 只注入预算相关知识
    extra_llm_params={"extra_body": {"enable_thinking": True}},
    knowledge=KnowledgeConfig(
        enable_extraction=False,
        enable_completion_extraction=False,
        enable_injection=False,
        owner="ad_placement_team",
    ),
)

# ===== 执行 Agent 配置 =====
EXECUTE_CONFIG = RunConfig(
    model="qwen/qwen3.5-plus-02-15",
    temperature=0.1,        # 执行Agent更低温度，减少随机性
    max_iterations=30,
    name="投放执行系统",
    tools=EXECUTION_TOOLS,
    skills=["planning", "ad_domain", "budget_strategy", "monitor_rules"],
    extra_llm_params={"extra_body": {"enable_thinking": True}},
    knowledge=KnowledgeConfig(
        enable_extraction=False,
        enable_completion_extraction=False,
        enable_injection=False,
        owner="ad_placement_team",
    ),
)

# 向后兼容：默认使用 Main Agent
RUN_CONFIG = MAIN_CONFIG

# 基础设施配置
SKILLS_DIR = str(Path(__file__).parent / "skills")
TRACE_STORE_PATH = ".trace"
LOG_LEVEL = "INFO"
LOG_FILE = None
