Skip to main content

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:
Supported formats:
  • 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:
Webhook URL: 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:
Execution:
  1. Load context files from workspace
  2. Send single LLM request with prompt + context
  3. Check response for ROUTINE_OK (nothing to report) or content (attention needed)
  4. Send notification based on status

Full Job Action

Multi-turn agent with full tool access:
Execution:
  1. Create a job via the scheduler
  2. Run full agent loop with tools
  3. 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:
State files are stored in workspace/routines/{name}/state.md.

Run History

Every execution creates a RoutineRun record:
Query run history:

Execution Engine

Cron Ticker

Polls the database every N seconds for due routines:
Default interval: 30 seconds

Event Matcher

Called synchronously from the agent main loop:
Matching process:
  1. Load event routines from cache
  2. Filter by channel (if specified)
  3. Match regex pattern against message content
  4. Check guardrails (cooldown, concurrency, dedup)
  5. Spawn execution in background task

Guardrail Checks

Cooldown

Concurrency

Deduplication

For event triggers, prevents firing on duplicate content:
Hashes are stored for the dedup_window duration.

Notifications

Routines send notifications based on status:
Notification format:

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 actions
  • migrations/ - Database schema migrations