Skip to main content
Trinity
Guides/Scheduling

Scheduling

Cron-based automation for agents using APScheduler. Schedule recurring tasks with timezone support, execution history, and manual triggers.

Concepts

Schedule — A cron expression paired with a message or task sent to an agent at the specified times.
Execution — Each time a schedule fires, it creates an execution record with status, duration, response, cost, and model used.
Autonomy Mode — Master toggle that enables or disables all schedules for an agent. Schedules will not fire if autonomy is off.
Scheduler Service — Standalone service with Redis distributed locks. Uses async fire-and-forget dispatch with DB polling for status.
Misfire Handling — If the scheduler restarts, missed jobs within a 1-hour grace window are caught up and fired immediately (misfire_grace_time=3600, coalesce=True, max_instances=1).
Schedule lifecycle: Create (set cron, write prompt, enable) triggers Run (scheduler fires, agent executes, log result)

Creating Schedules

1

Open the agent detail page and go to the scheduling section.

2

Click Create Schedule.

3

Configure: name, cron expression (e.g., 0 9 * * 1-5 for weekdays at 9 AM), message/task, timezone, and description.

4

Optionally select a model override (Opus, Sonnet, Haiku, or custom).

5

Enable or disable individual schedules with the toggle.

6

View execution history with status, duration, and cost.

7

Click Run Now to trigger a schedule immediately.

Agent Schedules tab showing three active weekly schedules with cron expressions and execution history

Execution Flow

1

Scheduler fires and sends a POST to /api/internal/execute-task with async_mode=True.

2

Backend spawns a background task and returns immediately.

3

Scheduler polls the database every 10 seconds until execution completes.

4

Execution record is updated with response, cost, and duration.

Schedule API

EndpointMethodDescription
/api/agents/{name}/schedulesGETList schedules
/api/agents/{name}/schedulesPOSTCreate schedule
/api/agents/{name}/schedules/{id}GET/PUT/DELETECRUD operations
/api/agents/{name}/schedules/{id}/enablePOSTEnable schedule
/api/agents/{name}/schedules/{id}/triggerPOSTManual trigger
/api/agents/{name}/schedules/{id}/executionsGETExecution history

Skills and Playbooks

Platform-managed skills that can be assigned to agents and invoked from the UI via the Playbooks tab or chat autocomplete.

Key Concepts

Skill — A reusable capability defined as a markdown file (SKILL.md) stored in the platform's skills library.
Skills Library — A GitHub repository synced to Trinity containing all available skills. Admins can trigger a sync from Settings.
Playbook — A skill invoked from the UI. The Playbooks tab shows assigned skills with a “Run” button.
Playbook Autocomplete — Type / in the Chat tab to see available playbooks with ghost text showing command syntax.

Managing Skills (Admin)

1

Go to Settings or the Skills admin page.

2

Sync the skills library from GitHub.

3

Create, edit, or delete skills (full CRUD). View skill details and usage.

Assigning Skills (Owner)

Open the agent detail page, go to the skills/playbooks section, and assign skills from the library. Skills are injected on the next agent start.

Running Playbooks (User)

Open agent detail, click the Playbooks tab, and click Run on a playbook. Or type / in the Chat tab to autocomplete a playbook command.

Skill Injection on Agent Start

When an agent starts, all assigned skills are written to the agent's .claude/commands/ directory. The agent can then use them as slash commands during execution.

Playbooks tab showing assigned skills with Run buttons

Approvals

Human-in-the-loop approval gates for process engine workflows. Processes pause at approval steps and wait for human decisions before continuing.

1

A process execution reaches a human_approval step. The step pauses the process (status: PAUSED).

2

An approval request appears in the Approvals inbox (accessible from the navigation bar).

3

The approver sees the process name, step description, context, and who requested it.

4

The approver can Approve or Reject, with an optional comment.

5

On approval, the process continues. On rejection, the execution is cancelled or follows the rejection path. Approvals can have configurable timeouts.

