开发者指南 · 16
扩展开发
16.1 添加新工具
- 在
app/services/tools.py中用@tool装饰器定义工厂函数 - 在
agent.py::create_user_agent注入到 Admin Agent 工具集 - 如需 Consumer 支持,在
consumer_agent.py中按 capability 条件注入 - 如需 channel 区分(如
send_message),在consumer_agent.create_consumer_agent中按channel参数注入 - 在
tools.py::CAPABILITY_PROMPTS中添加对应的能力提示词 - 如需 Subagent 可调用,加入
subagents.py::SHARED_TOOL_NAMES或MEMORY_TOOL_NAMES
16.2 添加新路由
- 在
app/routes/下创建新模块,使用APIRouter - 在
app/main.py中注册app.include_router(...) - Admin 路由:
Depends(get_current_user);Consumer 路由:Depends(get_service_context)
16.3 添加新页面(前端)
- 在
frontend/src/pages/下创建页面组件 - 在
frontend/src/router/index.tsx中添加<Route> - 如需侧栏导航项,在
SettingsLayout的settingsNav数组中添加 - 用
ErrorBoundary包裹(参考<ErrorBoundary scope="settings">)
16.4 添加新 API 调用
- 在
frontend/src/services/api.ts中添加 typed 函数 - 在
frontend/src/types/index.ts中添加类型定义
16.5 添加新 Subagent
- 修改
app/services/subagents.py::DEFAULT_SUBAGENTS(默认) 或通过/api/subagentsAPI CRUD - 工具列表在
SHARED_TOOL_NAMES + MEMORY_TOOL_NAMES中选择 - 前端
SubagentManager.tsx自动适配(从GET /api/subagents取available_tools)
16.6 添加新主题
- 在
frontend/src/styles/themes.css中复制一个[data-theme]块并调整变量 - 在
themeContext.tsx中添加THEMES项 + AntdThemeConfig - 在
AppLayout.tsx侧栏底部主题切换按钮中加入新主题
16.7 添加新 Tauri Command
- 在
tauri-launcher/src-tauri/src/lib.rs中用#[tauri::command]定义函数 - 在
invoke_handler!macro 中注册 - 在
dist/index.html中通过window.__TAURI__.invoke('cmd_name', { args })调用 - 重新
npx tauri build