开发者指南 · 16

扩展开发

16.1 添加新工具

  1. app/services/tools.py 中用 @tool 装饰器定义工厂函数
  2. agent.py::create_user_agent 注入到 Admin Agent 工具集
  3. 如需 Consumer 支持,在 consumer_agent.py 中按 capability 条件注入
  4. 如需 channel 区分(如 send_message),在 consumer_agent.create_consumer_agent 中按 channel 参数注入
  5. tools.py::CAPABILITY_PROMPTS 中添加对应的能力提示词
  6. 如需 Subagent 可调用,加入 subagents.py::SHARED_TOOL_NAMESMEMORY_TOOL_NAMES

16.2 添加新路由

  1. app/routes/ 下创建新模块,使用 APIRouter
  2. app/main.py 中注册 app.include_router(...)
  3. Admin 路由:Depends(get_current_user);Consumer 路由:Depends(get_service_context)

16.3 添加新页面(前端)

  1. frontend/src/pages/ 下创建页面组件
  2. frontend/src/router/index.tsx 中添加 <Route>
  3. 如需侧栏导航项,在 SettingsLayoutsettingsNav 数组中添加
  4. ErrorBoundary 包裹(参考 <ErrorBoundary scope="settings">

16.4 添加新 API 调用

  1. frontend/src/services/api.ts 中添加 typed 函数
  2. frontend/src/types/index.ts 中添加类型定义

16.5 添加新 Subagent

  1. 修改 app/services/subagents.py::DEFAULT_SUBAGENTS(默认) 或通过 /api/subagents API CRUD
  2. 工具列表在 SHARED_TOOL_NAMES + MEMORY_TOOL_NAMES 中选择
  3. 前端 SubagentManager.tsx 自动适配(从 GET /api/subagentsavailable_tools

16.6 添加新主题

  1. frontend/src/styles/themes.css 中复制一个 [data-theme] 块并调整变量
  2. themeContext.tsx 中添加 THEMES 项 + Antd ThemeConfig
  3. AppLayout.tsx 侧栏底部主题切换按钮中加入新主题

16.7 添加新 Tauri Command

  1. tauri-launcher/src-tauri/src/lib.rs 中用 #[tauri::command] 定义函数
  2. invoke_handler! macro 中注册
  3. dist/index.html 中通过 window.__TAURI__.invoke('cmd_name', { args }) 调用
  4. 重新 npx tauri build