__init__.py 1.2 KB

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