Skip to content

Commit 643f49e

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

File tree

4 files changed

+11
-41
lines changed

4 files changed

+11
-41
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: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ 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)
@@ -66,6 +63,12 @@ export const useAgentStore = defineStore('agent', () => {
6663
return items
6764
})
6865

66+
67+
// 工具相关状态
68+
const availableTools = computed(() => {
69+
return configurableItems.value.tools?.options || []
70+
})
71+
6972
const hasConfigChanges = computed(() =>
7073
JSON.stringify(agentConfig.value) !== JSON.stringify(originalAgentConfig.value)
7174
)
@@ -108,7 +111,6 @@ export const useAgentStore = defineStore('agent', () => {
108111
if (userStore.isAdmin) {
109112
await loadAgentConfig()
110113
}
111-
await fetchTools()
112114
}
113115

114116
isInitialized.value = true
@@ -159,6 +161,7 @@ export const useAgentStore = defineStore('agent', () => {
159161
try {
160162
const response = await agentApi.getAgentDetail(agentId)
161163
agentDetails.value[agentId] = response
164+
// availableTools.value[agentId] = response.available_tools || []
162165
return response
163166
} catch (err) {
164167
console.error(`Failed to fetch agent detail for ${agentId}:`, err)
@@ -291,17 +294,8 @@ export const useAgentStore = defineStore('agent', () => {
291294
isLoadingTools.value = true
292295
error.value = null
293296

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-
}
297+
console.error('[DEPRECATED] THIS METHOD IS DEPRECATED. USE fetchAgentDetail INSTEAD.')
298+
console.error('[DEPRECATED] fetchTools: selectedAgentId.value =', selectedAgentId.value)
305299
}
306300

307301
/**

0 commit comments

Comments
 (0)