Scheduled AI tasks
Bind a natural-language question + persona playbook to a schedule + delivery channel. Server ticks every 60s, runs the same BYOK plan-and-ground path /api/ai/chat uses, delivers via Slack.
What scheduled AI tasks are
A scheduled AI task binds a natural-language prompt + a persona playbook to a schedule + a delivery destination. It answers the “send me weekly ARR every Monday to Slack” use case, grounded through the semantic layer instead of a hand-written SQL string.
The schedule grammar matches the one Goni pipelines use (interval, 5-field cron, @-descriptors, CRON_TZ-prefixed cron, Quartz L). A background sweeper ticks every 60s, enumerates due tasks across every tenant, runs each one through the same plan-and-ground path /api/ai/chat uses, formats the response, and posts it to the delivery destination.
Endpoints on this page
GET /api/ai/tasks- tenant-scoped listGET /api/ai/tasks/{id}- single fetch (cross-tenant probe returns 404)POST /api/ai/tasks- createPUT /api/ai/tasks/{id}- update (secret preserved on redacted round-trip)DELETE /api/ai/tasks/{id}- deletePOST /api/ai/tasks/{id}/run-now- force-fire once, ignoring schedule
REST endpoints
| Method | Path | Auth | Response |
|---|---|---|---|
| GET | /api/ai/tasks | Session or JWT + allow_save | {tasks: [...], count} |
| GET | /api/ai/tasks/{id} | Session or JWT + allow_save | task object or 404 |
| POST | /api/ai/tasks | Session or JWT + allow_save | 201 + task object |
| PUT | /api/ai/tasks/{id} | Session or JWT + allow_save | 200 + task object |
| DELETE | /api/ai/tasks/{id} | Session or JWT + allow_save | {deleted: id} |
| POST | /api/ai/tasks/{id}/run-now | Session or JWT + allow_save | {task_id, status, detail} |
Every mutation gates on AllowSave (editor role). A scheduled task can page an on-call rotation or spend the tenant’s BYOK LLM budget, both editor-level concerns.
Scheduled task shape
Wire shape (JSON, redacted on reads):
{
"id": "at-9c1f0b2e4d80",
"tenant_id": "acme",
"owner": "analyst@example.com",
"name": "Weekly ARR to #metrics",
"playbook_id": "data-analyst",
"question": "Give me weekly active_arr by country",
"schedule": "CRON_TZ=Europe/Berlin 0 9 * * MON",
"enabled": true,
"delivery_channel": "slack_webhook",
"delivery_target": "https://hooks.slack.com/services/T000/B000/xxx",
"delivery_secret": "***",
"created_at": "2026-08-18T09:12:04Z",
"updated_at": "2026-08-18T09:12:04Z",
"last_run_at": "2026-08-18T09:12:34Z",
"last_run_status": "ok",
"last_run_detail": "*Weekly ARR to #metrics*\nQuestion: Give me weekly active_arr by country\nMetric: `active_arr`\nBy: country\nGrain: week\n"
}
Field notes:
idserver-minted,at-prefix + 12 hex chars.owneris the JWT-authenticated user who created the task; used as the audit-loguserattribution on every dispatch.playbook_idempty picks the registry default (data-analyst). Anmcp_onlyplaybook is refused at dispatch time (scheduled tasks emit text summaries; onlyscope: chatplaybooks are eligible).schedulegrammar reference below.enabled: falsepauses dispatch without deleting the task.delivery_channelisslack_webhook.delivery_targetis the destination Slack incoming-webhook URL.delivery_secretis an optional HMAC-SHA256 key for signed webhook bodies. Reads always redact it to"***"; PUT preserves the on-disk value when the request body omitsdelivery_secretor sends it empty, so a redacted round-trip cannot silently wipe the key.last_run_at | last_run_status | last_run_detailare stamped after every dispatch, scheduled or run-now.last_run_statusis one ofok | clarify | error | skipped;last_run_detailis truncated at 4000 chars so a monster LLM response or CH stack trace does not bloat the YAML.
Schedule grammar
schedule accepts the same shapes Goni pipelines accept. It is validated at PUT/POST time so a typo cannot land silently on disk and no-op every tick. Alerts and scheduled reports use a simpler interval-only grammar (see Alerts and scheduled reports).
| Shape | Example | Meaning |
|---|---|---|
| Interval | 5m, 15m, 1h, 6h, 1d | Fires every N units |
| Cron (5-field) | 30 2 * * * | Airflow-style, UTC by default |
Cron @-descriptor | @daily, @hourly, @every 5m | Standard crontab macros |
| Cron with timezone | CRON_TZ=Europe/Berlin 0 9 * * MON-FRI | IANA zone name |
Quartz L / L-N | 0 23 L * * | Last day of month at 23:00 |
@reboot is rejected. Quartz W and # are not implemented. See Pipelines: Schedule grammar for the full reference and the /api/schedule/preview endpoint.
Delivery channels
| Channel | delivery_target |
|---|---|
slack_webhook | Slack incoming-webhook URL |
slack_webhook formats the LLM response as a short Slack-friendly text block (name, question, grounded metric, dimensions, time grain, optional filters, explanation) and POSTs it via the same signed-delivery path pipelines use. The same SSRF guard, shared HTTP client, and HMAC signing apply verbatim, so private-IP or metadata-endpoint URLs are refused the same way.
Scheduler cadence
One leader-elected sweeper, 60s tick, per-task 90s dispatch timeout.
Per tick:
- The sweeper reads every scheduled-task YAML file across every tenant.
- For each
enabledtask, the shared schedule parser plus adue-atcheck againstlast_run_atdecides due-ness. - Each due task is dispatched sequentially. The dispatch mirrors
/api/ai/chatend-to-end: the tenant’s BYOK API key is decrypted, the hourly token budget is checked (and the tick is skipped if the window is exhausted), the playbook is resolved (unknown id ormcp_onlyscope refuses), the catalog is built from the compiled semantic project, and the plan runs under the same 0.2 temperature the chat handler uses. - The rendered text summary is delivered to the configured channel.
last_run_at | last_run_status | last_run_detailare written back to the YAML file atomically (temp write + rename).- The audit log records
action=ai.task.runwith anoriginderived from the playbook id, so/auditgroups scheduled dispatches under the sameai:<playbook>bucket as their interactive-chat siblings.
Because the scheduler holds no state across restarts, a process bounce resumes without duplication: the on-disk last_run_at timestamp is the durable cadence anchor.
Sequential per-task dispatch (not fan-out) is deliberate. A 60s tick with one-at-a-time dispatch caps throughput at roughly one call per second in the worst case, well under any BYOK provider’s default rate limit.
The fresh-task-fires-first-tick invariant
A newly-created task has last_run_at IS NULL. The shared due-at check treats a zero anchor as “due now”, so a fresh task fires on the very first sweeper pass after creation instead of sitting idle for one full cron period. This matches pipeline, alert, and report “never ran = due now” convention, and it is pinned by a CI test so a regression that silently delays every new task by one full period fails at build time.
Force-fire with run-now
POST /api/ai/tasks/{id}/run-now dispatches the task once, ignoring the schedule. Useful for verifying the delivery destination without waiting for the next cron boundary. Runs synchronously so the response body carries the outcome, and records it on the task like a scheduled run:
{
"task_id": "at-9c1f0b2e4d80",
"status": "ok",
"detail": "*Weekly ARR to #metrics*\nQuestion: Give me weekly active_arr by country\nMetric: `active_arr`\n..."
}
Same auth (allow_save), same audit-log row as a scheduled dispatch, with trigger: "manual" in the detail payload.
End-to-end example
Create a task that fires every Monday at 09:00 Berlin time to a Slack channel:
curl -sS -X POST https://your-goni-host/api/ai/tasks \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GONI_PAT" \
-d '{
"name": "Weekly ARR to #metrics",
"playbook_id": "data-analyst",
"question": "Give me weekly active_arr by country",
"schedule": "CRON_TZ=Europe/Berlin 0 9 * * MON",
"enabled": true,
"delivery_channel": "slack_webhook",
"delivery_target": "https://hooks.slack.com/services/T000/B000/xxx"
}'
Fetch it a minute later to confirm the first tick populated last_run_*:
curl -sS https://your-goni-host/api/ai/tasks/at-9c1f0b2e4d80 \
-H "Authorization: Bearer $GONI_PAT"
Force a delivery for testing without waiting for the next cron window:
curl -sS -X POST https://your-goni-host/api/ai/tasks/at-9c1f0b2e4d80/run-now \
-H "Authorization: Bearer $GONI_PAT"
RBAC and audit
Every mutation gates on AllowSave (editor role). Scheduled tasks page on-call rotations and spend BYOK budget, so a viewer session cannot create, edit, delete, or run-now a task.
Every dispatch appends an audit row with action=ai.task.run and origin=ai:<persona> (for example ai:data-analyst, ai:data-engineer, ai:data-architect, ai:diagnostic). Filtering the /audit UI by origin=ai:* therefore surfaces both scheduled dispatches and their interactive-chat siblings in one bucket. See Audit and lineage.
BYOK token budget interaction
Each dispatch consumes tokens against the tenant’s hourly BYOK budget, the same window /api/ai/chat and /api/ask use. When the budget is exhausted, the sweeper stamps last_run_status: "skipped" with a detail like hourly token budget exhausted - resets in 42m0s and moves on. Nothing is delivered.
A task on 5m cadence spending against a starter plan (200,000 tokens/hr) will run roughly 288 dispatches per day. Before scheduling aggressive cadences, peek the current window with:
curl -sS https://your-goni-host/api/ai/budget \
-H "Authorization: Bearer $GONI_PAT"
See Ask: per-tenant hourly token budget for plan tiers and reset semantics.
Related
- Ask: grounded AI Q&A - the interactive-chat counterpart to scheduled dispatch
- Persona playbooks - which playbooks are eligible (
scope: chat) and which are refused (scope: mcp_only) - Pipelines - the shared
ScheduleSpecgrammar and/api/schedule/previewendpoint - Alerts and scheduled reports - metric-threshold alerts and dashboard-snapshot reports on the same scheduler grammar
- REST API reference - the full endpoint index
Last updated