← Catalog

@pi-agents/loop

Recurring prompt execution and cron scheduling for pi-agent — /loop, cron_create, cron_delete, cron_list

Extension

Install

Install with PiG

pig install npm:@pi-agents/loop

Install with Pi

pi install npm:@pi-agents/loop
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "image": "https://raw.githubusercontent.com/ArtemisAI/pi-loop/main/assets/logo.png",
  "skills": [
    "./skills"
  ],
  "extensions": [
    "./dist/index.js"
  ]
}

README

Written by the package's publisher, shown as published in version 0.3.1 (README.md). PiG does not review it.

@pi-agents/loop

Recurring prompt scheduling and cron job management for pi-coding-agent. Ported from Claude Code's /loop system.

Features

  • /loop command — Fixed interval (/loop 5m check the deploy) or dynamic self-pacing (/loop monitor the build)
  • Cron tools — LLM-callable cron_create, cron_delete, cron_list for programmatic scheduling
  • ScheduleWakeup — schedule_wakeup tool for model-driven dynamic pacing (60-3600s delays)
  • Idle gating — Prompts only fire when the agent is idle, never interrupting in-progress work
  • Durable tasks — Optionally persist schedules across sessions via .pi-loop.json
  • Missed task recovery — Durable one-shots missed while offline are detected and fired on restart
  • Session resume — Session-only tasks survive conversation compaction
  • Anti-thundering-herd — Deterministic jitter (50% of interval, 30-min cap) prevents API load spikes
  • Auto-expiry — Recurring tasks expire after 7 days by default
  • Config files — Per-project .pi-loop.config.json overrides
  • Debug mode — Set PI_LOOP_DEBUG=1 for verbose logging

Install

pi install npm:@pi-agents/loop@latest

Or add to your pi-agent settings (~/.pi/agent/settings.json):

{
  "packages": ["npm:@pi-agents/loop"]
}

Usage

Slash Commands

CommandDescription
/loop [interval] <prompt>Start a recurring loop (default: dynamic pacing)
/loop-listList all active loops
/loop-kill <id>Cancel a loop by ID

Fixed interval:

/loop 5m check the deploy
/loop check tests every 15m

Dynamic pacing (no interval):

/loop monitor the build

The agent executes the prompt immediately, then uses schedule_wakeup to self-pace subsequent iterations.

LLM Tools

The extension registers four tools the LLM can call directly:

ToolDescription
cron_createSchedule a prompt on a 5-field cron expression
cron_deleteCancel a scheduled task by ID
cron_listList all active scheduled tasks
schedule_wakeupArm a single-shot timer for dynamic self-pacing

cron_create parameters:

ParameterTypeDefaultDescription
cronstringrequired5-field cron expression in local time
promptstringrequiredPrompt to enqueue at fire time
recurringbooleantruetrue = recurring, false = one-shot
durablebooleanfalsetrue = persist across sessions
labelstringoptionalHuman-readable label

schedule_wakeup parameters:

ParameterTypeDescription
delaySecondsnumberSeconds until wake-up (clamped to 60-3600)
reasonstringWhy this delay was chosen
promptstringPrompt to fire on wake-up

Cron Format

Standard 5-field cron in local time: minute hour day-of-month month day-of-week

PatternMeaning
*/5 * * * *Every 5 minutes
0 */2 * * *Every 2 hours
30 14 * * *Daily at 2:30 PM
0 9 * * 1-5Weekdays at 9 AM

Durable vs Session Tasks

  • Session tasks (default) — Live only for the current session. Survive compaction. Lost when the agent exits.
  • Durable tasks (durable: true) — Persisted to .pi-loop.json. Restored on next session start. Missed one-shots are recovered and fired.

Multi-Instance Safety

When multiple pi-agent sessions run in the same directory, a file-based lock (.pi-loop.json.lock) ensures only one instance processes durable tasks. Uses PID-based liveness checking to recover from crashed sessions.

Configuration

Create .pi-loop.config.json in your project root to override defaults:

{
  "maxJobs": 50,
  "recurringMaxAgeMs": 604800000,
  "durableFilePath": ".pi-loop.json"
}
SettingDefaultDescription
maxJobs50Maximum concurrent scheduled tasks
recurringMaxAgeMs604800000 (7d)Auto-expiry for recurring tasks
recurringJitterFrac0.5Jitter as fraction of cron gap (50%)
recurringJitterCapMs1800000 (30m)Maximum jitter delay
checkIntervalMs1000Scheduler tick interval
durableFilePath.pi-loop.jsonDurable task file path

Development

npm run build       # Compile TypeScript
npm run test        # Run all tests (unit + integration)
npm run test:unit   # Run unit tests only
npm run test:watch  # Watch mode

License

MIT