Files
aiagent/backend/app/core/tools_bootstrap.py
renjianbo de415ca310 feat: add Prompt template library, agent_call inter-agent tool, and RAG memory
- New PromptTemplatePicker component for browsing 13 preset prompt templates
- AgentConfig.vue: "Load from library" button for system prompt
- Agents.vue: "Create from Prompt template" entry with agent node + RAG memory
- seed_prompt_templates.py: 13 preset templates (客服/研发/教育/内容/分析/创意/健康医疗)
- agent_call tool: agents can delegate tasks to other agents (19th builtin tool)
- Created 全能助手 (general orchestrator) and 家庭医生助手 agents
- Switch template-created agents from type:llm to type:agent for full ReAct + RAG

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-03 21:57:30 +08:00

100 lines
3.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""确保内置工具注册到 tool_registryAPI 进程与 Celery Worker 均会导入执行流)。"""
from __future__ import annotations
import logging
import os
logger = logging.getLogger(__name__)
_registered = False
_EXPECTED_BUILTIN = 19
def ensure_builtin_tools_registered() -> None:
"""幂等:注册 file_write / system_info 等内置工具,供工作流 LLM 节点使用。"""
global _registered
if _registered:
return
from app.services.tool_registry import tool_registry
from app.services.builtin_tools import (
http_request_tool,
file_read_tool,
file_write_tool,
text_analyze_tool,
datetime_tool,
math_calculate_tool,
system_info_tool,
json_process_tool,
database_query_tool,
adb_log_tool,
schedule_create_tool,
schedule_list_tool,
schedule_delete_tool,
crypto_util_tool,
random_generate_tool,
send_email_tool,
url_parse_tool,
regex_test_tool,
agent_call_tool,
HTTP_REQUEST_SCHEMA,
FILE_READ_SCHEMA,
FILE_WRITE_SCHEMA,
TEXT_ANALYZE_SCHEMA,
DATETIME_SCHEMA,
MATH_CALCULATE_SCHEMA,
SYSTEM_INFO_SCHEMA,
JSON_PROCESS_SCHEMA,
DATABASE_QUERY_SCHEMA,
ADB_LOG_SCHEMA,
SCHEDULE_CREATE_SCHEMA,
SCHEDULE_LIST_SCHEMA,
SCHEDULE_DELETE_SCHEMA,
CRYPTO_UTIL_SCHEMA,
RANDOM_GENERATE_SCHEMA,
SEND_EMAIL_SCHEMA,
URL_PARSE_SCHEMA,
REGEX_TEST_SCHEMA,
AGENT_CALL_SCHEMA,
)
tool_registry.register_builtin_tool("http_request", http_request_tool, HTTP_REQUEST_SCHEMA)
tool_registry.register_builtin_tool("file_read", file_read_tool, FILE_READ_SCHEMA)
tool_registry.register_builtin_tool("file_write", file_write_tool, FILE_WRITE_SCHEMA)
tool_registry.register_builtin_tool("text_analyze", text_analyze_tool, TEXT_ANALYZE_SCHEMA)
tool_registry.register_builtin_tool("datetime", datetime_tool, DATETIME_SCHEMA)
tool_registry.register_builtin_tool("math_calculate", math_calculate_tool, MATH_CALCULATE_SCHEMA)
tool_registry.register_builtin_tool("system_info", system_info_tool, SYSTEM_INFO_SCHEMA)
tool_registry.register_builtin_tool("json_process", json_process_tool, JSON_PROCESS_SCHEMA)
tool_registry.register_builtin_tool("database_query", database_query_tool, DATABASE_QUERY_SCHEMA)
tool_registry.register_builtin_tool("adb_log", adb_log_tool, ADB_LOG_SCHEMA)
tool_registry.register_builtin_tool("schedule_create", schedule_create_tool, SCHEDULE_CREATE_SCHEMA)
tool_registry.register_builtin_tool("schedule_list", schedule_list_tool, SCHEDULE_LIST_SCHEMA)
tool_registry.register_builtin_tool("schedule_delete", schedule_delete_tool, SCHEDULE_DELETE_SCHEMA)
tool_registry.register_builtin_tool("crypto_util", crypto_util_tool, CRYPTO_UTIL_SCHEMA)
tool_registry.register_builtin_tool("random_generate", random_generate_tool, RANDOM_GENERATE_SCHEMA)
tool_registry.register_builtin_tool("send_email", send_email_tool, SEND_EMAIL_SCHEMA)
tool_registry.register_builtin_tool("url_parse", url_parse_tool, URL_PARSE_SCHEMA)
tool_registry.register_builtin_tool("regex_test", regex_test_tool, REGEX_TEST_SCHEMA)
tool_registry.register_builtin_tool("agent_call", agent_call_tool, AGENT_CALL_SCHEMA)
_registered = True
n = tool_registry.builtin_tool_count()
names = tool_registry.builtin_tool_names()
pid = os.getpid()
if n < _EXPECTED_BUILTIN:
logger.warning(
"内置工具注册数量异常: pid=%s count=%s 期望>=%s names=%sLLM 工具调用可能失效)",
pid,
n,
_EXPECTED_BUILTIN,
names,
)
else:
logger.info(
"内置工具就绪 pid=%s count=%s names=%sCelery Worker 若缺此项日志,说明未加载 workflow_tasks / 未执行 bootstrap",
pid,
n,
names,
)