from __future__ import annotations

from typing import Any

from .agent import SpiderAgent


def run_task(
    task: str,
    start_url: str,
    output_schema: dict[str, Any] | None = None,
    screenshot_path: str = "artifacts/last.png",
    **agent_kwargs: Any,
) -> dict[str, Any]:
    """以函数方式运行一次智能体任务。"""
    agent = SpiderAgent(**agent_kwargs)
    return agent.run(
        task=task,
        start_url=start_url,
        output_schema=output_schema,
        screenshot_path=screenshot_path,
    )
