feat: add agent response depth control

This commit is contained in:
2026-07-20 11:36:18 +08:00
parent 537978082a
commit c2655361b5
12 changed files with 192 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ import { computed, nextTick, onMounted, reactive, ref, watch } from "vue";
import { api, streamDebugAgent } from "../services/api";
import type { AgentRuntimeConfig, KnowledgeItem, ModelItem, PromptDetail, PromptHistoryItem } from "../types/api";
import AgentGenerationParameters from "./AgentGenerationParameters.vue";
import AgentResponseDepthControl from "./AgentResponseDepthControl.vue";
import AdminPagination from "./AdminPagination.vue";
import StreamingMarkdownMessage from "./StreamingMarkdownMessage.vue";
@@ -51,6 +52,7 @@ const agentForm = reactive({
maxToken: 8192 as number | null,
streamEnabled: 1,
reasoningVisible: 0,
responseDepth: 35,
question: "",
});
const runtimeConfig = ref<AgentRuntimeConfig | null>(null);
@@ -63,6 +65,7 @@ const runtimeForm = reactive({
maxToken: 8192 as number | null,
streamEnabled: 1,
reasoningVisible: 0,
responseDepth: 35,
});
const promptDirty = computed(() => promptContent.value !== savedPromptContent.value);
@@ -119,6 +122,7 @@ function applyRuntimeConfig(value: AgentRuntimeConfig) {
maxToken: value.maxToken,
streamEnabled: value.streamEnabled,
reasoningVisible: value.reasoningVisible,
responseDepth: value.responseDepth ?? 35,
});
}
@@ -134,6 +138,7 @@ function applyDebugModelDefaults(modelId?: number) {
maxToken: model.maxToken ?? (model.enabled === 1 ? runtimeConfig.value?.maxToken : null) ?? 8192,
streamEnabled: model.streamEnabled ?? 1,
reasoningVisible: runtimeConfig.value?.reasoningVisible ?? 0,
responseDepth: runtimeConfig.value?.responseDepth ?? 35,
});
}
@@ -151,6 +156,7 @@ async function saveRuntimeConfig() {
maxToken: runtimeForm.maxToken,
streamEnabled: runtimeForm.streamEnabled,
reasoningVisible: runtimeForm.reasoningVisible,
responseDepth: runtimeForm.responseDepth,
});
applyRuntimeConfig(saved);
const model = models.value.find((item) => item.id === saved.modelId);
@@ -304,6 +310,7 @@ async function debugAgent() {
maxToken: agentForm.maxToken,
streamEnabled: agentForm.streamEnabled,
reasoningVisible: agentForm.reasoningVisible,
responseDepth: agentForm.responseDepth,
},
(chunk) => {
currentAssistant().content += chunk;
@@ -423,6 +430,7 @@ function errorMessage(error: unknown, fallback: string) {
v-model:max-token="runtimeForm.maxToken"
:disabled="!runtimeConfig?.modelId"
/>
<AgentResponseDepthControl v-model="runtimeForm.responseDepth" :disabled="!runtimeConfig?.modelId" />
<el-form-item class="agent-stream-setting">
<div class="agent-stream-setting-copy">
<strong>用户端流式输出</strong>
@@ -480,6 +488,7 @@ function errorMessage(error: unknown, fallback: string) {
v-model:frequency-penalty="agentForm.frequencyPenalty"
v-model:max-token="agentForm.maxToken"
/>
<AgentResponseDepthControl v-model="agentForm.responseDepth" />
<el-form-item class="agent-stream-setting">
<div class="agent-stream-setting-copy">
<strong>流式输出</strong>

View File

@@ -0,0 +1,43 @@
<script setup lang="ts">
const props = defineProps<{
modelValue: number;
disabled?: boolean;
}>();
defineEmits<{
"update:modelValue": [value: number];
}>();
function depthLabel(value: number) {
if (value <= 33) return "精简";
if (value <= 66) return "平衡";
return "深入";
}
function depthCopy(value: number) {
if (value <= 33) return "少分析、短建议,优先回到当下和身体感受。";
if (value <= 66) return "保留必要解释,给出清楚但不过度展开的建议。";
return "允许更完整拆解,但仍保持回归自身、觉察和释放的方向。";
}
</script>
<template>
<el-form-item class="agent-response-depth">
<div class="agent-response-depth-head">
<div class="agent-stream-setting-copy">
<strong>回答深度</strong>
<span>{{ depthCopy(props.modelValue) }}</span>
</div>
<el-tag effect="plain">{{ depthLabel(props.modelValue) }} {{ props.modelValue }}</el-tag>
</div>
<el-slider
:model-value="props.modelValue"
:disabled="disabled"
:min="0"
:max="100"
:step="5"
:marks="{ 0: '精简', 50: '平衡', 100: '深入' }"
@update:model-value="$emit('update:modelValue', Number($event))"
/>
</el-form-item>
</template>

View File

@@ -19,6 +19,7 @@ import {
ElPagination,
ElProgress,
ElSelect,
ElSlider,
ElSwitch,
ElTabPane,
ElTable,
@@ -51,6 +52,7 @@ import "element-plus/theme-chalk/el-progress.css";
import "element-plus/theme-chalk/el-popper.css";
import "element-plus/theme-chalk/el-scrollbar.css";
import "element-plus/theme-chalk/el-select.css";
import "element-plus/theme-chalk/el-slider.css";
import "element-plus/theme-chalk/el-switch.css";
import "element-plus/theme-chalk/el-table.css";
import "element-plus/theme-chalk/el-tabs.css";
@@ -86,6 +88,7 @@ app.config.globalProperties.$ELEMENT = { locale: zhCn };
ElPagination,
ElProgress,
ElSelect,
ElSlider,
ElSwitch,
ElTabPane,
ElTable,

View File

@@ -1049,12 +1049,46 @@ textarea {
line-height: 1.6;
}
.agent-response-depth {
margin: 16px 0 0;
padding: 14px 16px 18px;
border: 1px solid #dce7e3;
border-radius: 8px;
background: #ffffff;
}
.agent-response-depth > .el-form-item__content {
display: grid;
gap: 14px;
}
.agent-response-depth-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
width: 100%;
}
.agent-response-depth .el-slider {
--el-slider-main-bg-color: #0f735d;
--el-slider-runway-bg-color: #dce7e3;
width: calc(100% - 12px);
margin: 2px 6px 0;
}
@media (max-width: 680px) {
.agent-stream-setting > .el-form-item__content {
align-items: flex-start;
flex-direction: column;
gap: 12px;
}
.agent-response-depth-head {
align-items: flex-start;
flex-direction: column;
gap: 10px;
}
}
.agent-parameter-label {

View File

@@ -139,6 +139,7 @@ export interface AgentGenerationConfig {
maxToken: number;
streamEnabled: number;
reasoningVisible: number;
responseDepth: number;
}
export interface AgentRuntimeConfig extends AgentGenerationConfig {