refactor(chatbot): 更新提示词和待办事项中间件,简化系统提示构建

This commit is contained in:
Wenjie Zhang 2026-04-06 12:09:22 +08:00
parent 66340c7227
commit 6809f67f70
6 changed files with 23 additions and 16 deletions

View File

@ -16,7 +16,7 @@ from yuxi.agents.middlewares.skills_middleware import SkillsMiddleware
from yuxi.services.mcp_service import get_tools_from_all_servers
from yuxi.services.subagent_service import get_subagents_from_names
from .prompt import PROMPT
from .prompt import TODO_MID_PROMPT, build_prompt_with_context
async def _build_middlewares(context):
@ -54,7 +54,7 @@ async def _build_middlewares(context):
SkillsMiddleware(), # Skills 中间件(提示词注入、依赖展开、动态激活)
subagents_middleware,
summary_middleware,
TodoListMiddleware(system_prompt="任务结束前,应该检查维护的待办事项列表是否结束。"),
TodoListMiddleware(system_prompt=TODO_MID_PROMPT), # 待办事项中间件
PatchToolCallsMiddleware(),
ModelRetryMiddleware(), # 模型重试中间件
]
@ -82,12 +82,10 @@ class ChatbotAgent(BaseAgent):
context = context or self.context_schema() # 获取上下文配置
system_prompt = f"{PROMPT.strip()}\n\n{context.system_prompt or ''}"
# 使用 create_agent 创建智能体
graph = create_agent(
model=load_chat_model(fully_specified_name=context.model),
system_prompt=system_prompt.strip(),
system_prompt=build_prompt_with_context(context),
middleware=await _build_middlewares(context),
state_schema=BaseState,
checkpointer=await self._get_checkpointer(),

View File

@ -7,9 +7,12 @@ from yuxi.utils.paths import (
)
PROMPT = f"""
你是一个人工智能助手 语析专门用来回答用户的问题请根据用户提供的信息尽可能详细地回答问题
你是一个交互式智能体语析
专门用来回答用户的问题请根据用户提供的信息尽可能详细地回答问题
如果你不确定答案可以说你不知道但请尽量提供相关的信息或建议请保持礼貌和专业
<| 文件系统约束 |>
系统主要工作路径为 {VIRTUAL_PATH_PREFIX}但必须遵守规范
- {VIRTUAL_PATH_WORKSPACE}用于存放工作文件用户目录不要轻易写入
- {VIRTUAL_PATH_OUTPUTS}用于写入的文件夹
@ -18,10 +21,17 @@ PROMPT = f"""
非必要不写入其他路径
如果启用了知识库除了使用知识库工具之外
需要精准获取信息的时候或者 query_kb 中没有找到相关的内容还可以直接访问知识库文件系统
<| 知识库访问 |>
query_kb 中没有找到相关的内容或者需要进一步基于检索到的内容获取更加详细的上下文的时候还可以直接访问知识库文件系统
路径为 {VIRTUAL_KBS_PATH}来获取信息
源文件可能无法解析可以在 {VIRTUAL_KBS_PATH}/<db_name>/parsed/ 中找到解析后的 markdown 文件
源文件可能无法直接读取可以在 {VIRTUAL_KBS_PATH}/<db_name>/parsed/ 中找到解析后的 markdown 文件
"""
TODO_MID_PROMPT = """
你需要根据任务的复杂程度来使用 write_todos 来记录规划和待办事项确保任务的每个步骤都被记录和跟踪
"""
def build_prompt_with_context(context):
system_prompt = f"{PROMPT.strip()}\n\n{context.system_prompt or ''}"
return system_prompt.strip()

View File

@ -180,6 +180,7 @@ def to_camel_case(s: str) -> str:
s = s[0].lower() + s[1:]
return s
async def _load_enabled_mcp_server_configs(
*,
names: list[str] | None = None,

View File

@ -77,5 +77,5 @@ async function exchangeOIDCCode(code) {
export const authApi = {
getOIDCConfig,
getOIDCLoginUrl,
exchangeOIDCCode,
exchangeOIDCCode
}

View File

@ -332,7 +332,7 @@ const healthChecking = ref(false)
// OIDC
const oidcEnabled = ref(false)
const oidcLoading = ref(false)
const oidcChecking = ref(true)
const oidcChecking = ref(true)
const oidcButtonText = ref('OIDC 登录')
//
@ -513,7 +513,8 @@ const handleOIDCLogin = async () => {
const response = await authApi.getOIDCLoginUrl()
if (response.login_url) {
// 便
const redirectPath = sessionStorage.getItem('redirect') || router.currentRoute.value.query.redirect || '/'
const redirectPath =
sessionStorage.getItem('redirect') || router.currentRoute.value.query.redirect || '/'
sessionStorage.setItem('oidc_redirect', redirectPath)
// OIDC Provider

View File

@ -9,9 +9,7 @@
<div v-else-if="error" class="error-section">
<a-result status="error" :title="errorTitle" :sub-title="errorMessage">
<template #extra>
<a-button type="primary" @click="goToLogin">
返回登录页
</a-button>
<a-button type="primary" @click="goToLogin"> 返回登录页 </a-button>
</template>
</a-result>
</div>
@ -107,7 +105,6 @@ const handleCallback = async () => {
router.push(redirectPath)
}
}, 500)
} catch (err) {
console.error('OIDC 回调处理失败:', err)
loading.value = false