agent_catalog.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """Read-only catalog for the business Agents shown in the web console."""
  2. from __future__ import annotations
  3. from importlib import import_module
  4. from pathlib import Path
  5. from typing import Any
  6. _PROJECT_ROOT = Path(__file__).resolve().parents[2]
  7. _AGENTS: dict[str, dict[str, str]] = {
  8. "demand_belong_category_agent": {
  9. "display_name": "分配 Agent",
  10. "subtitle": "语义归属与分类挂载",
  11. "prompt_path": "agents/demand_belong_category_agent/prompt/system_prompt.md",
  12. "tools_module": "agents.demand_belong_category_agent.tools",
  13. },
  14. "demand_grade_agent": {
  15. "display_name": "分等级 Agent",
  16. "subtitle": "证据融合与优先级判断",
  17. "prompt_path": "agents/demand_grade_agent/prompt/system_prompt.md",
  18. "tools_module": "agents.demand_grade_agent.tools",
  19. },
  20. "demand_video_expand_agent": {
  21. "display_name": "拓展 Agent",
  22. "subtitle": "视频点位与需求拓展",
  23. "prompt_path": "agents/demand_video_expand_agent/prompt/system_prompt.md",
  24. "tools_module": "agents.demand_video_expand_agent.tools",
  25. },
  26. }
  27. def get_agent_detail(agent_name: str) -> dict[str, Any] | None:
  28. """Return the current system prompt and registered tool definitions."""
  29. spec = _AGENTS.get(agent_name)
  30. if spec is None:
  31. return None
  32. prompt_path = _PROJECT_ROOT / spec["prompt_path"]
  33. prompt = prompt_path.read_text(encoding="utf-8")
  34. tools_module = import_module(spec["tools_module"])
  35. tools = []
  36. for tool_fn in tools_module.ALL_TOOLS:
  37. tools.append(
  38. {
  39. "name": getattr(tool_fn, "_tool_name", tool_fn.__name__),
  40. "description": getattr(
  41. tool_fn,
  42. "_tool_description",
  43. (tool_fn.__doc__ or "").strip(),
  44. ),
  45. "parameters": getattr(tool_fn, "_tool_parameters", {}),
  46. }
  47. )
  48. return {
  49. "name": agent_name,
  50. "display_name": spec["display_name"],
  51. "subtitle": spec["subtitle"],
  52. "system_prompt": prompt,
  53. "tools": tools,
  54. }