Skip to content

Commit a9d2f41

Browse files
committed
fix(agent): 修复智能体重复初始化和工具重复加载问题
- 修复智能体初始化时的并发问题,添加isInitializing状态防止重复初始化 - 优化工具加载逻辑,避免重复请求 - 移除AgentView中多余的watch监听
1 parent 7df10af commit a9d2f41

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

web/src/components/AgentChatComponent.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ const initAll = async () => {
991991
onMounted(async () => {
992992
await initAll();
993993
scrollController.enableAutoScroll();
994-
});
994+
});
995995
996996
watch(currentAgentId, async (newAgentId, oldAgentId) => {
997997
if (newAgentId !== oldAgentId) {

web/src/components/AgentConfigSidebar.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ const getToolNameById = (toolId) => {
423423
424424
const loadAvailableTools = async () => {
425425
try {
426+
// 避免重复加载,如果已经有工具就直接返回
427+
if (availableTools.value && Object.keys(availableTools.value).length > 0) {
428+
return;
429+
}
426430
await agentStore.fetchTools();
427431
} catch (error) {
428432
console.error('加载工具列表失败:', error);

web/src/stores/agent.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const useAgentStore = defineStore('agent', () => {
3333

3434
// 初始化状态
3535
const isInitialized = ref(false)
36+
const isInitializing = ref(false)
3637

3738
// ==================== 计算属性 ====================
3839
const selectedAgent = computed(() =>
@@ -76,6 +77,10 @@ export const useAgentStore = defineStore('agent', () => {
7677
async function initialize() {
7778
if (isInitialized.value) return
7879

80+
// 防止并发初始化
81+
if (isInitializing.value) return
82+
isInitializing.value = true
83+
7984
try {
8085
await fetchAgents()
8186
await fetchDefaultAgent()
@@ -111,6 +116,8 @@ export const useAgentStore = defineStore('agent', () => {
111116
console.error('Failed to initialize agent store:', err)
112117
handleChatError(err, 'initialize')
113118
error.value = err.message
119+
} finally {
120+
isInitializing.value = false
114121
}
115122
}
116123

@@ -321,6 +328,7 @@ export const useAgentStore = defineStore('agent', () => {
321328
isLoadingAgentDetail.value = false
322329
error.value = null
323330
isInitialized.value = false
331+
isInitializing.value = false
324332
}
325333

326334
return {

web/src/views/AgentView.vue

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,6 @@ const loadAgentConfig = async () => {
165165
}
166166
};
167167
168-
// 监听智能体选择变化
169-
watch(
170-
() => selectedAgentId.value,
171-
() => {
172-
loadAgentConfig();
173-
}
174-
);
175168
176169
// 选择智能体(使用store方法)
177170
const selectAgent = (agentId) => {

0 commit comments

Comments
 (0)