# Schedule tasks

import { Steps } from "@astrojs/starlight/components"
import Prereqs from "@docs/Prereqs.astro"
import UiWalkthrough from "@docs/UiWalkthrough.astro"
import ClientTabs from "@docs/ClientTabs.astro"

Schedule an agent to fire automatically on a cron expression: every Monday at 09:00, every hour, or any standard 5-field schedule.

<Prereqs>
  - A Ren account with a [project](/docs/deep-dives/concepts/compute/projects/) that has at least one agent attached -
  [The CLI installed](/docs/developers/cli/), or a personal access token for the API and TypeScript calls
</Prereqs>

## In the UI

<UiWalkthrough>
  {/* TODO(demo): screen recording – creating a cron trigger from the dashboard, ~10s loop */}
</UiWalkthrough>

<Steps>

1. Open **Triggers** under your project in the sidebar.

2. Click **New trigger** and choose **Cron**.

3. Pick the agent to run, type the prompt it should receive each fire, and set the schedule (5-field cron).

4. Optionally set a timezone (defaults to UTC).

5. Click **Create**. The trigger is enabled immediately.

</Steps>

## Programmatically

<ClientTabs clients={["cli", "api", "typescript"]}>

<Fragment slot="cli">
  **Create a cron trigger**

```bash
ren triggers create \
  --project-id prj_abc123 \
  --project-agent-id pagt_abc123 \
  --input-message "Summarize this week's activity" \
  --schedule "0 9 * * MON" \
  --timezone "America/New_York"
```

**List triggers in a project**

```bash
ren triggers list --project-id prj_abc123
```

**Update a trigger** (change schedule, prompt, or toggle enabled)

```bash
ren triggers update trg_abc123 \
  --project-id prj_abc123 \
  --schedule "0 */2 * * *" \
  --is-enabled false
```

**Archive a trigger** (stops the schedule permanently)

```bash
ren triggers archive trg_abc123 --project-id prj_abc123
```

</Fragment>

<Fragment slot="api">
  **Create a cron trigger**

```bash
curl -X POST https://api.renai.build/api/triggers \
  -H "Authorization: Bearer $REN_PAT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "projectId": "prj_abc123",
    "projectAgentId": "pagt_abc123",
    "inputMessage": "Summarize this week'\''s activity",
    "schedule": "0 9 * * MON",
    "timezone": "America/New_York"
  }'
```

**List triggers**

```bash
curl "https://api.renai.build/api/triggers?projectId=prj_abc123" \
  -H "Authorization: Bearer $REN_PAT_TOKEN"
```

**Update a trigger**

```bash
curl -X PATCH "https://api.renai.build/api/triggers/trg_abc123" \
  -H "Authorization: Bearer $REN_PAT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "projectId": "prj_abc123",
    "schedule": "0 */2 * * *",
    "isEnabled": false
  }'
```

**Archive a trigger**

```bash
curl -X POST "https://api.renai.build/api/triggers/trg_abc123/archive" \
  -H "Authorization: Bearer $REN_PAT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "projectId": "prj_abc123" }'
```

</Fragment>

<Fragment slot="typescript">
  ```ts
  import { createRenClient, pat } from "@renai-labs/sdk"

const client = createRenClient({
baseUrl: "https://api.renai.build",
auth: pat(process.env.REN_PAT_TOKEN!),
})

// Create a cron trigger
const { data: trigger, error } = await client.trigger.create({
body: {
projectId: "prj_abc123",
projectAgentId: "pagt_abc123",
inputMessage: "Summarize this week's activity",
schedule: "0 9 \* \* MON",
timezone: "America/New_York",
},
})
if (error) throw error
console.log(trigger.id) // "trg_abc123"

// List triggers
await client.trigger.list({ query: { projectId: "prj_abc123" } })

// Update a trigger
await client.trigger.update({
path: { triggerId: trigger.id },
body: { projectId: "prj*abc123", schedule: "0 */2 \_ \* \*", isEnabled: false },
})

// Archive a trigger
await client.trigger.archive({
path: { triggerId: trigger.id },
body: { projectId: "prj_abc123" },
})

```
</Fragment>

</ClientTabs>

The schedule uses standard 5-field cron syntax: `minute hour day-of-month month day-of-week`. Archiving a trigger stops it permanently.
```