| 1234567891011121314151617181920212223242526272829303132333435363738 |
- """
- find_agent — 老年受众高潜视频发现 Agent
- 职责:按需求搜索抖音视频,结合内容、分享行为和双侧年龄画像进行筛选。
- """
- from __future__ import annotations
- import logging
- from agents.find_agent.agent import create_find_agent
- from agents.find_agent.async_runner import _run_coroutine, arun_find_agent
- from agents.find_agent.output_sync import persist_model_recommendations
- from supply_agent.config import Settings
- from supply_agent.types import AgentResult
- __all__ = ["create_find_agent", "run_find_agent"]
- logger = logging.getLogger(__name__)
- def run_find_agent(
- user_input: str,
- *,
- settings: Settings | None = None,
- model: str | None = None,
- ) -> AgentResult:
- """同步运行 find_agent。
- find_agent 的搜索/详情/画像等工具均为 async,不能直接用 agent.run();
- 此函数内部会走 agent.arun(),并在结束前关闭异步 HTTP 客户端。
- """
- agent = create_find_agent(settings=settings, model=model)
- result = _run_coroutine(arun_find_agent(agent, user_input))
- try:
- persist_model_recommendations(result)
- except Exception:
- logger.exception("persist model recommendations failed")
- return result
|