Automations API
Create and manage scheduled agent prompts; inspect per-run Pocket relay usage.
Base path: /api/scheduled-tasks. All routes require a valid X-Agent-Access-Tokenfor the task's agent. List requires a query agent_id.
OpenAPI tag
scheduled-tasks tag. The product UI labels them Automations./api/scheduled-tasksX-Agent-Access-TokenCreate an automation. Returns the full row including id and next_run_at.
{
"agent_id": "uuid",
"prompt": "string (1–2000 chars)",
"interval_seconds": 3600
}Constraints: interval_seconds ∈ [60, 604800]. New jobs start with enabled=1 and next_run_at = now + interval.
/api/scheduled-tasks?agent_id={id}X-Agent-Access-TokenList automations for one agent, newest first. agent_id is required.
/api/scheduled-tasks/{id}X-Agent-Access-TokenFetch one automation. 404 if missing or token does not own the agent.
/api/scheduled-tasks/{id}X-Agent-Access-TokenPartial update: enabled, prompt, and/or interval_seconds.
{
"enabled": false,
"prompt": "optional new prompt",
"interval_seconds": 900
}Changing interval_seconds resets next_run_at to now + new interval.
/api/scheduled-tasks/{id}X-Agent-Access-TokenDelete automation (204). Cascades scheduled_task_runs rows when FK is enforced.
/api/scheduled-tasks/{id}/relay-statsX-Agent-Access-TokenLast up to 10 runs with per-run relay_count, success flag, and aggregates.
{
"total_relays_last_10_runs": 2,
"avg_relays_per_run": 1.0,
"runs": [
{
"started_at": 1710000000,
"finished_at": 1710000012,
"relay_count": 1,
"success": true
}
]
}Scheduler behavior
- Background loop in
services/scheduler.py - ~30s poll; runs due rows with
enabled=1 - Each run calls
AIAgentService.chat(message=prompt, …) - Updates
last_result/last_error,last_run_at,next_run_at,run_count