Skip to main content
Schedules

创建 Schedule

POST /api/v1/forward/schedules Schedule 绑定一个 Identity、一个 Template、初始事件、触发策略和执行策略。每次触发都会生成独立 Schedule Run。

请求头

Header是否必填说明
AuthorizationBearer <PAT 或 SAT>
Content-Typeapplication/json
Idempotency-Key有副作用请求可选的幂等键。

请求体参数

参数类型是否必填说明
identity_idstringSchedule 所属 Forward Identity ID。
template_idstring要执行的 Forward Template ID。
namestringSchedule 名称。
descriptionstringSchedule 描述。
initial_eventsarray每次执行注入的初始事件,当前支持 user.message
executionobject执行策略;省略时使用服务端默认值。
trigger_policyobject |null触发策略;省略或 null 时按 manual 处理。
environment_idstring执行环境。
sinksarray |null执行结果推送目标;为兼容性保留数组形式,当前最多允许一个元素。
metadataobject业务元数据,仅用于标签或透传。

触发策略

trigger_policy 是按 type 分发的对象。创建和更新请求只接收配置字段:typeexpressiontimezoneupcoming_runs_atlast_run_at 是服务端计算出的响应字段。
字段类型是否必填说明
typestringcrononceintervalmanual
expressionstring条件必填触发表达式;crononceinterval 必填,manual 不需要。
timezonestring条件必填IANA timezone,例如 Asia/Shanghaicron 必填,once 在表达式不带时区时必填,intervalmanual 可省略。
upcoming_runs_atarray响应返回后续触发时间,UTC ISO 8601。当前实现返回 [] 或最多一个下一次计划触发时间。
last_run_atstring |null响应返回最近一次触发时间。
type创建/更新入参说明
crontypeexpressiontimezone使用 5 字段 cron 表达式按指定 IANA timezone 重复触发。
oncetypeexpression、可选 timezone按 ISO 8601 时间触发一次;表达式不带 offset 时必须提供 timezone
intervaltypeexpression按 ISO 8601 duration 重复触发,例如 PT15M
manualtype不自动触发,只能通过 Run Schedule 接口手动执行。
typeexpression 格式示例说明
cron标准 5 字段 cron0 9 * * *分钟级日历规则;不支持秒字段和 6 字段 cron。
onceISO 8601 绝对时间2026-06-23T09:00:002026-06-23T01:00:00Z目标时间必须至少晚于服务端当前时间 1 分钟。
intervalISO 8601 durationPT15MPT1HP1D固定间隔触发,最小粒度 1 分钟。
manual省略或空字符串-不产生计划触发时间。

执行策略

字段类型默认值说明
session_modestringnew_sessionSession 使用方式,取值 new_sessionreuse_session
max_concurrent_runsinteger1同一个 Schedule 最大并发 Run 数。
max_attemptsinteger1单个 Run 的实际尝试次数上限,允许值为 12;小于 1 或大于 2 会被拒绝。
timeout_msinteger300000单次尝试超时时间。
session_mode说明
new_session每次触发都创建新的执行 Session,不延续历史上下文。
reuse_sessionForward 为该 Schedule 管理一个固定执行 Session,并在多次触发间持续使用;调用方不能指定任意已有 session_id
max_attempts=2 表示同一个 Schedule Run 在首次执行失败后,最多由服务端自动再尝试一次。是否重试由服务端根据失败类型判断;参数错误、权限错误、并发限制、超时或连接中断等场景不会保证重试。客户端可通过 Schedule Run 的 attempt 字段查看实际执行到第几次。 创建时省略 execution.max_attempts 使用默认值 1;显式传入时只接受整数 12

推送目标

