# Automate goals and routines via the API

> Use goals and routines to run agents on a schedule or loop them until a job is done.

canonical: https://agentsky.dev/help/goals-and-routines-api
source: https://agentsky.dev/help/goals-and-routines-api.md
updated: 2026-10-21

---

**Use goals and routines to run agents on a schedule or loop them until a job is done.**

A **goal** is an objective you give an agent that it works toward over multiple turns. A **routine** is a recurring automated run — like a cron job for an agent.

**Goals via the API:**

1. Create a session: `POST /api/v1/sessions`.
2. Set a goal: `POST /api/v1/sessions/{id}/goal` with the objective text.
3. The agent works toward the goal, pausing to ask for input when needed.
4. Listen for `goal.completed`, `goal.paused`, or `goal.stopped` via webhooks.

Goals can run indefinitely — there is no required iteration ceiling for long-running agents.

**Routines via the CLI:**

```bash
sky routine create --name "daily-report" --cron "0 9 * * *" --session <session-id>
```

Use `sky routine runs` to see past runs and `sky routine list` to manage your routines.

**Assigning questions to a specific person:**

When an agent needs human input, you can specify who must answer. The `ask_user` tool accepts a `requiredUserId` and a `dueAt` deadline — the right person gets notified and can respond from any surface.

Where: API (goals), CLI and API (routines)

**Good to know:** Webhook events `goal.completed`, `goal.stopped`, `goal.paused`, and `goal.resumed` fire for every goal state change. Related: [What are automations?](https://agentsky.dev/help/automations-overview), [Receive webhook events](https://agentsky.dev/help/webhook-events), [Use the sky CLI](https://agentsky.dev/help/sky-cli-overview).
