Skip to content

Commit 1d04842

Browse files
committed
refactor(agent-tools): 移除已弃用的工具获取接口及相关代码
1 parent 3b03a91 commit 1d04842

File tree

4 files changed

+10
-56
lines changed

4 files changed

+10
-56
lines changed

server/routers/chat_router.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ async def update_chat_models(model_provider: str, model_names: list[str], curren
718718
@chat.get("/tools")
719719
async def get_tools(agent_id: str, current_user: User = Depends(get_required_user)):
720720
"""获取所有可用工具(需要登录)"""
721+
logger.error("[DEPRECATED] 该接口已被弃用,将在未来版本中移除")
721722
# 获取Agent实例和配置类
722723
if not (agent := agent_manager.get_agent(agent_id)):
723724
raise HTTPException(status_code=404, detail=f"智能体 {agent_id} 不存在")

web/src/apis/agent_api.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,6 @@ export const agentApi = {
141141
return apiAdminPost('/api/chat/set_default_agent', { agent_id: agentId })
142142
},
143143

144-
/**
145-
* 获取所有可用工具的信息
146-
* @returns {Promise} - 工具信息列表
147-
*/
148-
getTools: (agentId) => apiGet(`/api/chat/tools?agent_id=${agentId}`),
149-
150144
/**
151145
* 恢复被人工审批中断的对话(流式响应)
152146
* @param {string} agentId - 智能体ID

web/src/components/AgentConfigSidebar.vue

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -421,21 +421,9 @@ const getToolNameById = (toolId) => {
421421
return tool ? tool.name : toolId;
422422
};
423423
424-
const loadAvailableTools = async () => {
425-
try {
426-
// 避免重复加载,如果已经有工具就直接返回
427-
if (availableTools.value && Object.keys(availableTools.value).length > 0) {
428-
return;
429-
}
430-
await agentStore.fetchTools();
431-
} catch (error) {
432-
console.error('加载工具列表失败:', error);
433-
}
434-
};
435-
436424
const openToolsModal = async () => {
425+
console.log("availableTools.value", availableTools.value)
437426
try {
438-
await loadAvailableTools();
439427
selectedTools.value = [...(agentConfig.value?.tools || [])];
440428
toolsModalOpen.value = true;
441429
} catch (error) {
@@ -563,13 +551,6 @@ const resetConfig = async () => {
563551
message.error('重置配置失败');
564552
}
565553
};
566-
567-
// 监听器
568-
watch(() => props.isOpen, (newVal) => {
569-
if (newVal && (!availableTools.value || Object.keys(availableTools.value).length === 0)) {
570-
loadAvailableTools();
571-
}
572-
});
573554
</script>
574555
575556
<style lang="less" scoped>

web/src/stores/agent.js

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@ export const useAgentStore = defineStore('agent', () => {
1919
// 智能体详情相关状态
2020
const agentDetails = ref({}) // 存储每个智能体的详细信息(含 configurable_items)
2121

22-
// 工具相关状态
23-
const availableTools = ref([])
24-
2522
// 加载状态
2623
const isLoadingAgents = ref(false)
2724
const isLoadingConfig = ref(false)
28-
const isLoadingTools = ref(false)
2925
const isLoadingAgentDetail = ref(false)
3026

3127
// 错误状态
@@ -66,6 +62,12 @@ export const useAgentStore = defineStore('agent', () => {
6662
return items
6763
})
6864

65+
66+
// 工具相关状态
67+
const availableTools = computed(() => {
68+
return configurableItems.value.tools?.options || []
69+
})
70+
6971
const hasConfigChanges = computed(() =>
7072
JSON.stringify(agentConfig.value) !== JSON.stringify(originalAgentConfig.value)
7173
)
@@ -108,7 +110,6 @@ export const useAgentStore = defineStore('agent', () => {
108110
if (userStore.isAdmin) {
109111
await loadAgentConfig()
110112
}
111-
await fetchTools()
112113
}
113114

114115
isInitialized.value = true
@@ -284,26 +285,7 @@ export const useAgentStore = defineStore('agent', () => {
284285
Object.assign(agentConfig.value, updates)
285286
}
286287

287-
/**
288-
* 获取工具列表
289-
*/
290-
async function fetchTools() {
291-
isLoadingTools.value = true
292-
error.value = null
293-
294-
try {
295-
const response = await agentApi.getTools(selectedAgentId.value)
296-
availableTools.value = response.tools
297-
} catch (err) {
298-
console.error('Failed to fetch tools:', err)
299-
handleChatError(err, 'fetch')
300-
error.value = err.message
301-
throw err
302-
} finally {
303-
isLoadingTools.value = false
304-
}
305-
}
306-
288+
307289
/**
308290
* 清除错误状态
309291
*/
@@ -321,10 +303,8 @@ export const useAgentStore = defineStore('agent', () => {
321303
agentConfig.value = {}
322304
originalAgentConfig.value = {}
323305
agentDetails.value = {}
324-
availableTools.value = []
325306
isLoadingAgents.value = false
326307
isLoadingConfig.value = false
327-
isLoadingTools.value = false
328308
isLoadingAgentDetail.value = false
329309
error.value = null
330310
isInitialized.value = false
@@ -339,10 +319,8 @@ export const useAgentStore = defineStore('agent', () => {
339319
agentConfig,
340320
originalAgentConfig,
341321
agentDetails,
342-
availableTools,
343322
isLoadingAgents,
344323
isLoadingConfig,
345-
isLoadingTools,
346324
isLoadingAgentDetail,
347325
error,
348326
isInitialized,
@@ -353,6 +331,7 @@ export const useAgentStore = defineStore('agent', () => {
353331
agentsList,
354332
isDefaultAgent,
355333
configurableItems,
334+
availableTools,
356335
hasConfigChanges,
357336

358337
// 方法
@@ -367,7 +346,6 @@ export const useAgentStore = defineStore('agent', () => {
367346
resetAgentConfig,
368347
updateConfigItem,
369348
updateAgentConfig,
370-
fetchTools,
371349
clearError,
372350
reset
373351
}

0 commit comments

Comments
 (0)