sinks 为兼容性保留数组形式。省略、传入 null[] 都会创建不带推送目标的 Schedule;传入一个有效元素会配置投递;传入两个或更多元素会返回 HTTP 400 unsupported_sinks_input。每个元素只能是以下公开格式之一:
{
  "type": "im_channel",
  "channel_id": "channel_xxx",
  "target": {
    "type": "user",
    "external_id": "536769"
  }
}
{
  "type": "im_channel",
  "channel_id": "channel_xxx",
  "target": {
    "type": "group",
    "external_id": "cid_group_123"
  }
}
Channel 必须属于 PAT 用户,且使用 identity_resolution.mode=fixed、已启用并绑定,并与 Schedule 的 Identity 和 Template 匹配。 external_id 是渠道原生的、不可透视的用户或群组 ID,创建时不会探测其可达性。target.type=group 仅支持根群组,不支持 thread 或 topic。 在渠道 IM 会话中发送 /target,可获取当前会话的 target 配置。 运行时的投递可达性错误会记录在对应 Run 的 push_status=failed,不会改变 Agent Run 状态。

示例请求

curl -s -X POST 'https://api.qoder.com.cn/api/v1/forward/schedules' \
  -H "Authorization: Bearer $QODER_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "identity_id": "idn_019eabc123",
  "template_id": "tmpl_support",
  "name": "Daily tech brief",
  "description": "Generate a daily technology news summary",
  "initial_events": [
    {
      "type": "user.message",
      "content": "Summarize current technology news in five bullet points."
    }
  ],
  "trigger_policy": {
    "type": "cron",
    "expression": "0 9 * * *",
    "timezone": "Asia/Shanghai"
  },
  "execution": {
    "session_mode": "new_session",
    "max_concurrent_runs": 1,
    "max_attempts": 2,
    "timeout_ms": 300000
  },
  "environment_id": "env_019e64e01a137caf953ac2ac7b42ec5c",
  "sinks": [
    {
      "type": "im_channel",
      "channel_id": "channel_xxx",
      "target": {
        "type": "user",
        "external_id": "536769"
      }
    }
  ]
}'

示例响应

HTTP 200 OK
{
  "id": "sched_019f00112233445566778899aabbccdd",
  "identity_id": "idn_019eabc123",
  "template_id": "tmpl_support",
  "name": "Daily tech brief",
  "description": "Generate a daily technology news summary",
  "status": "active",
  "initial_events": [
    {
      "type": "user.message",
      "content": "Summarize current technology news in five bullet points."
    }
  ],
  "execution": {
    "session_mode": "new_session",
    "max_concurrent_runs": 1,
    "max_attempts": 2,
    "timeout_ms": 300000
  },
  "trigger_policy": {
    "type": "cron",
    "expression": "0 9 * * *",
    "timezone": "Asia/Shanghai",
    "upcoming_runs_at": [
      "2026-06-23T01:00:00Z"
    ]
  },
  "environment_id": "env_019e64e01a137caf953ac2ac7b42ec5c",
  "sinks": [
    {
      "type": "im_channel",
      "channel_id": "channel_xxx",
      "target": {
        "type": "user",
        "external_id": "536769"
      }
    }
  ],
  "metadata": {},
  "created_at": "2026-06-22T10:00:00Z",
  "updated_at": "2026-06-22T10:00:00Z"
}

响应字段

字段类型说明
返回值object创建后的完整 Schedule 对象。

错误

HTTPTypeCode触发条件
400invalid_request_errorinvalid_trigger_policy触发策略类型或表达式不合法。
400invalid_request_errortrigger_policy_too_frequent触发粒度小于 1 分钟。
400invalid_request_errortrigger_policy_time_too_soononce 目标时间过近。
400invalid_request_errorinvalid_requestexecution.max_attempts 不在 1..2 范围内。
400invalid_request_errorunsupported_sinks_inputsinks 数量、类型或字段非法,或固定 Channel 不可用、归属不符或执行上下文不匹配。
404not_found_erroridentity_not_foundIdentity 不存在。
404not_found_errortemplate_not_foundTemplate 不存在。
401authentication_errorauthentication_requiredPAT 或 SAT 无效或已过期。

备注

  • 省略 sinks、传入 null[] 时,创建的 Schedule 都返回 sinks: []
  • manual Schedule 只能通过 Run Schedule 接口触发。
  • once Schedule 的首次计划 Run 进入终态后会自动归档。

相关