Files
chatgpt-on-wechat/docs/tools/scheduler.mdx
zhayujie aea081703f fix(scheduler): inject delivered output into receiver session with sliding window
Further refinements on top of #2795:

- persist real session_id (notify_session_id) at task creation so group chats
  correctly map back to the user's actual conversation
- mark scheduler turns with [SCHEDULED] (recognise legacy "Scheduled task"
  prefix too for backward-compatible pruning)
- prune both DB and in-memory to scheduler_inject_max_per_session (default 3),
  only marker-tagged pairs are touched; regular user turns never deleted
- send_message type gated by scheduler_inject_send_message (default false) —
  fixed reminder text rarely benefits follow-up Q&A

Co-authored-by: huangrichao2020 <grdomai43881@gmail.com>
2026-05-03 21:27:24 +08:00

71 lines
2.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: scheduler - 定时任务
description: 创建和管理定时任务
---
创建和管理动态定时任务,支持灵活的调度方式和执行模式。
## 依赖
| 依赖 | 安装命令 |
| --- | --- |
| `croniter` ≥ 2.0.0 | `pip install croniter>=2.0.0` |
安装核心依赖时已包含:`pip3 install -r requirements.txt`
## 调度方式
| 方式 | 说明 |
| --- | --- |
| 一次性任务 | 在指定时间执行一次 |
| 固定间隔 | 按固定时间间隔重复执行 |
| Cron 表达式 | 使用 Cron 语法定义复杂调度规则 |
## 执行模式
- **固定消息发送**:到达触发时间时发送预设消息
- **Agent 动态任务**:到达触发时间时由 Agent 智能执行任务
## 使用方式
通过自然语言即可创建和管理定时任务:
- "每天早上 9 点给我发天气预报"
- "每隔 2 小时检查一下服务器状态"
- "明天下午 3 点提醒我开会"
- "查看所有定时任务"
<Frame>
<img src="https://cdn.link-ai.tech/doc/20260202195402.png" width="800" />
</Frame>
## 结果进入会话上下文
定时任务在隔离 session 中执行(内部规划与 tool 调用不污染用户会话),但**最终输出**会作为一对消息回写到接收者的真实会话,用户可以直接追问"刚才那条第二点展开说说"。
**默认策略**
- Agent 动态任务的输出进入上下文
- 固定消息类任务默认不进入上下文(可通过配置打开)
- 每个会话最多保留最近 **3 对** scheduler 消息,更早的自动清理;普通用户消息不受影响
**配置项**
| 配置项 | 默认值 | 说明 |
| --- | --- | --- |
| `scheduler_inject_to_session` | `true` | 总开关 |
| `scheduler_inject_max_per_session` | `3` | 每会话保留 scheduler 消息对数上限 |
| `scheduler_inject_send_message` | `false` | 是否同时注入固定消息类任务 |
```json
{
"scheduler_inject_to_session": true,
"scheduler_inject_max_per_session": 3,
"scheduler_inject_send_message": false
}
```
<Note>
群聊场景(飞书 / 企微群机器人 / 钉钉等)下用户的真实 session_id 形如 `user_id:group_id`,与 receiver 不同。创建任务时会自动记录正确的 session_id老的 `tasks.json` 缺该字段时回落到 receiver行为与历史版本一致。
</Note>