> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blocks.team/llms.txt
> Use this file to discover all available pages before exploring further.

# @task

The `@task` decorator defines a single-turn automation. Tasks are one-shot
(but can be long-running) and can be triggered by events or on a schedule
(`schedule.daily`, `schedule.weekly`).

<CodeGroup>
  ```python automation.py theme={null}
  from blocks import on, task

  @on("schedule.daily")
  @on("webhook")
  @task(name="version-drift-bot")
  def version_drift_bot(input):
      ...
  ```
</CodeGroup>

The only required argument is `name`. The `name` must be unique per workspace;
changing it will create a new automation or overwrite an existing one with the
same name.

### Arguments

<ResponseField name="name" type="string" required>
  The name of the automation.
</ResponseField>

<ResponseField name="required_env_vars" type="array">
  Environment variables that must be set before the automation can be enabled.
</ResponseField>

### When to use `@task` vs `@agent`

Reach for `@task` first. Tasks are one-turn — they run once per trigger and
finish. Use them for scheduled jobs, webhook handlers, or any automation that
doesn't need to keep talking to a user.

Reach for `@agent` only when you need a **multi-turn conversation** — users
continuing the thread from Slack, Linear, or the dashboard, with context
carried across messages.

<CodeGroup>
  ```python task.py theme={null}
  from blocks import on, task

  @on("schedule.daily")
  @task(name="version-drift-bot")
  def version_drift_bot(input):
      ...
  ```

  ```python agent.py theme={null}
  from blocks import agent, on

  @agent(name="claude-custom", required_env_vars=["ANTHROPIC_API_KEY"])
  @on("slack.mention")
  @on("github.issue_comment")
  def claude_agent(input, config):
      ...
  ```
</CodeGroup>
