"""
Agent 抽象基类。

每个 Agent 负责一个独立任务，通过构造函数注入已有引擎，组合而非重建。
"""

from abc import ABC, abstractmethod
from datetime import datetime


class BaseAgent(ABC):
    """Agent 基类。"""

    name: str = ""
    description: str = ""

    def __init__(self, **engines):
        """
        注入已有基础设施。

        支持的引擎:
            dm: DataManager
            fe: FactorEngine
            bt: VectorBTEngine
            opt: OptunaEngine
            sent: SentimentEngine
            ml_models: dict[str, BaseModel]
        """
        self.dm = engines.get("dm")
        self.fe = engines.get("fe")
        self.bt = engines.get("bt")
        self.opt = engines.get("opt")
        self.sent = engines.get("sent")
        self.ml_models = engines.get("ml_models", {})

    @abstractmethod
    def execute(self, **kwargs) -> dict:
        """执行 Agent 任务，返回结构化结果。"""
        ...

    def log(self, msg: str):
        print(f"[{self.name}] {msg}")

    def _today(self) -> str:
        return datetime.now().strftime("%Y%m%d")
