Overview
Routines are named, persistent, user-owned tasks that fire automatically based on triggers (cron schedules, events, webhooks, or manual invocation). Each routine has an action (lightweight LLM call or full job) and guardrails to prevent runaway execution.Architecture
Core Concepts
Routine Structure
Every routine has:- ID: Unique UUID
- Name: Human-readable identifier
- Description: What the routine does
- Trigger: When to fire (cron/event/webhook/manual)
- Action: What to execute (lightweight/full_job)
- Guardrails: Safety constraints (cooldown, concurrency, dedup)
- Notify Config: Where and when to send notifications
Triggers
Cron Trigger
Fires on a schedule:- Standard cron:
"0 9 * * MON-FRI" - Human-readable:
"every 2h","daily at 9am"
Event Trigger
Fires when a channel message matches a pattern:Webhook Trigger
Fires on incoming HTTP POST:https://your-domain.com/hooks/routine/{id}
Manual Trigger
Only fires via CLI or tool call:Actions
Lightweight Action
Single LLM call, no tools. Fast and cheap:- Load context files from workspace
- Send single LLM request with prompt + context
- Check response for
ROUTINE_OK(nothing to report) or content (attention needed) - Send notification based on status
Full Job Action
Multi-turn agent with full tool access:- Create a job via the scheduler
- Run full agent loop with tools
- Return when complete or max iterations reached
Guardrails
Prevents runaway execution:Notification Config
Creating Routines
Via CLI
Via Tool Call
The agent can create routines:Programmatic API
Runtime State
Routine State
Routines can maintain state across runs:workspace/routines/{name}/state.md.
Run History
Every execution creates aRoutineRun record:
Execution Engine
Cron Ticker
Polls the database every N seconds for due routines:Event Matcher
Called synchronously from the agent main loop:- Load event routines from cache
- Filter by channel (if specified)
- Match regex pattern against message content
- Check guardrails (cooldown, concurrency, dedup)
- Spawn execution in background task
Guardrail Checks
Cooldown
Concurrency
Deduplication
For event triggers, prevents firing on duplicate content:dedup_window duration.
Notifications
Routines send notifications based on status:Database Schema
Routines Table
Routine Runs Table
Configuration
Examples
Daily PR Summary
Deploy Webhook
Security Alert Monitor
Source Code
Key files:src/agent/routine.rs- Core types (Routine, Trigger, Action, Guardrails)src/agent/routine_engine.rs- Execution engine (cron ticker, event matcher)src/agent/scheduler.rs- Job scheduling for full_job actionsmigrations/- Database schema migrations