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. \