A approval_required WebSocket event is fired when a process needs human approval.

Approval API

EndpointMethodDescription
/api/approvalsGETList pending approvals
/api/approvals/{id}GETGet approval details
/api/approvals/{id}/decidePOSTSubmit decision (approve/reject)

Automatic Retry

Failed executions can automatically retry with configurable delay and attempt limits.

Configuration

FieldDefaultRangeDescription
max_retries10-5Max retry attempts (0 = disabled)
retry_delay_seconds6030-600Delay between retries

Retry Behavior

1

Execution fails (error or timeout)

2

If max_retries > 0 and attempts remain, scheduler waits retry_delay_seconds

3

Rate-limit errors (429) use 2x delay, capped at 300 seconds

4

Retry creates a new execution record linked to the original

5

Process repeats until success or max retries exhausted

Execution Statuses

StatusMeaning
pending_retryFailed, retry scheduled but not yet fired
runningRetry in progress
success / failedFinal outcome

MCP Tools

ToolDescription
list_agent_schedules(name)List schedules
create_agent_schedule(name, ...)Create schedule
get_agent_schedule(name, id)Get schedule details
update_agent_schedule(name, id, ...)Update schedule
delete_agent_schedule(name, id)Delete schedule
toggle_agent_schedule(name, id)Enable or disable
trigger_agent_schedule(name, id)Manual trigger
get_schedule_executions(name, id)Execution history

Pre-Check Hook

An optional executable shipped by an agent template that gates each cron tick before Claude is invoked. When present, it lets the agent decide at runtime whether the scheduled work is actually needed — so empty polls (no new PRs, no new emails, no alerts) consume zero tokens.

How It Works

1

Template ships ~/.trinity/pre-check as an executable file with a shebang

2

Before each scheduled cron tick, Trinity runs the file inside the agent container

3

Scheduler acts on the output (see table below)

Pre-check resultScheduler action
No ~/.trinity/pre-check fileFire as usual (backward-compatible)
Exit 0, non-empty stdoutFire — stdout becomes the chat message (overrides schedule's configured message)
Exit 0, empty stdoutSkip — record a skipped execution row, no Claude invocation, zero cost
Exit non-zeroFail-open — log the error and fire with the original message
Timeout (>60s) or errorFail-open — fire with the original message

Key Behaviors

Language-agnostic — hook is exec'd directly; interpreter chosen by shebang
Manual triggers bypass the hook entirely — clicking “Run Now” always fires
Skipped executions appear in the execution list with status skipped, zero cost, and a reason string. They do not count against retry limits
Fail-open — a broken or slow hook never suppresses a scheduled invocation

For Template Authors

Place the hook at ~/.trinity/pre-check (no extension), make it executable (chmod +x), and include a shebang. The hook receives no arguments. Print a work description to stdout if there is work, or print nothing if there is nothing to do.

#!/usr/bin/env python3
import sys
# ... check for new items ...
if new_items:
    print(f"Review {len(new_items)} new PRs: {', '.join(new_items)}")
# else: exit 0 with empty stdout → Trinity records a skip

Per-Schedule Timeout

Each schedule has its own timeout_seconds. It cannot exceed the agent's execution_timeout_seconds cap:

Creating or updating a schedule with timeout_seconds > agent.execution_timeout_seconds returns 400 error=schedule_timeout_exceeds_agent_cap.
Lowering the agent cap below an active schedule's timeout returns 400 error=agent_timeout_below_active_schedules.

Raise the agent cap first, then raise the schedule timeout.

Limitations

Execution timeout is per-agent configurable (default 60 minutes, max 2 hours).
Parallel execution is controlled by per-agent capacity slots (default 3).
Missed jobs are only caught up within the 1-hour grace window.
Retries count against the agent's parallel capacity slots.
Pre-check hooks run with the same permissions as the agent's normal tool calls (developer user inside the container).