From cbe2ff13393436744a55acab2b1eef7f6244a91e Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Sat, 15 Aug 2026 18:17:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(gateway):=20=E9=9D=99=E9=BB=98=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=E5=A2=9E=E5=8A=A0=E4=B8=BB=E5=8A=A8?= =?UTF-8?q?=E9=80=81=E8=BE=BE=E6=8F=90=E7=A4=BA=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E9=9D=99=E9=BB=98=E4=B8=A2=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit silent_agent_task 的最终响应发往 scheduler/ 虚拟会话、被出站分发器跳过,成功时用户收不到任何消息,只能依赖 agent 主动调用 send_session_message。 - 定时任务系统提示词仅对 scheduler/ 虚拟会话追加送达提示(避免普通 agent_task 重复发送) - scheduler_manage 工具描述新增 Silent Mode Delivery 指引:用户期望收到结果时,prompt 必须要求用 send_session_message 交付 --- src/gateway/execution.rs | 15 ++++++++++++++- src/tools/scheduler_manage.rs | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/gateway/execution.rs b/src/gateway/execution.rs index 35b9b85..c8d8155 100644 --- a/src/gateway/execution.rs +++ b/src/gateway/execution.rs @@ -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(), diff --git a/src/tools/scheduler_manage.rs b/src/tools/scheduler_manage.rs index de416f0..4141621 100644 --- a/src/tools/scheduler_manage.rs +++ b/src/tools/scheduler_manage.rs @@ -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. \