Skip to content
pi-c Artifact [37b92dc180]
Login

Artifact [37b92dc180]

Artifact 37b92dc180fff4cbd387a57fdb5b92f85691771a6d1109407d9cba489ea431c8:


# Loops

A loop sends a conversation the same prompt on a clock: "check the deploy every 5 minutes and tell
me if it is unhealthy". pic saves it in the journal, so a loop outlives the terminal it was started
in and a crash never sends a run twice.

## Starting one

In the terminal, `/loop 5m check the deploy and tell me if it is unhealthy`. The interval is a
number with `s`, `m`, `h` or `d` (`90s`, `5m`, `1h30m`, `1d`); the shortest is one minute, and a
loop given none runs every 10 minutes. The first run starts now. pic answers with what it made:

```
● loop L1 every 5m · first run now · about 41k tokens a run · ends in 7 days
  fires while pic is open here or pic remote runs · Esc during its run pauses it · /loop lists it
```

From a shell, `pic loop --session ID 5m PROMPT` does the same (without `--session`, in a new
conversation). A conversation can have eight loops at once.

## While it runs

Each run is a request of its own, with a first line saying a loop sent it, so the model knows you
did not just type it. If a request is running when a loop comes due, the loop's run waits and goes
next, as a follow-up does. A loop never stacks up: while one run waits, the loop does not fire
again. The footer names the next loop and when it runs (`loop L1 in 3:12`), and what loops have
spent once they have spent anything.

pic has no timer of its own. A loop fires while a pic is open in its workspace (the terminal
interface, or a request running there), or while `pic remote` runs. When none is, nothing fires:
the list says "not firing", and the first pic to open the journal fires it once, however many runs
it missed; that run says how many came due.

## Stopping one

- Esc during a loop's run stops the run and pauses the loop. `/loop resume L1` starts it again.
- `/stop` pauses every loop of the conversation and shows the list.
- `/loop` shows the list: `p` pauses the chosen loop, `r` resumes it, `s` stops it for good, `a`
  pauses them all.
- `/loop pause L1`, `/loop resume L1`, `/loop stop L1`; from a shell, `pic loop pause L1` and the
  rest.

A loop ends on its own 7 days after it started; its last run says so. Paused loops are kept until
you stop them.

## What a loop costs

There is no spending cap: each run is a full request with the conversation's context, so a loop
every 5 minutes for a day is about 290 requests. `pic loop` lists each loop with its runs and what
they cost, and `pic usage --by-wake` adds tokens. `pic ps` lists the workspace's loops after its
processes.

## For hooks and scripts

A loop's run arrives through the inbox with sender `wake:ID`, so a `UserPromptSubmit` hook sees
that origin and can refuse it. `pic loop fire` fires what is due now and starts the requests, as the
terminal does on its own; `pic loop --json` prints the list as JSON.