Files
aiagent/backend/scripts/init_builtin_tools.py
renjianbo df4fab1e6e feat: Agent 批量测试、作业助手与上传预览;Windows 启动脚本与文档- 新增 run_agent_test_cases 与示例 JSON、(红头)agent测试用例文档
- 扩展 test_agent_execution(--homework、UTF-8 控制台)
- 后端:uploads 预览、file_read、工作流与对话落盘等
- 前端:AgentChatPreview 与设计器相关调整
- 忽略 redis二进制、agent_workspaces、uploads、tessdata 等本机产物

Made-with: Cursor
2026-04-13 20:17:18 +08:00

80 lines
2.4 KiB
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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.
#!/usr/bin/env python3
"""
初始化内置工具脚本
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from app.core.database import SessionLocal
from app.models.tool import Tool
from app.services.tool_registry import tool_registry
from app.services.builtin_tools import (
http_request_tool,
file_read_tool,
HTTP_REQUEST_SCHEMA,
FILE_READ_SCHEMA
)
def init_builtin_tools():
"""初始化内置工具"""
db = SessionLocal()
try:
# 注册内置工具到注册表
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
)
print("✅ 内置工具已注册到工具注册表")
# 保存到数据库
tools_to_create = [
("http_request", HTTP_REQUEST_SCHEMA, "发送HTTP请求支持GET、POST、PUT、DELETE方法"),
("file_read", FILE_READ_SCHEMA, "读取工作区内文件文本、PDF、docx、xlsx、图片 OCR 等")
]
created_count = 0
for tool_name, tool_schema, description in tools_to_create:
existing = db.query(Tool).filter(Tool.name == tool_name).first()
if not existing:
tool = Tool(
name=tool_name,
description=description,
category="builtin",
function_schema=tool_schema,
implementation_type="builtin",
is_public=True
)
db.add(tool)
created_count += 1
print(f"✅ 创建工具: {tool_name}")
else:
# 更新工具定义
existing.function_schema = tool_schema
existing.description = description
print(f" 更新工具: {tool_name}")
db.commit()
print(f"\n✅ 内置工具初始化完成!创建了 {created_count} 个工具")
except Exception as e:
db.rollback()
print(f"❌ 初始化失败: {str(e)}")
import traceback
traceback.print_exc()
finally:
db.close()
if __name__ == "__main__":
init_builtin_tools()