Files
aiagent/backend/app/core/tools_bootstrap.py
renjianbo beff3fac8d fix: delete agent 500 error + dynamic personality + deployment guide
- Fix delete agent 500: clean up FK records (agent_llm_logs, permissions,
  schedules, executions, team_members) and unbind goals/tasks before delete
- Remove hardcoded personality templates in Android, replace with dynamic
  system prompt generation from name + description
- Set promptSectionsEnabled=false to bypass PromptComposer for personality
- Add Tencent Cloud Linux deployment guide (Docker Compose)
- Accumulated backend service updates, frontend UI fixes, Android app changes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-29 01:17:21 +08:00

214 lines
10 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 = 57
def ensure_builtin_tools_registered() -> None:
"""幂等:注册所有内置工具,供工作流 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,
code_execute_tool,
git_operation_tool,
web_search_tool,
pdf_generate_tool,
project_scaffold_tool,
task_plan_tool,
excel_process_tool,
browser_use_tool,
docker_manage_tool,
deploy_push_tool,
agent_create_tool,
tool_register_tool,
capability_check_tool,
code_tool_create_tool,
extension_log_tool,
self_review_tool,
knowledge_graph_search_tool,
knowledge_graph_add_tool,
entity_search_tool,
learning_path_tool,
image_ocr_tool,
image_vision_tool,
speech_to_text_tool,
text_to_speech_tool,
main_agent_create_task,
main_agent_assign_task,
main_agent_check_progress,
main_agent_notify_user,
feishu_create_doc_tool,
feishu_create_calendar_event_tool,
feishu_search_contacts_tool,
feishu_send_approval_tool,
feishu_read_messages_tool,
feishu_create_sheet_tool,
feishu_upload_file_tool,
create_gitea_issue,
parse_test_result_file,
project_scan_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,
CODE_EXECUTE_SCHEMA,
GIT_OPERATION_SCHEMA,
WEB_SEARCH_SCHEMA,
PDF_GENERATE_SCHEMA,
PROJECT_SCAFFOLD_SCHEMA,
TASK_PLAN_SCHEMA,
EXCEL_PROCESS_SCHEMA,
BROWSER_USE_SCHEMA,
DOCKER_MANAGE_SCHEMA,
DEPLOY_PUSH_SCHEMA,
AGENT_CREATE_SCHEMA,
TOOL_REGISTER_SCHEMA,
CAPABILITY_CHECK_SCHEMA,
CODE_TOOL_CREATE_SCHEMA,
EXTENSION_LOG_SCHEMA,
SELF_REVIEW_SCHEMA,
KNOWLEDGE_GRAPH_SEARCH_SCHEMA,
KNOWLEDGE_GRAPH_ADD_SCHEMA,
ENTITY_SEARCH_SCHEMA,
LEARNING_PATH_SCHEMA,
IMAGE_OCR_SCHEMA,
IMAGE_VISION_SCHEMA,
SPEECH_TO_TEXT_SCHEMA,
TEXT_TO_SPEECH_SCHEMA,
MAIN_AGENT_CREATE_TASK_SCHEMA,
MAIN_AGENT_ASSIGN_TASK_SCHEMA,
MAIN_AGENT_CHECK_PROGRESS_SCHEMA,
MAIN_AGENT_NOTIFY_USER_SCHEMA,
FEISHU_CREATE_DOC_SCHEMA,
FEISHU_CREATE_CALENDAR_EVENT_SCHEMA,
FEISHU_SEARCH_CONTACTS_SCHEMA,
FEISHU_SEND_APPROVAL_SCHEMA,
FEISHU_READ_MESSAGES_SCHEMA,
FEISHU_CREATE_SHEET_SCHEMA,
FEISHU_UPLOAD_FILE_SCHEMA,
CREATE_GITEA_ISSUE_SCHEMA,
PARSE_TEST_RESULT_FILE_SCHEMA,
PROJECT_SCAN_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)
tool_registry.register_builtin_tool("code_execute", code_execute_tool, CODE_EXECUTE_SCHEMA)
tool_registry.register_builtin_tool("git_operation", git_operation_tool, GIT_OPERATION_SCHEMA)
tool_registry.register_builtin_tool("web_search", web_search_tool, WEB_SEARCH_SCHEMA)
tool_registry.register_builtin_tool("pdf_generate", pdf_generate_tool, PDF_GENERATE_SCHEMA)
tool_registry.register_builtin_tool("project_scaffold", project_scaffold_tool, PROJECT_SCAFFOLD_SCHEMA)
tool_registry.register_builtin_tool("task_plan", task_plan_tool, TASK_PLAN_SCHEMA)
tool_registry.register_builtin_tool("excel_process", excel_process_tool, EXCEL_PROCESS_SCHEMA)
tool_registry.register_builtin_tool("browser_use", browser_use_tool, BROWSER_USE_SCHEMA)
tool_registry.register_builtin_tool("docker_manage", docker_manage_tool, DOCKER_MANAGE_SCHEMA)
tool_registry.register_builtin_tool("deploy_push", deploy_push_tool, DEPLOY_PUSH_SCHEMA)
tool_registry.register_builtin_tool("agent_create", agent_create_tool, AGENT_CREATE_SCHEMA)
tool_registry.register_builtin_tool("tool_register", tool_register_tool, TOOL_REGISTER_SCHEMA)
tool_registry.register_builtin_tool("capability_check", capability_check_tool, CAPABILITY_CHECK_SCHEMA)
tool_registry.register_builtin_tool("code_tool_create", code_tool_create_tool, CODE_TOOL_CREATE_SCHEMA)
tool_registry.register_builtin_tool("extension_log", extension_log_tool, EXTENSION_LOG_SCHEMA)
tool_registry.register_builtin_tool("self_review", self_review_tool, SELF_REVIEW_SCHEMA)
tool_registry.register_builtin_tool("knowledge_graph_search", knowledge_graph_search_tool, KNOWLEDGE_GRAPH_SEARCH_SCHEMA)
tool_registry.register_builtin_tool("knowledge_graph_add", knowledge_graph_add_tool, KNOWLEDGE_GRAPH_ADD_SCHEMA)
tool_registry.register_builtin_tool("entity_search", entity_search_tool, ENTITY_SEARCH_SCHEMA)
tool_registry.register_builtin_tool("learning_path", learning_path_tool, LEARNING_PATH_SCHEMA)
tool_registry.register_builtin_tool("image_ocr", image_ocr_tool, IMAGE_OCR_SCHEMA)
tool_registry.register_builtin_tool("image_vision", image_vision_tool, IMAGE_VISION_SCHEMA)
tool_registry.register_builtin_tool("speech_to_text", speech_to_text_tool, SPEECH_TO_TEXT_SCHEMA)
tool_registry.register_builtin_tool("text_to_speech", text_to_speech_tool, TEXT_TO_SPEECH_SCHEMA)
tool_registry.register_builtin_tool("create_task", main_agent_create_task, MAIN_AGENT_CREATE_TASK_SCHEMA)
tool_registry.register_builtin_tool("assign_task", main_agent_assign_task, MAIN_AGENT_ASSIGN_TASK_SCHEMA)
tool_registry.register_builtin_tool("check_progress", main_agent_check_progress, MAIN_AGENT_CHECK_PROGRESS_SCHEMA)
tool_registry.register_builtin_tool("notify_user", main_agent_notify_user, MAIN_AGENT_NOTIFY_USER_SCHEMA)
tool_registry.register_builtin_tool("feishu_create_doc", feishu_create_doc_tool, FEISHU_CREATE_DOC_SCHEMA)
tool_registry.register_builtin_tool("feishu_create_calendar_event", feishu_create_calendar_event_tool, FEISHU_CREATE_CALENDAR_EVENT_SCHEMA)
tool_registry.register_builtin_tool("feishu_search_contacts", feishu_search_contacts_tool, FEISHU_SEARCH_CONTACTS_SCHEMA)
tool_registry.register_builtin_tool("feishu_send_approval", feishu_send_approval_tool, FEISHU_SEND_APPROVAL_SCHEMA)
tool_registry.register_builtin_tool("feishu_read_messages", feishu_read_messages_tool, FEISHU_READ_MESSAGES_SCHEMA)
tool_registry.register_builtin_tool("feishu_create_sheet", feishu_create_sheet_tool, FEISHU_CREATE_SHEET_SCHEMA)
tool_registry.register_builtin_tool("feishu_upload_file", feishu_upload_file_tool, FEISHU_UPLOAD_FILE_SCHEMA)
tool_registry.register_builtin_tool("create_gitea_issue", create_gitea_issue, CREATE_GITEA_ISSUE_SCHEMA)
tool_registry.register_builtin_tool("parse_test_result_file", parse_test_result_file, PARSE_TEST_RESULT_FILE_SCHEMA)
tool_registry.register_builtin_tool("project_scan", project_scan_tool, PROJECT_SCAN_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,
)