Skip to content

Automations

xopc automations are durable, product-level rules stored in SQLite (~/.xopc/xopc.db). An automation combines one trigger with one action, records every run, and can execute either an agent instruction or a workflow.

Use the Gateway console at #/automations to create, pause, resume, run, delete, and inspect automations. The page keeps creation in a centered modal and shows upcoming runs, recent history, and operational metrics in one place.

Concepts

ConceptMeaning
TriggerHow the automation starts: manual, schedule, or webhook
ActionWhat runs: agent instruction or workflow
RunOne execution attempt with status, timestamps, summary, and errors
After-runOptional post-run behavior such as saving to session or posting a webhook
ReliabilityTimeout, retry, concurrency, and failure-disable settings

Triggers

Scheduled automations support one-time, interval, and cron-expression schedules:

ts
type AutomationSchedule =
  | { kind: 'once'; at: string }
  | { kind: 'interval'; everyMs: number; anchorMs?: number }
  | { kind: 'cron'; expr: string; tz?: string };

type AutomationTrigger =
  | { kind: 'manual' }
  | { kind: 'schedule'; schedule: AutomationSchedule }
  | { kind: 'webhook'; secretId?: string };

Use once for exact one-time reminders, interval for fixed-frequency monitoring, and cron for calendar schedules. Put tz on each cron-expression schedule that depends on a human local time.

Actions

Automations intentionally have a small action surface:

ts
type AutomationAction =
  | {
      kind: 'agent';
      agentId?: string;
      instruction: string;
      workingDirectory?: string;
      model?: string;
      timeoutSeconds?: number;
    }
  | {
      kind: 'workflow';
      workflowId: string;
      agentId?: string;
      input?: unknown;
      goal?: string;
      timeoutSeconds?: number;
    };

Choose an agent action when the automation should ask an agent to do work in a session. Choose a workflow action when the job should call a known workflow directly without relying on a model to decide the invocation.

Data Model

Runtime state is stored on the automation row:

ts
type AutomationState = {
  nextRunAtMs?: number;
  runningRunId?: string;
  lastRunAtMs?: number;
  lastRunStatus?: 'queued' | 'running' | 'succeeded' | 'failed' | 'cancelled' | 'timeout';
  lastError?: string;
  consecutiveFailures?: number;
};

SQLite tables:

TablePurpose
automationsAutomation definitions, triggers, actions, reliability, after-run behavior, and state
automation_runsExecution history and outcomes

Automations are database-backed. They are not configured through xopc.json.

Scheduler Behavior

  • On startup, scheduled automations recompute nextRunAtMs.
  • Manual and webhook automations only run when explicitly invoked.
  • Running automations are tracked through state.runningRunId.
  • Runs write status, timing, summaries, errors, session keys, and workflow run ids to SQLite.
  • The service exposes history through the Gateway console and API.

Gateway API

Create:

http
POST /api/automations
Content-Type: application/json

{
  "name": "Daily review",
  "trigger": {
    "kind": "schedule",
    "schedule": { "kind": "cron", "expr": "0 9 * * 1-5", "tz": "Asia/Shanghai" }
  },
  "action": {
    "kind": "agent",
    "instruction": "Summarize yesterday and plan today."
  },
  "afterRun": { "kind": "saveToSession" },
  "reliability": { "timeoutSeconds": 1800, "retryCount": 1 }
}

Common endpoints:

MethodPathPurpose
GET/api/automationsList automations
POST/api/automationsCreate automation
GET/api/automations/metricsRead automation metrics
GET/api/automations/:idRead one automation
PATCH/api/automations/:idUpdate automation
DELETE/api/automations/:idDelete automation
POST/api/automations/:id/runRun now
POST/api/automations/:id/pausePause automation
POST/api/automations/:id/resumeResume automation
GET/api/automation-runsList runs
GET/api/automation-runs/:runIdRead one run
POST/api/automation-runs/:runId/cancelCancel a run

Agent Tool

When the gateway runtime exposes the automation service, agents can use the automation tool to list, create, update, delete, run, pause, resume, and inspect history. The tool uses the same structured payloads as the API.

Released under the MIT License.