Back to Eliza

Triggers API

packages/docs/rest/triggers.md

2.0.16.5 KB
Original Source

Triggers schedule the agent to perform tasks automatically. They are backed by the elizaOS TaskService and support interval-based, cron-based, and one-shot scheduling. The agent must be running and triggers must be enabled in configuration.

<Info> Triggers are disabled by configuration in some deployments. Check `GET /api/triggers/health` to verify the trigger system is available. </Info>

Endpoints

GET /api/triggers/health

Get the trigger system health snapshot. This endpoint works even when triggers are disabled.

Response

json
{
  "triggersEnabled": true,
  "activeTriggers": 3,
  "disabledTriggers": 1,
  "totalExecutions": 42,
  "totalFailures": 2,
  "totalSkipped": 0
}

GET /api/triggers

List all triggers, sorted alphabetically by display name.

Response

json
{
  "triggers": [
    {
      "triggerId": "550e8400-e29b-41d4-a716-446655440000",
      "displayName": "Morning Check-in",
      "triggerType": "interval",
      "enabled": true,
      "intervalMs": 3600000,
      "instructions": "Post a morning update",
      "wakeMode": "inject_now",
      "createdBy": "api",
      "nextRunAtMs": 1718003600000,
      "lastRunAtMs": 1718000000000,
      "runCount": 5
    }
  ]
}

POST /api/triggers

Create a new trigger. Returns 429 if the active trigger limit for the creator is reached, and 409 if an equivalent trigger (same dedupe key) already exists.

Request

json
{
  "displayName": "Morning Check-in",
  "instructions": "Post a morning update about what you're working on",
  "triggerType": "interval",
  "intervalMs": 3600000,
  "wakeMode": "inject_now",
  "enabled": true,
  "createdBy": "api"
}
ParameterTypeRequiredDescription
kindstringNoTrigger kind: "text" (default) or "workflow". Workflow triggers require workflowId.
displayNamestringNoHuman-readable trigger name (default: "New Trigger")
instructionsstringNoInstructions for the agent when this trigger fires
triggerTypestringNo"interval", "cron", or "once" (default: "interval")
intervalMsnumberNoInterval in milliseconds (for triggerType: "interval")
cronExpressionstringNoCron expression (for triggerType: "cron")
scheduledAtIsostringNoISO 8601 datetime for one-shot triggers (for triggerType: "once")
maxRunsnumberNoMaximum number of times this trigger can fire
wakeModestringNo"inject_now" fires immediately (default), other modes defer
enabledbooleanNoWhether the trigger is active (default: true)
createdBystringNoCreator identifier for limit tracking (default: "api")
workflowIdstringNoworkflow ID (required when kind is "workflow")
workflowNamestringNoHuman-readable workflow name (for kind: "workflow")

Response (201 Created)

json
{
  "trigger": {
    "triggerId": "550e8400-e29b-41d4-a716-446655440000",
    "displayName": "Morning Check-in",
    "triggerType": "interval",
    "enabled": true,
    "intervalMs": 3600000,
    "nextRunAtMs": 1718003600000
  }
}

GET /api/triggers/:id

Get a trigger by its ID (trigger UUID or task UUID).

Path Parameters

ParameterTypeRequiredDescription
idstringYesTrigger ID or task ID

Response

json
{
  "trigger": {
    "triggerId": "550e8400-e29b-41d4-a716-446655440000",
    "displayName": "Morning Check-in",
    "triggerType": "interval",
    "enabled": true,
    "intervalMs": 3600000
  }
}

PUT /api/triggers/:id

Update a trigger. Fields not provided are preserved from the existing trigger. Changing schedule parameters recomputes nextRunAtMs.

Path Parameters

ParameterTypeRequiredDescription
idstringYesTrigger ID

Request

json
{
  "displayName": "Updated Morning Check-in",
  "intervalMs": 7200000,
  "enabled": true
}
ParameterTypeRequiredDescription
displayNamestringNoNew display name
instructionsstringNoNew instructions
intervalMsnumberNoNew interval in milliseconds
cronExpressionstringNoNew cron expression
scheduledAtIsostringNoNew one-shot datetime
maxRunsnumberNoNew maximum run count
enabledbooleanNoEnable or disable the trigger

Response

json
{
  "trigger": {
    "triggerId": "550e8400-e29b-41d4-a716-446655440000",
    "displayName": "Updated Morning Check-in",
    "enabled": true,
    "intervalMs": 7200000,
    "nextRunAtMs": 1718007200000
  }
}

DELETE /api/triggers/:id

Delete a trigger permanently.

Path Parameters

ParameterTypeRequiredDescription
idstringYesTrigger ID

Response

json
{
  "ok": true
}

POST /api/triggers/:id/execute

Manually execute a trigger immediately, regardless of its schedule.

Path Parameters

ParameterTypeRequiredDescription
idstringYesTrigger ID

Response

json
{
  "ok": true,
  "result": { "success": true },
  "trigger": {
    "triggerId": "550e8400-e29b-41d4-a716-446655440000",
    "runCount": 6,
    "lastRunAtMs": 1718001000000
  }
}

GET /api/triggers/:id/runs

Get the run history for a trigger.

Path Parameters

ParameterTypeRequiredDescription
idstringYesTrigger ID

Response

json
{
  "runs": [
    {
      "runId": "run-001",
      "startedAt": 1718000000000,
      "completedAt": 1718000005000,
      "success": true,
      "source": "scheduled"
    }
  ]
}

Common Error Codes

StatusCodeDescription
400INVALID_REQUESTRequest body is malformed or missing required fields
401UNAUTHORIZEDMissing or invalid authentication token
404NOT_FOUNDRequested resource does not exist
409TRIGGER_EXISTSA trigger with the same configuration already exists
429TRIGGER_LIMIT_REACHEDMaximum number of triggers for this creator has been reached
500TRIGGER_DISABLEDTrigger system is disabled in configuration
500INTERNAL_ERRORUnexpected server error