Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

feat: 优化内置智能体配置同步机制

wizardchen89e75bb6fe01
diff --git a/frontend/src/components/AgentSelector.vue b/frontend/src/components/AgentSelector.vue
index 17629a949..f063c311b 100644
--- a/frontend/src/components/AgentSelector.vue
+++ b/frontend/src/components/AgentSelector.vue
@@ -172,7 +172,7 @@ const dropdownStyle = ref<Record<string, string>>({});
// 内置智能体
const builtinAgents = computed(() => {
- return [
+ const defaults = [
{
id: BUILTIN_QUICK_ANSWER_ID,
name: t('input.normalMode'),
@@ -187,7 +187,23 @@ const builtinAgents = computed(() => {
is_builtin: true,
config: { agent_mode: 'smart-reasoning' as const }
}
- ] as CustomAgent[];
+ ];
+
+ return defaults.map(def => {
+ const apiAgent = agents.value.find(a => a.id === def.id);
+ if (apiAgent) {
+ return {
+ ...apiAgent,
+ name: def.name,
+ description: def.description,
+ config: {
+ ...(apiAgent.config || {}),
+ agent_mode: def.config.agent_mode
+ }
+ };
+ }
+ return def;
+ }) as CustomAgent[];
});
// 自定义智能体
diff --git a/frontend/src/components/Input-field.vue b/frontend/src/components/Input-field.vue
index 8ae035ffb..0827f06f4 100644
--- a/frontend/src/components/Input-field.vue
+++ b/frontend/src/components/Input-field.vue
@@ -1177,8 +1177,8 @@ const handleSelectAgent = (agent: CustomAgent) => {
// 内置智能体检查 - 从实际的智能体配置来判断
if (agent.is_builtin) {
- // 从 agents 列表中获取实际的内置智能体数据
- const builtinAgent = agents.value.find(a => a.id === agent.id);
+ // 从 agents 列表中获取实际的内置智能体数据,如果没找到则使用传入的 agent (此时应该包含合并后的配置)
+ const builtinAgent = agents.value.find(a => a.id === agent.id) || agent;
if (builtinAgent) {
const notReadyReasons = getBuiltinAgentNotReadyReasons(builtinAgent, isAgentType);
if (notReadyReasons.length > 0) {
@@ -1200,18 +1200,26 @@ const handleSelectAgent = (agent: CustomAgent) => {
selectedAgentId.value = agent.id;
settingsStore.toggleAgent(!!isAgentType);
- // 如果是自定义智能体,同步网络搜索状态和模型
- if (!agent.is_builtin) {
- const agentWebSearch = agent.config?.web_search_enabled;
- if (agentWebSearch !== undefined) {
- // 智能体配置了网络搜索设置,同步到 store
- settingsStore.toggleWebSearch(agentWebSearch);
- }
-
- // 如果智能体配置了模型,同步到 store
- const agentModel = agent.config?.model_id;
- if (agentModel) {
- selectedModelId.value = agentModel;
+ // 同步智能体的配置状态(包括内置和自定义智能体)
+ // 1. 同步网络搜索状态
+ const agentWebSearch = agent.config?.web_search_enabled;
+ if (agentWebSearch !== undefined) {
+ // 智能体配置了网络搜索设置,同步到 store
+ settingsStore.toggleWebSearch(agentWebSearch);
+ } else if (agent.is_builtin) {
+ // 如果是内置智能体且未配置网络搜索,不强制修改,保留当前用户设置
+ // 或者可以考虑恢复默认值,视需求而定
+ }
+
+ // 2. 同步模型
+ const agentModel = agent.config?.model_id;
+ if (agentModel) {
+ selectedModelId.value = agentModel;
+ } else if (agent.is_builtin) {
+ // 如果是内置智能体且未配置特定模型,恢复为系统默认模型
+ // 这样可以确保从专用模型切换回普通模式时,模型也切回通用模型
+ if (conversationConfig.value?.summary_model_id) {
+ selectedModelId.value = conversationConfig.value.summary_model_id;
}
}
diff --git a/frontend/src/views/agent/AgentEditorModal.vue b/frontend/src/views/agent/AgentEditorModal.vue
index 98e3ff88e..4cc777d5b 100644
--- a/frontend/src/views/agent/AgentEditorModal.vue
+++ b/frontend/src/views/agent/AgentEditorModal.vue
@@ -959,7 +959,8 @@ const kbOptions = ref<{ label: string; value: string; type?: 'document' | 'faq';
const mcpOptions = ref<{ label: string; value: string }[]>([]);
// 系统默认配置(用于内置智能体显示默认提示词)
-const defaultSystemPrompt = ref(''); // 统一的默认系统提示词
+const defaultAgentSystemPrompt = ref(''); // Agent 模式的默认系统提示词(来自 agent-config)
+const defaultNormalSystemPrompt = ref(''); // 普通模式的默认系统提示词(来自 conversation-config)
const defaultContextTemplate = ref('');
const defaultRewritePromptSystem = ref('');
const defaultRewritePromptUser = ref('');
@@ -1295,14 +1296,14 @@ const fillBuiltinAgentDefaults = () => {
const isAgent = config.agent_mode === 'smart-reasoning';
if (isAgent) {
- // Agent 模式:填入统一的默认提示词
- if (!config.system_prompt && defaultSystemPrompt.value) {
- config.system_prompt = defaultSystemPrompt.value;
+ // Agent 模式:使用 agent-config 的默认提示词
+ if (!config.system_prompt && defaultAgentSystemPrompt.value) {
+ config.system_prompt = defaultAgentSystemPrompt.value;
}
} else {
- // 普通模式:填入默认系统提示词和上下文模板
- if (!config.system_prompt && defaultSystemPrompt.value) {
- config.system_prompt = defaultSystemPrompt.value;
+ // 普通模式:使用 conversation-config 的默认系统提示词和上下文模板
+ if (!config.system_prompt && defaultNormalSystemPrompt.value) {
+ config.system_prompt = defaultNormalSystemPrompt.value;
}
if (!config.context_template && defaultContextTemplate.value) {
config.context_template = defaultContextTemplate.value;
@@ -1458,17 +1459,16 @@ const loadDependencies = async () => {
console.warn('Failed to load placeholders', e);
}
- // 加载 Agent 模式默认提示词(统一提示词)
+ // 加载 Agent 模式默认提示词(来自 agent-config,用于 smart-reasoning 模式)
const agentConfig = await getAgentConfig();
if (agentConfig.data?.system_prompt) {
- defaultSystemPrompt.value = agentConfig.data.system_prompt;
+ defaultAgentSystemPrompt.value = agentConfig.data.system_prompt;
}
- // 加载系统默认配置(用于普通模式)
+ // 加载系统默认配置(来自 conversation-config,用于普通模式 quick-answer)
const conversationConfig = await getConversationConfig();
- if (conversationConfig.data?.prompt && !defaultSystemPrompt.value) {
- // 如果 Agent 配置没有提供默认提示词,则使用普通模式的
- defaultSystemPrompt.value = conversationConfig.data.prompt;
+ if (conversationConfig.data?.prompt) {
+ defaultNormalSystemPrompt.value = conversationConfig.data.prompt;
}
if (conversationConfig.data?.context_template) {
defaultContextTemplate.value = conversationConfig.data.context_template;
diff --git a/internal/types/custom_agent.go b/internal/types/custom_agent.go
index 49f9c91c7..78af9819c 100644
--- a/internal/types/custom_agent.go
+++ b/internal/types/custom_agent.go
@@ -229,8 +229,14 @@ func GetBuiltinQuickAnswerAgent(tenantID uint64) *CustomAgent {
IsBuiltin: true,
TenantID: tenantID,
Config: CustomAgentConfig{
- AgentMode: AgentModeQuickAnswer,
- SystemPrompt: "",
+ AgentMode: AgentModeQuickAnswer,
+ SystemPrompt: "",
+ ContextTemplate: `请根据以下参考资料回答用户问题。
+
+参考资料:
+{{contexts}}
+
+用户问题:{{query}}`,
Temperature: 0.7,
MaxCompletionTokens: 2048,
WebSearchEnabled: true,