feat: add fallback mode for AI agents and update knowledge base handling

- Introduced AIAgentFallbackMode with options for NoAnswer and SuggestRetry.
- Updated AI agent edit component to include fallback mode selection.
- Modified API types and payloads to accommodate fallback mode.
- Removed deprecated KnowledgeFallbackMode and related logic from knowledge base.
- Adjusted knowledge retrieval and response handling to utilize new fallback logic.
- Updated tests to reflect changes in fallback mode handling for AI agents.
This commit is contained in:
mlogclub
2026-04-18 13:36:44 +08:00
parent d9c4b669b2
commit c84870b968
25 changed files with 497 additions and 139 deletions
@@ -50,6 +50,8 @@ import {
} from "@/lib/api/admin";
import { getEnumOptions } from "@/lib/enums";
import {
AIAgentFallbackMode,
AIAgentFallbackModeLabels,
AIAgentHandoffMode,
AIAgentHandoffModeLabels,
AIModelType,
@@ -93,6 +95,7 @@ const schema = z.object({
.number()
.min(0, "回复超时秒数必须是大于等于 0 的整数"),
handoffMode: z.string().trim().min(1, "请选择转人工模式"),
fallbackMode: z.string().trim().min(1, "请选择兜底策略"),
fallbackMessage: z.string().trim(),
});
@@ -118,6 +121,13 @@ const handoffModeOptions = getEnumOptions(AIAgentHandoffModeLabels).map(
}),
);
const fallbackModeOptions = getEnumOptions(AIAgentFallbackModeLabels).map(
(option) => ({
value: String(option.value),
label: option.label,
}),
);
function buildForm(item: AIAgent | null): EditForm {
if (!item) {
return {
@@ -129,6 +139,7 @@ function buildForm(item: AIAgent | null): EditForm {
welcomeMessage: "",
replyTimeoutSeconds: 180,
handoffMode: String(AIAgentHandoffMode.WaitPool),
fallbackMode: String(AIAgentFallbackMode.NoAnswer),
fallbackMessage: "",
};
}
@@ -141,6 +152,7 @@ function buildForm(item: AIAgent | null): EditForm {
welcomeMessage: item.welcomeMessage || "",
replyTimeoutSeconds: item.replyTimeoutSeconds ?? 180,
handoffMode: String(item.handoffMode),
fallbackMode: String(item.fallbackMode),
fallbackMessage: item.fallbackMessage || "",
};
}
@@ -163,6 +175,7 @@ function buildPayload(
replyTimeoutSeconds: Number(form.replyTimeoutSeconds),
teamIds,
handoffMode: Number(form.handoffMode),
fallbackMode: Number(form.fallbackMode),
fallbackMessage: form.fallbackMessage.trim(),
knowledgeIds,
skillIds,
@@ -737,13 +750,34 @@ function EditDialogBody({
</FieldContent>
</Field>
<Field data-invalid={!!errors.fallbackMode}>
<FieldLabel></FieldLabel>
<FieldContent className="space-y-3">
<Controller
control={control}
name="fallbackMode"
render={({ field }) => (
<OptionCombobox
value={field.value}
options={fallbackModeOptions}
placeholder="请选择兜底策略"
searchPlaceholder="搜索兜底策略"
emptyText="未找到兜底策略"
onChange={field.onChange}
/>
)}
/>
<FieldError errors={[errors.fallbackMode]} />
</FieldContent>
</Field>
<Field data-invalid={!!errors.fallbackMessage}>
<FieldLabel htmlFor="ai-agent-fallback-message">
</FieldLabel>
<FieldContent>
<div className="text-xs text-muted-foreground mb-1">
使 AI Graph Tool
Graph Tool
</div>
<Textarea
id="ai-agent-fallback-message"