register.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. """将 runcomfy_workflow_builder 注册到 Tool Agent Registry (PostgreSQL)
  2. 运行: python tools/local/runcomfy_workflow_builder/register.py
  3. """
  4. import sys
  5. from pathlib import Path
  6. # 确保能 import tool_agent
  7. sys.path.insert(0, str(Path(__file__).resolve().parents[3] / "src"))
  8. from tool_agent.tool.tool_store import PostgreSQLToolStore
  9. TOOL_ID = "runcomfy_workflow_builder"
  10. TOOL_DATA = {
  11. "id": TOOL_ID,
  12. "name": "RunComfy Workflow Builder",
  13. "version": "1.0.0",
  14. "introduction": (
  15. "ComfyUI 工作流构建辅助工具。提供模型查询、节点 Schema 检索、示例工作流浏览/加载、工作流验证等能力。"
  16. "⚠️ 首次使用请先调用 action=read_skill 获取完整使用指南,了解 API JSON 格式规则和架构差异后再构建工作流。"
  17. ),
  18. "tutorial": (
  19. "调用方式: POST /run_tool {tool_id: 'runcomfy_workflow_builder', params: {action: '...', ...}}\n"
  20. "\n"
  21. "支持的 action:\n"
  22. " read_skill - 【首次必读】返回 skill.md 使用指南\n"
  23. " search_models - 查询环境中可用的 checkpoint/lora/vae/controlnet\n"
  24. " get_node_schema - 获取 ComfyUI 节点的参数定义\n"
  25. " list_examples - 浏览/搜索示例工作流库 (70+)\n"
  26. " load_example - 加载具体示例 JSON 作为参考模板\n"
  27. " verify_workflow - 验证手写 API JSON 的合法性\n"
  28. "\n"
  29. "推荐流程: read_skill → list_examples → load_example → search_models → 修改 → verify_workflow → 交给 executor"
  30. ),
  31. "input": {
  32. "type": "object",
  33. "properties": {
  34. "action": {
  35. "type": "string",
  36. "description": "要执行的操作。⚠️ 首次使用请先调用 read_skill 了解完整规则。",
  37. "enum": ["read_skill", "search_models", "get_node_schema", "list_examples", "load_example", "verify_workflow"]
  38. },
  39. "category": {
  40. "type": "string",
  41. "description": "模型分类(checkpoints/loras/vaes/controlnets) 或示例分类(flux/controlnet/inpaint/...)"
  42. },
  43. "keyword": {
  44. "type": "string",
  45. "description": "搜索关键词(大小写不敏感)"
  46. },
  47. "class_type": {
  48. "type": "string",
  49. "description": "ComfyUI 节点类型名 (get_node_schema 用),如 KSampler、ControlNetApplySD3"
  50. },
  51. "name": {
  52. "type": "string",
  53. "description": "示例工作流名称 (load_example 用),支持 stem/路径/部分关键词"
  54. },
  55. "workflow": {
  56. "type": "object",
  57. "description": "待验证的 ComfyUI API JSON 字典 (verify_workflow 用)"
  58. }
  59. },
  60. "required": ["action"]
  61. },
  62. "output": {
  63. "type": "object",
  64. "description": "根据 action 不同返回不同结构,均包含 action 字段标识操作类型"
  65. },
  66. "updated_time": 0,
  67. "status": "已接入",
  68. }
  69. if __name__ == "__main__":
  70. print(f"Registering tool: {TOOL_ID}")
  71. store = PostgreSQLToolStore()
  72. store.insert_or_update(TOOL_DATA)
  73. store.close()
  74. print(f"✅ Tool '{TOOL_ID}' registered successfully.")
  75. print(f" Description: {TOOL_DATA['introduction'][:80]}...")
  76. print(f" Actions: {TOOL_DATA['input']['properties']['action']['enum']}")