Tasks

A task is saved work attached to an agent. Use tasks when you want repeatable instructions that can run on demand or by trigger.

Create a task

teammate_id is the wire name for the agent id: JSON request and response bodies keep it. The SDK accepts agent_id (canonical) and teammate_id alike.

Key fields

FieldTypeDescription
teammate_idint (required)Agent that executes the task
instructionsstring (required)What should happen when the task runs
namestringTask label
schedulestringCron expression, e.g. 0 9 * * 1-5. Attaches trigger immediately
webhookboolEnable webhook trigger at creation. Returns webhook_url once
user_idstringEnd-user scope. See Users
All fields
FieldTypeDescription
toolsstring[]Optional override of agent tools
expected_outputstringOutput format expectation
goalsstringTask-specific goals injected into prompt context
schedule_timezonestringTimezone for schedule. Defaults to UTC
enable_lessonsboolAccumulate lessons from runs. Defaults to true. See Lessons

webhook_enabled is true when a webhook trigger is active. webhook_url is only set on first creation when webhook=True; it's not retrievable afterwards.

Run a task

Python
Approval callbacks, non-streaming runs, tool scoping

run_and_wait() handles approval pauses inline, no polling loop needed. It accepts the same callbacks as runs.create_and_wait(); see Human-in-the-Loop.

Python

Non-streaming:

Python

Pass task_setup_tools=False to keep a run limited to the task's normal tools, skipping the internal same-scope management tools for tasks, runs, inboxes, webhooks, and integrations. Pass feedback=False to disable the internal issue-reporting tool (report_issue).

Scheduling

Pass schedule= at creation time to attach a cron trigger in the same call:

Python

See Scheduling for cron patterns, interval schedules, and pausing or reshaping schedules.

Webhook trigger

Python

Add one to an existing task with client.tasks.triggers.create(task.id, type="webhook"); the returned trigger.url is likewise shown once.

Retrieve a task's results

Every run reports its task (run.task_id) and runs.list filters by it, so a scheduled or webhook-triggered task's history and outputs are one call away:

Python

Failed runs carry a machine-readable error_code plus a human-readable output; retryable=True means client.runs.retry(run.id) will be accepted. Prefer push? Subscribe a webhook endpoint to run.completed / run.failed.

Lessons

Agents save lessons from a task's runs: durable corrections and preferences they apply on future runs, accumulated automatically (capped at 20 per task; disable with enable_lessons=False). The API is the curation surface: read what the agent learned, remove bad entries.

Python

Manage tasks

Python

Next: Runs · Scheduling · Human-in-the-Loop · Webhook Events

Was this page helpful?