feat: 添加搜索工具功能(Tavily Search)

- 新增 SearchToolConfig 模型:支持搜索工具配置
- Agent 增加 tools 字段:可配置可用工具列表
- 后台管理增加搜索工具配置页面
- Agent 管理增加工具启用开关
- 网页端增加搜索工具禁用复选框
- WebSocket chat 处理增加搜索调用逻辑
- 默认配置 Tavily Search API
This commit is contained in:
2026-04-13 13:26:43 +08:00
parent 85dd206154
commit 0c9bfca346
5 changed files with 466 additions and 6 deletions

View File

@@ -32,6 +32,9 @@
.agent-selector select { padding: 8px 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px; cursor: pointer; min-width: 150px; }
.ws-status { font-size: 12px; color: #666; background: #f0f0f0; padding: 4px 8px; border-radius: 4px; }
.ws-status.connected { color: #10a37f; }
.tool-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.tool-toggle input { width: 14px; height: 14px; }
.tool-toggle label { cursor: pointer; }
.messages-container { flex: 1; overflow-y: auto; padding: 24px; }
.message { max-width: 800px; margin: 0 auto 24px; display: flex; gap: 16px; }
@@ -141,6 +144,10 @@
<div class="agent-selector">
<select id="agentSelect" onchange="switchAgent()"><option value="">加载中...</option></select>
</div>
<div class="tool-toggle">
<input type="checkbox" id="enableSearch" checked>
<label for="enableSearch"><i class="ri-search-line"></i> 搜索</label>
</div>
<div class="ws-status" id="wsStatus">连接中...</div>
</div>
</div>
@@ -676,8 +683,20 @@
document.getElementById('sendBtn').disabled = true;
input.value = '';
input.style.height = 'auto';
// 获取工具禁用状态
const enableSearch = document.getElementById('enableSearch').checked;
const disabledTools = [];
if (!enableSearch) disabledTools.push('search');
if (ws?.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ action: 'chat', message: msg, conversation_id: currentConversationId, agent_id: currentAgentId }));
ws.send(JSON.stringify({
action: 'chat',
message: msg,
conversation_id: currentConversationId,
agent_id: currentAgentId,
disabled_tools: disabledTools // 禁用的工具列表
}));
}
}