feat: Introduce agent type presets for smart-reasoning mode

- Added a new configuration file `agent_type_presets.yaml` to define various agent type presets, including RAG Q&A, Wiki Q&A, Hybrid (Wiki + RAG), and Data Analysis.
- Updated the `builtin_agents.yaml` to associate built-in agents with the new agent type presets, enhancing their configuration options.
- Enhanced the agent system prompt templates to reflect the new agent types and their functionalities.
- Implemented API endpoints to retrieve agent type presets, allowing for dynamic loading in the frontend.
- Updated the frontend to support agent type selection in the agent editor modal, improving user experience by auto-filling relevant configurations based on selected presets.

These changes significantly enhance the flexibility and usability of the agent system, allowing users to easily configure agents based on predefined types.
This commit is contained in:
wizardchen
2026-04-21 17:12:41 +08:00
parent 0531700518
commit 4022f134bd
18 changed files with 1177 additions and 233 deletions
+59
View File
@@ -1,10 +1,21 @@
import { get, post, put, del } from "../../utils/request";
// 智能体配置
// 智能推理下的智能体类型预设 ID
// 'rag-qa' : 经典文档/FAQ 分块 RAG
// 'wiki-qa' : Wiki 图谱导航问答
// 'hybrid-rag-wiki': Wiki + 分块混合检索
// 'custom' : 完全自定义(不应用预设)
export type AgentType = 'rag-qa' | 'wiki-qa' | 'hybrid-rag-wiki' | 'data-analysis' | 'custom';
export interface CustomAgentConfig {
// ===== 基础设置 =====
agent_mode?: 'quick-answer' | 'smart-reasoning'; // 运行模式:quick-answer=RAG模式, smart-reasoning=ReAct Agent模式
// 智能推理模式下的类型预设,用于一键应用"系统提示词 + 工具 + KB 兼容性"组合
// 仅在 agent_mode === 'smart-reasoning' 时生效;quick-answer 模式忽略
agent_type?: AgentType;
system_prompt?: string; // 统一系统提示词(使用 {{web_search_status}} 占位符动态控制行为)
system_prompt_id?: string; // 引用的 prompt template ID(预设会填入此字段)
context_template?: string; // 上下文模板(普通模式)
// ===== 模型设置 =====
@@ -179,6 +190,54 @@ export function getPlaceholders() {
return get<{ data: PlaceholdersResponse }>('/api/v1/agents/placeholders');
}
// ===== 智能体类型预设 =====
// 后端 kb_filter 结构(见 internal/types/agent_type_preset.go)
export interface AgentTypeKBFilter {
any_of?: string[]; // KB 至少拥有其一
all_of?: string[]; // KB 必须全部拥有
none_of?: string[]; // KB 必须全部不拥有
}
// KB 能力标签(后端 types.KBCapabilities 的 JSON)
export interface KBCapabilities {
vector: boolean;
keyword: boolean;
wiki: boolean;
graph: boolean;
faq: boolean;
}
// 预设的"自动填充"配置载荷:仅包含被预设覆盖的字段;其他字段不动
export interface AgentTypePresetConfig {
system_prompt_id?: string;
temperature?: number;
max_iterations?: number;
allowed_tools?: string[];
retain_retrieval_history?: boolean;
faq_priority_enabled?: boolean;
web_search_enabled?: boolean;
supported_file_types?: string[];
kb_selection_mode?: 'all' | 'selected' | 'none';
}
export interface AgentTypePresetI18n {
label: string;
description: string;
}
export interface AgentTypePreset {
id: AgentType;
i18n: Record<string, AgentTypePresetI18n>;
config?: AgentTypePresetConfig; // 为空表示"自定义"类型(无预设)
kb_filter?: AgentTypeKBFilter; // 为空表示所有 KB 可选
}
// 拉取类型预设列表(编辑器用)
export function getAgentTypePresets() {
return get<{ data: AgentTypePreset[] }>('/api/v1/agents/type-presets');
}
// ===== IM渠道 =====
export interface IMChannel {
+13 -9
View File
@@ -472,12 +472,6 @@ export default {
retrieveKBOnlyWhenMentioned: 'Retrieve Only When Mentioned',
retrieveKBOnlyWhenMentionedDesc: "Off: auto-retrieve configured KBs; On: retrieve only when user {'@'} mentions",
retrievalSectionTitle: 'Retrieval Strategy',
retrievalPreference: 'Retrieval Preference',
retrievalPreferenceDesc: 'Controls which retrieval tools the agent uses to access knowledge bases',
retrievalPreferenceAuto: 'Auto (based on KB capabilities)',
retrievalPreferenceVectorOnly: 'RAG Only',
retrievalPreferenceWikiOnly: 'Wiki Only',
retrievalPreferenceHybrid: 'Hybrid (RAG + Wiki)',
rerankModel: 'ReRank Model',
rerankModelDesc: 'Used to rerank knowledge base retrieval results for better accuracy',
rerankModelPlaceholder: 'Select ReRank Model',
@@ -3571,9 +3565,6 @@ export default {
groupData: 'Data Analysis',
writeWarning: 'Mutates Wiki content',
dangerTag: 'Write',
// Preset
presetLabel: 'Retrieval Preset',
presetDesc: 'Switching the preset will update the checkboxes below (RAG / Wiki tools) in one click',
// Status bar
statusNoKb: 'No knowledge base is linked',
statusKb: 'In scope: {rag} RAG KBs · {wiki} Wiki KBs',
@@ -3639,6 +3630,19 @@ export default {
wechatQRExpired: 'QR code expired, please try again',
wechatBinding: 'Binding...',
},
agentType: {
label: 'Agent Type',
desc: 'Picking a preset auto-fills the system prompt, tool list and recommended KB scope.',
defaultNamePattern: 'My {label}',
kbMismatch: {
ragQa: 'RAG retrieval not enabled',
wikiQa: 'Wiki not enabled',
hybridRagWiki: 'No retrieval surface enabled',
dataAnalysis: 'Requires RAG (FAQ not supported)',
generic: 'Not compatible with current type',
},
kbIncompatibleWarn: '{count} selected KB(s) are not compatible with this type, please adjust manually.',
},
mcp: {
label: 'MCP Services',
desc: 'Select MCP services available to the Agent',
+13 -3
View File
@@ -3622,9 +3622,6 @@ export default {
groupData: '데이터 분석',
writeWarning: 'Wiki 내용을 변경합니다',
dangerTag: '쓰기',
// 프리셋
presetLabel: '검색 전략 프리셋',
presetDesc: '프리셋 전환 시 아래 체크박스(RAG/Wiki 도구)가 일괄 조정됩니다',
// 상태바
statusNoKb: '연결된 지식베이스가 없습니다',
statusKb: '범위 내: RAG 지식베이스 {rag}개 · Wiki 지식베이스 {wiki}개',
@@ -3636,6 +3633,19 @@ export default {
effectiveDesc: '현재 설정 기준 저장 시 에이전트가 실제 호출할 수 있는 도구 집합',
effectiveEmpty: '사용 가능한 도구가 없어 일반 모델 대화로 동작합니다',
},
agentType: {
label: '에이전트 유형',
desc: '프리셋을 선택하면 시스템 프롬프트, 도구 목록, 권장 지식 베이스 범위가 자동으로 채워집니다.',
defaultNamePattern: '나의 {label}',
kbMismatch: {
ragQa: 'RAG 검색 비활성화',
wikiQa: 'Wiki 비활성화',
hybridRagWiki: '활성화된 검색 수단 없음',
dataAnalysis: 'RAG 필요 (FAQ 미지원)',
generic: '현재 유형과 호환 안 됨',
},
kbIncompatibleWarn: '선택된 {count}개의 지식 베이스가 현재 유형과 호환되지 않습니다. 수동으로 조정해 주세요.',
},
mcp: {
label: 'MCP 서비스',
desc: 'Agent가 호출할 수 있는 MCP 서비스를 선택하세요',
+13 -3
View File
@@ -3192,9 +3192,6 @@ export default {
groupData: 'Анализ данных',
writeWarning: 'Изменяет содержимое Wiki',
dangerTag: 'Запись',
// Пресет
presetLabel: 'Пресет поиска',
presetDesc: 'Переключение пресета одним кликом меняет флажки ниже (инструменты RAG/Wiki)',
// Строка состояния
statusNoKb: 'База знаний не подключена',
statusKb: 'В области: {rag} RAG баз · {wiki} Wiki баз',
@@ -3251,6 +3248,19 @@ export default {
sessionModeThread: 'По потоку',
sessionModeHint: 'Режим пользователя: отдельный диалог для каждого пользователя. /clear для нового диалога. Режим потока: отдельный диалог для каждого потока. Несколько человек могут общаться в одном потоке.',
},
agentType: {
label: 'Тип агента',
desc: 'Выбор пресета автоматически заполняет системный промпт, список инструментов и рекомендуемую область баз знаний.',
defaultNamePattern: 'Мой {label}',
kbMismatch: {
ragQa: 'RAG-поиск отключён',
wikiQa: 'Wiki отключён',
hybridRagWiki: 'Поиск не включён',
dataAnalysis: 'Требуется RAG (не FAQ)',
generic: 'Несовместимо с типом',
},
kbIncompatibleWarn: 'Выбранные базы знаний ({count}) несовместимы с текущим типом. Настройте вручную.'
},
mcp: {
label: 'MCP-сервисы',
desc: 'Выберите MCP-сервисы, доступные агенту',
+13 -9
View File
@@ -1337,12 +1337,6 @@ export default {
retrieveKBOnlyWhenMentioned: "仅在 {'@'} 提及时检索",
retrieveKBOnlyWhenMentionedDesc: "关闭:自动检索已配置的知识库,开启:仅当用户 {'@'} 提及时才检索",
retrievalSectionTitle: "检索策略",
retrievalPreference: "检索偏好",
retrievalPreferenceDesc: "控制智能体使用哪些检索工具来访问知识库",
retrievalPreferenceAuto: "自动(根据知识库能力)",
retrievalPreferenceVectorOnly: "仅 RAG",
retrievalPreferenceWikiOnly: "仅 Wiki",
retrievalPreferenceHybrid: "混合(RAG + Wiki)",
rerankModel: "ReRank 模型",
rerankModelDesc: "用于对知识库检索结果进行重排序,提高回答准确性",
rerankModelPlaceholder: "请选择 ReRank 模型",
@@ -3623,9 +3617,6 @@ export default {
groupData: "数据分析",
writeWarning: "会修改 Wiki 内容",
dangerTag: "可写",
// 预设
presetLabel: "检索策略预设",
presetDesc: "切换预设会一次性调整下方勾选(对应的 RAG/Wiki 工具)",
// 顶部状态栏
statusNoKb: "当前未关联任何知识库",
statusKb: "作用域内:{rag} 个 RAG 知识库 · {wiki} 个 Wiki 知识库",
@@ -3637,6 +3628,19 @@ export default {
effectiveDesc: "根据当前配置计算,这是智能体保存后实际能调用的工具集合",
effectiveEmpty: "当前没有可用工具,智能体将退化为纯模型问答",
},
agentType: {
label: "智能体类型",
desc: "选择一个预设会自动填充系统提示词、工具列表和推荐的知识库范围。",
defaultNamePattern: "我的{label}",
kbMismatch: {
ragQa: "未启用 RAG 检索",
wikiQa: "未启用 Wiki",
hybridRagWiki: "未启用任何检索能力",
dataAnalysis: "需启用 RAG(不支持 FAQ)",
generic: "不适用于当前类型",
},
kbIncompatibleWarn: "已选的 {count} 个知识库不适用于当前类型,请手动调整",
},
mcp: {
label: "MCP 服务",
desc: "选择 Agent 可以调用的 MCP 服务",
+430 -110
View File
@@ -64,6 +64,36 @@
</div>
</div>
<!-- 智能体类型(仅智能推理模式下显示) -->
<div v-if="isAgentMode && agentTypePresets.length > 0" class="setting-row setting-row--emphasize">
<div class="setting-info">
<label>{{ $t('agentEditor.agentType.label') }}</label>
<p class="desc">{{ $t('agentEditor.agentType.desc') }}</p>
<p
v-if="activeAgentTypePreset"
class="desc agent-type-preset-desc"
>{{ agentTypePresetDescription(activeAgentTypePreset) }}</p>
</div>
<div class="setting-control">
<t-select
:value="agentType"
@change="onAgentTypeChange"
:disabled="isBuiltinAgent"
:placeholder="$t('agentEditor.agentType.label')"
:options="agentTypeSelectOptions"
:popup-props="{ overlayClassName: 'agent-type-popup' }"
class="agent-type-select"
>
<template #option="{ option }">
<div class="agent-type-option">
<span class="agent-type-option-label">{{ option.label }}</span>
<span v-if="option.desc" class="agent-type-option-desc">{{ option.desc }}</span>
</div>
</template>
</t-select>
</div>
</div>
<!-- 名称 -->
<div class="setting-row">
<div class="setting-info">
@@ -142,7 +172,7 @@
position="corner"
:hasKnowledgeBase="hasKnowledgeBase"
@select="handleSystemPromptTemplateSelect"
@reset-default="handleSystemPromptTemplateSelect"
@reset-default="handleAgentSystemPromptResetDefault"
/>
</div>
<!-- 普通模式:单个提示词 -->
@@ -627,23 +657,6 @@
<span>{{ $t('agentEditor.tools.statusInactive', { count: inactiveToolCount }) }}</span>
</div>
</div>
<div class="tools-overview-row tools-overview-row--preset">
<div class="tools-preset-label">
<span class="tools-preset-title">{{ $t('agentEditor.tools.presetLabel') }}</span>
<span class="tools-preset-hint">{{ $t('agentEditor.tools.presetDesc') }}</span>
</div>
<t-radio-group
:value="formData.config.retrieval_preference"
@change="onRetrievalPresetChange"
size="small"
variant="default-filled"
>
<t-radio-button value="auto">{{ $t('agent.editor.retrievalPreferenceAuto') }}</t-radio-button>
<t-radio-button value="vector_only">{{ $t('agent.editor.retrievalPreferenceVectorOnly') }}</t-radio-button>
<t-radio-button value="wiki_only">{{ $t('agent.editor.retrievalPreferenceWikiOnly') }}</t-radio-button>
<t-radio-button value="hybrid">{{ $t('agent.editor.retrievalPreferenceHybrid') }}</t-radio-button>
</t-radio-group>
</div>
</div>
<div class="settings-group">
@@ -876,14 +889,15 @@
filterable
:min-collapsed-num="3"
>
<t-option-group v-if="myKbOptions.length" :label="$t('agent.editor.myKnowledgeBases')">
<t-option-group v-if="filteredMyKbOptions.length" :label="$t('agent.editor.myKnowledgeBases')">
<t-option
v-for="kb in myKbOptions"
v-for="kb in filteredMyKbOptions"
:key="kb.value"
:value="kb.value"
:label="kb.label"
:disabled="kb.disabled"
>
<div class="kb-option-item">
<div class="kb-option-item" :title="kb.disabled ? kb.disabledReason : ''">
<span class="kb-option-icon" :class="kb.type === 'faq' ? 'faq-icon' : 'doc-icon'">
<t-icon :name="kb.type === 'faq' ? 'chat-bubble-help' : 'folder'" />
</span>
@@ -891,17 +905,19 @@
<span v-if="kb.ragEnabled" class="kb-option-tag tag-rag">RAG</span>
<span v-if="kb.wikiEnabled" class="kb-option-tag tag-wiki">Wiki</span>
<span class="kb-option-count">{{ kb.count || 0 }}</span>
<span v-if="kb.disabled" class="kb-option-disabled-hint">{{ kb.disabledReason }}</span>
</div>
</t-option>
</t-option-group>
<t-option-group v-if="sharedKbOptions.length" :label="$t('agent.editor.sharedKnowledgeBases')">
<t-option-group v-if="filteredSharedKbOptions.length" :label="$t('agent.editor.sharedKnowledgeBases')">
<t-option
v-for="kb in sharedKbOptions"
v-for="kb in filteredSharedKbOptions"
:key="kb.value"
:value="kb.value"
:label="kb.label"
:disabled="kb.disabled"
>
<div class="kb-option-item">
<div class="kb-option-item" :title="kb.disabled ? kb.disabledReason : ''">
<span class="kb-option-icon" :class="kb.type === 'faq' ? 'faq-icon' : 'doc-icon'">
<t-icon :name="kb.type === 'faq' ? 'chat-bubble-help' : 'folder'" />
</span>
@@ -910,6 +926,7 @@
<span v-if="kb.wikiEnabled" class="kb-option-tag tag-wiki">Wiki</span>
<span v-if="kb.orgName" class="kb-option-org">{{ kb.orgName }}</span>
<span class="kb-option-count">{{ kb.count || 0 }}</span>
<span v-if="kb.disabled" class="kb-option-disabled-hint">{{ kb.disabledReason }}</span>
</div>
</t-option>
</t-option-group>
@@ -1116,25 +1133,6 @@
</div>
<div class="settings-group">
<!-- 检索偏好 -->
<div class="setting-row">
<div class="setting-info">
<label>{{ $t('agent.editor.retrievalPreference') }}</label>
<p class="desc">{{ $t('agent.editor.retrievalPreferenceDesc') }}</p>
</div>
<div class="setting-control">
<t-select
v-model="formData.config.retrieval_preference"
style="width: 200px"
>
<t-option value="auto">{{ $t('agent.editor.retrievalPreferenceAuto') }}</t-option>
<t-option value="vector_only">{{ $t('agent.editor.retrievalPreferenceVectorOnly') }}</t-option>
<t-option value="wiki_only">{{ $t('agent.editor.retrievalPreferenceWikiOnly') }}</t-option>
<t-option value="hybrid">{{ $t('agent.editor.retrievalPreferenceHybrid') }}</t-option>
</t-select>
</div>
</div>
<!-- 查询扩展(仅普通模式) -->
<div v-if="!isAgentMode" class="setting-row">
<div class="setting-info">
@@ -1356,13 +1354,23 @@
import { ref, computed, watch, nextTick } from 'vue';
import { useI18n } from 'vue-i18n';
import { MessagePlugin } from 'tdesign-vue-next';
import { createAgent, updateAgent, getPlaceholders, type CustomAgent, type PlaceholderDefinition } from '@/api/agent';
import {
createAgent,
updateAgent,
getPlaceholders,
getAgentTypePresets,
type CustomAgent,
type PlaceholderDefinition,
type AgentTypePreset,
type AgentType,
type KBCapabilities,
} from '@/api/agent';
import { listModels, type ModelConfig } from '@/api/model';
import { listKnowledgeBases } from '@/api/knowledge-base';
import { listMCPServices, type MCPService } from '@/api/mcp-service';
import { listSkills, type SkillInfo } from '@/api/skill';
import { listWebSearchProviders, type WebSearchProviderEntity } from '@/api/web-search-provider';
import { getAgentConfig, getConversationConfig, getStorageEngineStatus, type StorageEngineStatusItem, type PromptTemplate } from '@/api/system';
import { getAgentConfig, getConversationConfig, getStorageEngineStatus, getPromptTemplates, type StorageEngineStatusItem, type PromptTemplate } from '@/api/system';
import { useUIStore } from '@/stores/ui';
import { useAuthStore } from '@/stores/auth';
import { useOrganizationStore } from '@/stores/organization';
@@ -1376,7 +1384,7 @@ const uiStore = useUIStore();
const authStore = useAuthStore();
const orgStore = useOrganizationStore();
const { t } = useI18n();
const { t, locale: i18nLocale } = useI18n();
const props = defineProps<{
visible: boolean;
@@ -1393,7 +1401,12 @@ const emit = defineEmits<{
const currentSection = ref(props.initialSection || 'basic');
const saving = ref(false);
const allModels = ref<ModelConfig[]>([]);
const kbOptions = ref<{ label: string; value: string; type?: 'document' | 'faq'; count?: number; shared?: boolean; orgName?: string; ragEnabled?: boolean; wikiEnabled?: boolean }[]>([]);
const kbOptions = ref<{ label: string; value: string; type?: 'document' | 'faq'; count?: number; shared?: boolean; orgName?: string; ragEnabled?: boolean; wikiEnabled?: boolean; capabilities?: KBCapabilities }[]>([]);
// 智能体类型预设(仅 smart-reasoning 模式下展示)
const agentTypePresets = ref<AgentTypePreset[]>([]);
// Agent 系统提示词模板缓存(用于切换智能体类型时根据 system_prompt_id 解析出实际文本填入)
const agentSystemPromptTemplates = ref<PromptTemplate[]>([]);
const mcpOptions = ref<{ label: string; value: string }[]>([]);
const webSearchProviderList = ref<WebSearchProviderEntity[]>([]);
const skillOptions = ref<{ name: string; description: string }[]>([]);
@@ -1748,7 +1761,7 @@ const defaultFormData = {
is_builtin: false,
config: {
// 基础设置
agent_mode: 'quick-answer' as 'quick-answer' | 'smart-reasoning',
agent_mode: 'smart-reasoning' as 'quick-answer' | 'smart-reasoning',
system_prompt: '',
context_template: '{{query}}',
// 模型设置
@@ -1771,7 +1784,10 @@ const defaultFormData = {
kb_selection_mode: 'none' as 'all' | 'selected' | 'none',
knowledge_bases: [] as string[],
retrieve_kb_only_when_mentioned: false,
retrieval_preference: 'auto' as 'auto' | 'vector_only' | 'wiki_only' | 'hybrid',
// 智能推理下的类型预设:新建 agent 时默认给 RAG 问答(最常用场景)。
// 编辑既有 agent 时会被 agent 自己保存的 agent_type 覆盖。
agent_type: 'rag-qa' as AgentType,
system_prompt_id: '' as string,
// 图片上传/多模态设置
image_upload_enabled: false,
vlm_model_id: '',
@@ -1816,6 +1832,209 @@ const agentMode = computed({
const isAgentMode = computed(() => agentMode.value === 'smart-reasoning');
// ============================================================================
// 智能体类型预设(仅 smart-reasoning 模式下可见)
// 选择类型后自动填充 system_prompt_id / allowed_tools 等;
// 选择 "custom" 或没有匹配预设时不做任何覆盖。
// ============================================================================
const agentType = computed({
get: () => (formData.value.config.agent_type as AgentType) || 'custom',
set: (val: AgentType) => { formData.value.config.agent_type = val; },
});
// 当前激活的预设对象(用于 KB 过滤 / UI 徽章)
const activeAgentTypePreset = computed<AgentTypePreset | null>(() => {
if (!isAgentMode.value) return null;
const id = agentType.value;
if (!id || id === 'custom') return null;
return agentTypePresets.value.find(p => p.id === id) || null;
});
// 根据当前 locale 挑选 i18n 标签
const agentTypePresetLabel = (p: AgentTypePreset): string => {
const locale = i18nLocale.value || 'default';
return p.i18n?.[locale]?.label || p.i18n?.default?.label || p.id;
};
const agentTypePresetDescription = (p: AgentTypePreset): string => {
const locale = i18nLocale.value || 'default';
return p.i18n?.[locale]?.description || p.i18n?.default?.description || '';
};
// t-select 的 options 数据:label 给 TDesign 自己(用于选中态显示),desc 走自定义 option slot
const agentTypeSelectOptions = computed(() => {
return agentTypePresets.value.map(p => ({
value: p.id,
label: agentTypePresetLabel(p),
desc: agentTypePresetDescription(p),
}));
});
// 为每个预设生成"我的 <label>"的默认名称,让用户可以一键保存
// custom 类型默认名为空(让用户自己想)
const getPresetDefaultName = (preset: AgentTypePreset | null): string => {
if (!preset || preset.id === 'custom') return '';
return t('agentEditor.agentType.defaultNamePattern', { label: agentTypePresetLabel(preset) });
};
const getPresetDefaultDescription = (preset: AgentTypePreset | null): string => {
if (!preset) return '';
return agentTypePresetDescription(preset);
};
// 判断当前名称/描述是否由系统自动填入(任一预设的默认值 或 空)
// 用于在切换类型时只覆盖"未被用户手动编辑"的值,避免覆盖用户输入
const isNameSystemGenerated = (name: string): boolean => {
if (!name) return true;
return agentTypePresets.value.some(p => getPresetDefaultName(p) === name);
};
const isDescriptionSystemGenerated = (desc: string): boolean => {
if (!desc) return true;
return agentTypePresets.value.some(p => getPresetDefaultDescription(p) === desc);
};
// 按预设 id 返回面向用户的不兼容原因文案。
// 不要直接把 "vector / keyword / wiki" 这些底层 capability 名回传给用户 —
// 用户不关心技术实现,只想知道"为什么我这个知识库不能用"。
const presetKbMismatchKeyMap: Record<string, string> = {
'rag-qa': 'ragQa',
'wiki-qa': 'wikiQa',
'hybrid-rag-wiki': 'hybridRagWiki',
'data-analysis': 'dataAnalysis',
};
const presetKbMismatchReason = (preset: AgentTypePreset): string => {
const subKey = presetKbMismatchKeyMap[preset.id];
if (subKey) return t(`agentEditor.agentType.kbMismatch.${subKey}`);
return t('agentEditor.agentType.kbMismatch.generic');
};
// 评估单个 KB 是否满足给定预设的 kb_filter
const kbSatisfiesPresetFilter = (kb: { capabilities?: KBCapabilities; ragEnabled?: boolean; wikiEnabled?: boolean; type?: string }, preset: AgentTypePreset | null): { ok: boolean; reason: string } => {
if (!preset || !preset.kb_filter) return { ok: true, reason: '' };
const caps = kb.capabilities || {
vector: !!kb.ragEnabled,
keyword: !!kb.ragEnabled,
wiki: !!kb.wikiEnabled,
graph: false,
faq: kb.type === 'faq',
};
const has = (name: string): boolean => {
switch (name) {
case 'vector': return !!caps.vector;
case 'keyword': return !!caps.keyword;
case 'wiki': return !!caps.wiki;
case 'graph': return !!caps.graph;
case 'faq': return !!caps.faq;
default: return false;
}
};
const f = preset.kb_filter;
const reason = presetKbMismatchReason(preset);
if (f.all_of && f.all_of.length > 0) {
for (const n of f.all_of) {
if (!has(n)) return { ok: false, reason };
}
}
if (f.any_of && f.any_of.length > 0) {
if (!f.any_of.some(n => has(n))) {
return { ok: false, reason };
}
}
if (f.none_of && f.none_of.length > 0) {
for (const n of f.none_of) {
if (has(n)) return { ok: false, reason };
}
}
return { ok: true, reason: '' };
};
// KB 过滤后的选项(用于"指定知识库"下拉)— 不满足的仍保留但标记 disabled + tooltip
const filteredKbOptionsForPreset = computed(() => {
const preset = activeAgentTypePreset.value;
return kbOptions.value.map(kb => {
const { ok, reason } = kbSatisfiesPresetFilter(kb, preset);
return { ...kb, disabled: !ok, disabledReason: reason };
});
});
const filteredMyKbOptions = computed(() => filteredKbOptionsForPreset.value.filter(kb => !kb.shared));
const filteredSharedKbOptions = computed(() => filteredKbOptionsForPreset.value.filter(kb => kb.shared));
// 当前选中的 KB 中,有多少个在新预设下会被禁用(用于保存前提示)
const incompatibleSelectedKbCount = computed(() => {
const preset = activeAgentTypePreset.value;
if (!preset || kbSelectionMode.value !== 'selected') return 0;
const selected = new Set(formData.value.config.knowledge_bases || []);
return filteredKbOptionsForPreset.value.filter(kb => selected.has(kb.value) && kb.disabled).length;
});
// 应用一个预设的 config 到 formData.config(仅覆盖预设里明确设置的字段,其他不动)
const applyAgentTypePreset = (preset: AgentTypePreset | null) => {
if (!preset || !preset.config) return;
const c = preset.config;
const target = formData.value.config;
if (c.system_prompt_id !== undefined) {
target.system_prompt_id = c.system_prompt_id;
// 根据 system_prompt_id 从已加载的模板列表里查出正文并回填到用户可见的 textarea
const tmpl = agentSystemPromptTemplates.value.find(t => t.id === c.system_prompt_id);
if (tmpl && typeof tmpl.content === 'string') {
target.system_prompt = tmpl.content;
} else {
// 模板列表还没加载完 / 或预设引用了不存在的 id:清空让用户感知到变化
target.system_prompt = '';
if (c.system_prompt_id) {
console.warn(`[AgentType] system_prompt_id "${c.system_prompt_id}" not found in agent_system_prompt templates`);
}
}
}
if (typeof c.temperature === 'number') target.temperature = c.temperature;
if (typeof c.max_iterations === 'number') target.max_iterations = c.max_iterations;
if (Array.isArray(c.allowed_tools)) target.allowed_tools = [...c.allowed_tools];
if (typeof c.retain_retrieval_history === 'boolean') target.retain_retrieval_history = c.retain_retrieval_history;
if (typeof c.faq_priority_enabled === 'boolean') target.faq_priority_enabled = c.faq_priority_enabled;
if (typeof c.web_search_enabled === 'boolean') target.web_search_enabled = c.web_search_enabled;
// supported_file_types 采用"强同步"语义:只有 data-analysis 需要限定 csv/xlsx,
// 其余类型切过来时必须清空,否则会从上一个类型带过来残留。
if (Array.isArray(c.supported_file_types)) {
target.supported_file_types = [...c.supported_file_types];
} else {
target.supported_file_types = [];
}
// kb_selection_mode 同步到 formData 以及 UI 状态(两处都要改,否则单选按钮不更新)
if (c.kb_selection_mode) {
target.kb_selection_mode = c.kb_selection_mode;
kbSelectionMode.value = c.kb_selection_mode;
}
};
// 用户手动切换类型 → 应用预设
const onAgentTypeChange = (val: AgentType) => {
// 切换前捕获"名称/描述是否可安全覆盖"
// 已编辑过的用户输入(不等于任何预设默认值)绝不覆盖
const canOverrideName = isNameSystemGenerated(formData.value.name);
const canOverrideDesc = isDescriptionSystemGenerated(formData.value.description);
agentType.value = val;
const preset = agentTypePresets.value.find(p => p.id === val) || null;
if (val !== 'custom') {
applyAgentTypePreset(preset);
}
// 用新预设的默认名/描述刷新自动填充字段
if (canOverrideName) {
formData.value.name = getPresetDefaultName(preset);
}
if (canOverrideDesc) {
formData.value.description = getPresetDefaultDescription(preset);
}
// 如果新预设与当前已选 KB 冲突,软提示(不强制移除)
if (incompatibleSelectedKbCount.value > 0) {
MessagePlugin.warning(
t('agentEditor.agentType.kbIncompatibleWarn', { count: incompatibleSelectedKbCount.value }),
4000,
);
}
};
// 思考模式计算属性(直接绑定 boolean)
const thinkingEnabled = computed({
get: () => formData.value.config.thinking === true,
@@ -1943,6 +2162,25 @@ watch(() => props.visible, async (val) => {
kbSelectionMode.value = 'none';
mcpSelectionMode.value = 'none';
skillsSelectionMode.value = 'none';
// 新建智能推理 agent 时,立即应用默认的 agent_type 预设
// (补齐 system_prompt / allowed_tools / kb_selection_mode 等),
// 否则用户在 modal 打开瞬间看到的"默认表单"和类型下拉显示的类型不一致。
if (newFormData.config.agent_mode === 'smart-reasoning') {
const defaultTypeId = newFormData.config.agent_type as AgentType;
const preset = agentTypePresets.value.find(p => p.id === defaultTypeId) || null;
if (defaultTypeId && defaultTypeId !== 'custom') {
applyAgentTypePreset(preset);
}
// 给新建表单补上"我的 XXX"默认名 + 预设描述,让用户可直接保存;
// 用户输入过的值不会被覆盖(此处是新建场景,字段必定为空)。
if (!formData.value.name) {
formData.value.name = getPresetDefaultName(preset);
}
if (!formData.value.description) {
formData.value.description = getPresetDefaultDescription(preset);
}
}
}
}
});
@@ -2063,9 +2301,11 @@ watch(skillsSelectionMode, (mode) => {
// 监听模式变化,自动调整配置
watch(agentMode, (val, _oldVal) => {
if (val === 'smart-reasoning') {
// 切换到 Agent 模式,根据知识库配置启用工具
// 切换到 Agent 模式,根据知识库配置启用工具。
// 注意:默认不注入 thinking / todo_write —— 它们用于显式反思或多步计划,
// 会显著增加 token 消耗,用户按需手动勾选。
if (formData.value.config.allowed_tools.length === 0) {
const tools = ['thinking', 'todo_write'];
const tools: string[] = [];
if (hasRagKnowledgeBase.value) {
tools.push(
'knowledge_search',
@@ -2154,43 +2394,6 @@ watch(hasWikiKnowledgeBase, (hasWiki, oldHasWiki) => {
}
});
// 检索策略预设:一键改写 allowed_tools
// auto -> 按作用域内知识库能力自动补齐(RAG 库 → RAG 工具;Wiki 库 → Wiki 读取工具)
// vector_only -> 只保留 RAG 工具,移除 Wiki 工具
// wiki_only -> 只保留 Wiki 读取工具,移除 RAG 工具
// hybrid -> 两者都补齐
const onRetrievalPresetChange = (val: string) => {
formData.value.config.retrieval_preference = val as 'auto' | 'vector_only' | 'wiki_only' | 'hybrid';
if (!isAgentMode.value) return;
const current = new Set(formData.value.config.allowed_tools || []);
const addAll = (list: string[]) => list.forEach(t => current.add(t));
const removeAll = (list: string[]) => list.forEach(t => current.delete(t));
switch (val) {
case 'vector_only':
if (hasRagKnowledgeBase.value) addAll(knowledgeBaseTools);
removeAll(allWikiTools);
break;
case 'wiki_only':
removeAll(knowledgeBaseTools);
if (hasWikiKnowledgeBase.value) addAll(wikiReadTools);
break;
case 'hybrid':
if (hasRagKnowledgeBase.value) addAll(knowledgeBaseTools);
if (hasWikiKnowledgeBase.value) addAll(wikiReadTools);
break;
case 'auto':
default:
if (hasRagKnowledgeBase.value) addAll(knowledgeBaseTools);
if (hasWikiKnowledgeBase.value) addAll(wikiReadTools);
break;
}
formData.value.config.allowed_tools = Array.from(current);
};
// 监听运行模式变化,自动切换页面
watch(isAgentMode, (isAgent) => {
// 如果当前在高级设置页面但切换到了Agent模式,切换到基础设置
@@ -2239,14 +2442,16 @@ const loadDependencies = async () => {
if (kbRes.data) {
kbRes.data.forEach((kb: any) => {
const strategy = kb.indexing_strategy;
const caps: KBCapabilities | undefined = kb.capabilities;
myKbs.push({
label: kb.name,
value: kb.id,
type: kb.type || 'document',
count: kb.type === 'faq' ? (kb.chunk_count || 0) : (kb.knowledge_count || 0),
shared: false,
ragEnabled: !strategy || strategy.vector_enabled || strategy.keyword_enabled,
wikiEnabled: strategy?.wiki_enabled || false,
ragEnabled: caps ? (caps.vector || caps.keyword) : (!strategy || strategy.vector_enabled || strategy.keyword_enabled),
wikiEnabled: caps ? caps.wiki : (strategy?.wiki_enabled || false),
capabilities: caps,
});
});
}
@@ -2260,6 +2465,7 @@ const loadDependencies = async () => {
sharedList.forEach((shared: any) => {
const kb = shared.knowledge_base;
if (!kb || myKbIds.has(kb.id)) return;
const caps: KBCapabilities | undefined = kb.capabilities;
sharedKbs.push({
label: kb.name,
value: kb.id,
@@ -2267,8 +2473,9 @@ const loadDependencies = async () => {
count: kb.type === 'faq' ? (kb.chunk_count || 0) : (kb.knowledge_count || 0),
shared: true,
orgName: shared.org_name,
ragEnabled: !kb.indexing_strategy || kb.indexing_strategy.vector_enabled || kb.indexing_strategy.keyword_enabled,
wikiEnabled: kb.indexing_strategy?.wiki_enabled || false,
ragEnabled: caps ? (caps.vector || caps.keyword) : (!kb.indexing_strategy || kb.indexing_strategy.vector_enabled || kb.indexing_strategy.keyword_enabled),
wikiEnabled: caps ? caps.wiki : (kb.indexing_strategy?.wiki_enabled || false),
capabilities: caps,
});
});
}
@@ -2302,6 +2509,27 @@ const loadDependencies = async () => {
skillsAvailable.value = false;
}
// 加载智能体类型预设(smart-reasoning 模式下的"类型"下拉)
try {
const presetsRes: any = await getAgentTypePresets();
if (presetsRes?.data && Array.isArray(presetsRes.data)) {
agentTypePresets.value = presetsRes.data as AgentTypePreset[];
}
} catch (e) {
console.warn('Failed to load agent type presets', e);
}
// 加载 Agent 系统提示词模板(供 applyAgentTypePreset 根据 system_prompt_id 回填正文)
try {
const tmplRes = await getPromptTemplates();
const cfg = tmplRes?.data;
if (cfg?.agent_system_prompt && Array.isArray(cfg.agent_system_prompt)) {
agentSystemPromptTemplates.value = cfg.agent_system_prompt;
}
} catch (e) {
console.warn('Failed to load prompt templates for agent type presets', e);
}
// 加载存储引擎可用状态(用于图片存储 provider 选择)
try {
const statusRes = await getStorageEngineStatus();
@@ -3116,6 +3344,30 @@ const handleSystemPromptTemplateSelect = (template: PromptTemplate) => {
formData.value.config.system_prompt = template.content;
};
// Agent 系统提示词的"恢复默认":
// 当前选中了非 custom 的智能体类型时,"默认"应当是该类型预设绑定的提示词
// (比如 Wiki 问答 → wiki_researcher),而不是 agent_system_prompt 模板表里
// 全局 default: true 的那一条。只有当类型为 custom 或找不到预设绑定的模板时,
// 才回退到 PromptTemplateSelector 传来的全局默认模板。
const handleAgentSystemPromptResetDefault = (fallback: PromptTemplate) => {
const typeId = agentType.value;
if (typeId && typeId !== 'custom') {
const preset = agentTypePresets.value.find(p => p.id === typeId);
const presetPromptId = preset?.config?.system_prompt_id;
if (presetPromptId) {
const tmpl = agentSystemPromptTemplates.value.find(t => t.id === presetPromptId);
if (tmpl && typeof tmpl.content === 'string') {
formData.value.config.system_prompt = tmpl.content;
formData.value.config.system_prompt_id = tmpl.id;
return;
}
}
}
// Fallback:没有合适的类型预设,用 PromptTemplateSelector 找到的全局默认
formData.value.config.system_prompt = fallback.content;
formData.value.config.system_prompt_id = fallback.id;
};
const handleContextTemplateSelect = (template: PromptTemplate) => {
formData.value.config.context_template = template.content;
};
@@ -3445,6 +3697,28 @@ const handleSave = async () => {
padding-right: 0;
}
}
// 强调行:用于"智能体类型"这类对用户影响最大、需要突出的关键配置。
// 视觉上只做极轻度强调 —— 左侧 3px 品牌色竖条 + label 加粗。
&.setting-row--emphasize {
position: relative;
padding-left: 14px;
&::before {
content: '';
position: absolute;
left: 0;
top: 22px;
bottom: 22px;
width: 3px;
border-radius: 2px;
background: var(--td-brand-color, #0052d9);
}
.setting-info label {
font-weight: 600;
}
}
}
.setting-info {
@@ -3727,24 +4001,6 @@ const handleSave = async () => {
}
}
.tools-preset-label {
display: flex;
flex-direction: column;
min-width: 0;
gap: 2px;
.tools-preset-title {
font-size: 13px;
font-weight: 600;
color: var(--td-text-color-primary);
}
.tools-preset-hint {
font-size: 12px;
color: var(--td-text-color-secondary);
}
}
// ===== 按组的卡片网格 =====
.tool-groups {
display: flex;
@@ -4404,6 +4660,32 @@ const handleSave = async () => {
white-space: nowrap;
}
.kb-option-disabled-hint {
flex-shrink: 0;
font-size: 11px;
color: var(--td-warning-color-6, #d46b08);
background: var(--td-warning-color-1, #fff7e6);
padding: 1px 6px;
border-radius: 4px;
max-width: 240px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.agent-type-preset-desc {
margin-top: 4px;
color: var(--td-text-color-secondary);
font-size: 12px;
line-height: 1.5;
}
.agent-type-select {
width: 100%;
min-width: 240px;
max-width: 360px;
}
.kb-option-count {
flex-shrink: 0;
font-size: 11px;
@@ -4475,3 +4757,41 @@ const handleSave = async () => {
}
}
</style>
<!-- Non-scoped styles: TDesign teleports the popup outside this component, so
scoped selectors can't reach .agent-type-popup .t-select-option. -->
<style lang="less">
.agent-type-popup {
.t-select-option {
// 默认 option 是 32px 单行;我们要双行显示,取消固定高度并放宽 padding
height: auto !important;
min-height: 48px;
line-height: 1.4;
padding: 8px 12px;
white-space: normal;
}
}
.agent-type-option {
display: flex;
flex-direction: column;
gap: 2px;
min-width: 0;
width: 100%;
}
.agent-type-option-label {
font-size: 13px;
font-weight: 500;
color: var(--td-text-color-primary);
line-height: 1.4;
}
.agent-type-option-desc {
font-size: 12px;
color: var(--td-text-color-secondary);
line-height: 1.4;
white-space: normal;
overflow-wrap: break-word;
}
</style>