# Schedule a run

A schedule starts a [run](/docs/concepts/runs.md) of an agent, task or workflow at set times.

## Before you start

You need a project with an agent. See [Create an agent](/docs/agents/create-agent.md).

## Create a schedule

**Studio**

1. In your project, open **Orchestration** > **Triggers**.
2. Click **Create schedule**.
3. Enter `Weekday stand-up` as the **Name**.
4. Keep **Type** as **Agent**.
5. Under **Target**, pick your agent, `Stand-up host`.
6. Keep **Mode** as **New conversation**.
7. Enter `Write today's stand-up questions.` as the **Instructions**.
8. Set **Frequency** to **Weekdays**.
9. Enter `08:30` as the **Time**. Schedules run in UTC.
10. Click **Create schedule**. Studio opens the schedule, **Active**.
11. Open the **⋯** menu in the page's header.
12. Click **Run now**. Studio opens the run, which reads **Completed** when it finishes.
13. Open **Conversations**.
14. Click `Weekday stand-up`.
15. Click **Open chat**. You should now see three questions in the agent's message.

**Code**

1. Add the agent:

```ts title="agents/stand-up-host.ts"
import { agent } from "veryfront/agent";

export default agent({
  id: "stand-up-host",
  name: "Stand-up host",
  system: "Write three short stand-up questions for the team: what they did, what they will do, what blocks them. Nothing else.",
});
```

2. Add the schedule:

```ts title="schedules/weekday-standup.ts"
import { schedule } from "veryfront/schedule";

export default schedule({
  id: "weekday-standup",
  name: "Weekday stand-up",
  schedule: "30 8 * * 1-5",
  timezone: "UTC",
  target: { kind: "agent", id: "stand-up-host", conversationMode: "create_new" },
  agentMessage: { prompt: "Write today's stand-up questions." },
});
```

3. Run it on your machine. It prints three questions:

```bash
npx veryfront schedule run weekday-standup
```

4. [Push the project](/docs/projects/local.md). The schedule waits in **Orchestration** > **Triggers** as **Source-defined**.
5. Open the **⋯** menu on its row.
6. Click **Activate**.
7. Open the **⋯** menu in the page's header.
8. Click **Run now**. You should now see the run read **Completed**.

### Try it in a sandbox

```playground
step: Create a project | npm create -y veryfront@latest team-standup -- --template ai-agent --yes
step: Add the agent | cd team-standup && printf '%s\n' 'import { agent } from "veryfront/agent";' '' 'export default agent({' '  id: "stand-up-host",' '  name: "Stand-up host",' '  system: "Write three short stand-up questions for the team: what they did, what they will do, what blocks them. Nothing else.",' '});' > agents/stand-up-host.ts
step: Add the schedule | mkdir -p schedules && printf '%s\n' 'import { schedule } from "veryfront/schedule";' '' 'export default schedule({' '  id: "weekday-standup",' '  name: "Weekday stand-up",' '  schedule: "30 8 * * 1-5",' '  timezone: "UTC",' '  target: { kind: "agent", id: "stand-up-host", conversationMode: "create_new" },' '  agentMessage: { prompt: "Write today'\''s stand-up questions." },' '});' > schedules/weekday-standup.ts
step: Push the project | npx veryfront push
check: npx veryfront schedule run weekday-standup
expect: "status": "completed"
```

**API**

1. Set `PROJECT` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT=<id>`.
2. Set `AGENT_ID` to your agent's ID: `export AGENT_ID=<id>`.
3. Create the schedule with your [API key](/docs/authentication/api-keys.md):

```bash
curl -X POST https://api.veryfront.com/projects/$PROJECT/schedules \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Weekday stand-up",
    "target": { "kind": "agent", "id": "'$AGENT_ID'", "conversation_mode": "create_new" },
    "schedule": "30 8 * * 1-5",
    "timezone": "UTC",
    "config": { "prompt": "Write today'"'"'s stand-up questions." }
  }'
```

4. Set `SCHEDULE_ID` to the response's `schedule.id`: `export SCHEDULE_ID=<id>`.
5. Run it now:

```bash
curl -X POST https://api.veryfront.com/runs \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "project_id": "'$PROJECT'", "source": { "type": "schedule", "id": "'$SCHEDULE_ID'" } }'
```

6. Set `RUN_ID` to the response's `id`: `export RUN_ID=<id>`.
7. Read the run until `status` is `completed`. You should now see three questions in `output.text`:

```bash
curl https://api.veryfront.com/runs/$RUN_ID \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

### Try it in a sandbox

```playground
step: Add the Stand-up host agent | curl -fsS -X POST https://api.veryfront.com/projects/$VERYFRONT_PROJECT_ID/agents -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"id": "stand-up-host", "name": "Stand-up host", "system_prompt": "Write three short stand-up questions for the team: what they did, what they will do, what blocks them. Nothing else."}'
step: Set PROJECT | export PROJECT=$VERYFRONT_PROJECT_ID
step: Set AGENT_ID | export AGENT_ID=stand-up-host
step: Create the schedule | curl -X POST https://api.veryfront.com/projects/$PROJECT/schedules -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{ "name": "Weekday stand-up", "target": { "kind": "agent", "id": "'$AGENT_ID'", "conversation_mode": "create_new" }, "schedule": "30 8 * * 1-5", "timezone": "UTC", "config": { "prompt": "Write today'"'"'s stand-up questions." } }' | tee schedule.json
step: Set SCHEDULE_ID | export SCHEDULE_ID=$(jq -r .schedule.id schedule.json)
step: Run it now | curl -X POST https://api.veryfront.com/runs -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{ "project_id": "'$PROJECT'", "source": { "type": "schedule", "id": "'$SCHEDULE_ID'" } }' | tee run.json
step: Set RUN_ID | export RUN_ID=$(jq -r .id run.json)
step: Wait until it is completed | until [ "$(curl -s https://api.veryfront.com/runs/$RUN_ID -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r .status)" = completed ]; do sleep 3; done
check: curl https://api.veryfront.com/runs/$RUN_ID -H "Authorization: Bearer $VERYFRONT_API_KEY"
expect: "status":"completed"
```

## With MCP

1. Call `veryfront__create_schedule`. The instructions go in `config.prompt`:

```json
{
  "project_reference": "team-stand-up",
  "name": "Weekday stand-up",
  "target": { "kind": "agent", "id": "stand-up-host", "conversation_mode": "create_new" },
  "schedule": "30 8 * * 1-5",
  "timezone": "UTC",
  "config": { "prompt": "Write today's stand-up questions." }
}
```

2. Call `veryfront__create_schedule_run` with the same `project_reference` and the schedule's `id` from step 1 as `schedule_id`. It returns the run's `run_id`.
3. Call `veryfront__get_run` with that `run_id` until `status` is `completed`, a few seconds. It worked when `output.text` holds three questions.

`veryfront__create_schedule` makes a schedule directly; it can't activate one defined in `schedules/`.

## Next steps

* [Trigger a run from a webhook](/docs/orchestration/webhooks.md)
* [Debug a run](/docs/observability/debug.md)
