"""
demand_grade_agent 工厂 — 组装需求分级评估 Agent。
"""
from __future__ import annotations

from pathlib import Path

from supply_agent import Agent
from supply_agent.config import Settings
from agents.demand_grade_agent.tools import register_all_tools
from supply_infra.agent_prompt_injection import compose_agent_system_prompt

_PROMPT_PATH = Path(__file__).parent / "prompt" / "system_prompt.md"
DEMAND_GRADE_AGENT_SYSTEM_PROMPT = _PROMPT_PATH.read_text(encoding="utf-8")


def create_demand_grade_agent(
    settings: Settings | None = None,
    *,
    model: str | None = None,
) -> Agent:
    """创建 demand_grade_agent 实例，注册专属工具。"""
    agent = Agent(
        settings=settings,
        name="demand_grade_agent",
        model=model,
        system_prompt=compose_agent_system_prompt(
            DEMAND_GRADE_AGENT_SYSTEM_PROMPT,
            "demand_grade_agent",
        ),
        max_iterations=40,
    )
    register_all_tools(agent.tools)
    return agent
