feat(gateway): 静默定时任务增加主动送达提示,避免结果静默丢失

silent_agent_task 的最终响应发往 scheduler/ 虚拟会话、被出站分发器跳过,成功时用户收不到任何消息,只能依赖 agent 主动调用 send_session_message。

- 定时任务系统提示词仅对 scheduler/ 虚拟会话追加送达提示(避免普通 agent_task 重复发送)

- scheduler_manage 工具描述新增 Silent Mode Delivery 指引:用户期望收到结果时,prompt 必须要求用 send_session_message 交付
This commit is contained in:
oudecheng 2026-08-15 18:17:07 +08:00
parent 508806a408
commit cbe2ff1339
2 changed files with 17 additions and 1 deletions

View File

@ -74,6 +74,11 @@ impl CompactionSink for CompactionSinkImpl {
const SCHEDULED_TASK_EXECUTION_SYSTEM_PROMPT: &str = "系统说明当前输入来自一次已经触发的定时任务执行。你现在需要执行任务内容本身而不是创建、修改、恢复、暂停或查询新的定时任务。除非当前任务内容明确要求管理调度器否则不要调用任何定时任务管理工具像“每小时”、“每天”、“cron”、“定时”等词只应视为任务背景不应再解释为新的建任务请求。";
/// 静默(后台)定时任务的送达提示:最终响应发往虚拟会话,不会自动推送给用户,
/// 必须显式调用 send_session_message 才能把结果送达用户会话。
/// 仅在 scheduler/ 虚拟会话silent_agent_task中追加避免普通 agent_task 重复发送。
const SCHEDULED_TASK_SILENT_DELIVERY_HINT: &str = "特别注意:本次定时任务运行在后台独立会话中,你的最终响应不会自动发送给用户。如果任务需要向用户交付结果或发出通知,必须主动调用 send_session_message 工具把内容发送到当前会话,否则用户不会收到任何消息。";
pub(crate) fn compose_scheduled_task_system_prompt(system_prompt: Option<&str>) -> String {
match system_prompt
.map(str::trim)
@ -497,8 +502,16 @@ impl AgentExecutionService {
session_guard.ensure_chat_loaded(request.chat_id, original_topic_id.as_deref())?;
session_guard.ensure_agent_prompt_before_user_message(request.chat_id)?;
let scheduled_system_prompt =
let mut scheduled_system_prompt =
compose_scheduled_task_system_prompt(request.system_prompt);
// 静默任务scheduler/ 虚拟会话)的最终响应不会送达用户,
// 提示 agent 必须用 send_session_message 主动交付结果
if is_scheduler_chat_id(request.chat_id) {
scheduled_system_prompt = format!(
"{}\n{}",
scheduled_system_prompt, SCHEDULED_TASK_SILENT_DELIVERY_HINT
);
}
session_guard.append_persisted_message(
request.chat_id,
original_topic_id.as_deref(),

View File

@ -41,6 +41,9 @@ impl Tool for SchedulerManageTool {
IMPORTANT - Default to Silent Mode: \
When users request scheduled tasks without explicitly specifying the mode, default to silent_agent_task instead of agent_task. Silent mode is preferred for most automated tasks because it runs in a dedicated background session without cluttering the main conversation. Only use agent_task when the user explicitly wants interactive execution in the main chat. \
\
IMPORTANT - Silent Mode Delivery: \
A silent_agent_task runs in a background session and its final response is NOT automatically sent to the user's conversation; only execution failures trigger a notification. Therefore, when the user expects to receive the task's result (a report, a status, an alert, etc.), the prompt MUST explicitly instruct the task to deliver its result by calling the send_session_message tool. Without this instruction the user will receive nothing on success. \
\
IMPORTANT - Target Configuration: \
For agent_task and silent_agent_task, the target.channel and target.chat_id determine where notifications are sent. \
- If target is omitted or fields are empty, they are automatically filled from the current conversation context. \