Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build LLM-powered apps with the Anthropic Claude API or SDK across Python, TypeScript, Java, Go, Ruby, C#, and PHP.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
shared/managed-agents-scheduled-deployments.md
1# Managed Agents — Scheduled Deployments23A **scheduled deployment** runs an agent on a recurring cron schedule — each firing creates a session autonomously. Use it for predictable-cadence work: nightly triage, weekly compliance scans, hourly monitors.45Requires the `managed-agents-2026-04-01` beta header (the SDK sets it automatically for `client.beta.deployments.*` / `client.beta.deployment_runs.*` calls).67## Create a deployment89A deployment bundles everything a session needs (agent, environment, optional files / GitHub / memory stores / vaults) plus a `schedule` and the `initial_events` that kick off each run:1011- `agent` and `environment_id` are required — same shapes as `sessions.create` (see `shared/managed-agents-core.md`).12- `initial_events` must contain the starting `user.message`.13- `schedule` takes a cron `expression` and an IANA `timezone`. Minute-level granularity is the maximum.1415```bash16curl -fsSL https://api.anthropic.com/v1/deployments \17-H "x-api-key: $ANTHROPIC_API_KEY" \18-H "anthropic-version: 2023-06-01" \19-H "anthropic-beta: managed-agents-2026-04-01" \20-H "content-type: application/json" \21-d @- <<EOF22{23"name": "Weekly compliance scan",24"agent": "$AGENT_ID",25"environment_id": "$ENVIRONMENT_ID",26"initial_events": [27{"type": "user.message", "content": [{"type": "text", "text": "Run the weekly compliance scan."}]}28],29"schedule": {30"type": "cron",31"expression": "0 20 * * 5",32"timezone": "America/New_York"33}34}35EOF36```3738```python39deployment = client.beta.deployments.create(40name="Weekly compliance scan",41agent=agent.id,42environment_id=environment.id,43initial_events=[44{45"type": "user.message",46"content": [{"type": "text", "text": "Run the weekly compliance scan."}],47},48],49schedule={50"type": "cron",51"expression": "0 20 * * 5",52"timezone": "America/New_York",53},54)55```5657The response is a deployment object (`depl_` ID prefix). Check `schedule.upcoming_runs_at` — the next fire times — to confirm the schedule parses the way you intended:5859```json60{61"id": "depl_01xyz",62"status": "active",63"paused_reason": null,64"schedule": {65"type": "cron",66"expression": "0 20 * * 5",67"timezone": "America/New_York",68"last_run_at": null,69"upcoming_runs_at": ["2026-05-09T00:00:00Z", "2026-05-16T00:00:00Z", "2026-05-23T00:00:00Z"]70}71}72```7374Deployments may apply up to **10 seconds of jitter** to distribute load. Maximum **1000 scheduled deployments per organization** (contact Anthropic support for more).7576### Cron and timezone semantics7778- **Expression:** standard POSIX cron (`minute hour day-of-month month day-of-week`).79- **Timezone:** IANA identifier (e.g. `"America/Los_Angeles"`).80- **DST:** literal wall-clock matching — `"0 20 * * *"` in `America/New_York` fires at 8:00 PM local regardless of EST/EDT.8182> ⚠️ **DST edge:** wall-clock times that don't exist on a spring-forward day (e.g. 2AM) are **skipped**; times that occur twice on a fall-back day **fire twice**. Schedule outside the 1–3AM local window, or use UTC, when missed or duplicate executions are unacceptable.8384## Deployment runs8586Every trigger attempt — successful or not — writes a **deployment run** record (`drun_` prefix), so you can audit failures independent of the session lifecycle. A successful run carries the created `session_id`; follow that session via the event stream (`shared/managed-agents-events.md`) or webhooks (`shared/managed-agents-webhooks.md`) as usual. A failed run carries an `error` whose `type` explains why session creation was rejected.8788```python89# All runs for a deployment90for run in client.beta.deployment_runs.list(deployment_id=deployment.id):91print(run.created_at, run.session_id or run.error.type)9293# Failures only94for run in client.beta.deployment_runs.list(deployment_id=deployment.id, has_error=True):95print(run.created_at, run.error.type, run.error.message)96```9798```typescript99for await (const run of client.beta.deploymentRuns.list({100deployment_id: deployment.id,101has_error: true,102})) {103console.log(run.created_at, run.error?.type, run.error?.message);104}105```106107Raw HTTP: `GET /v1/deployment_runs?deployment_id=...&has_error=true`.108109A failed run looks like:110111```json112{113"type": "deployment_run",114"id": "drun_01abc124",115"deployment_id": "depl_01xyz",116"trigger_context": { "type": "schedule", "scheduled_at": "2026-05-09T00:00:00Z" },117"session_id": null,118"error": { "type": "environment_archived", "message": "environment `env_01abc` is archived" },119"agent": { "type": "agent", "id": "agent_01ghi789", "version": 3 },120"created_at": "2026-05-09T00:00:01Z"121}122```123124Error types include `environment_archived`, `agent_archived`, `vault_not_found`, `session_rate_limited`, and `service_unavailable`.125126## Lifecycle: pause / unpause / archive127128| Operation | SDK | Effect |129|---|---|---|130| Pause | `client.beta.deployments.pause(id)` | Suppresses scheduled triggers go-forward. Sessions already running continue. **Manual runs are still permitted while paused.** Sets `paused_reason: {"type": "manual"}`. |131| Unpause | `client.beta.deployments.unpause(id)` | Resumes from the next scheduled occurrence. **Missed triggers are not backfilled.** Clears `paused_reason`. |132| Archive | `client.beta.deployments.archive(id)` | **Terminal** — the schedule stops and the deployment can no longer be modified. Use pause for anything reversible. |133134Raw HTTP: `POST /v1/deployments/{deployment_id}/pause` (likewise `/unpause`, `/archive`).135136### Failure behavior137138- **Rate-limited:** recorded immediately as a `session_rate_limited` run, **no retry** — the schedule simply tries again at the next occurrence. (Rate limits on API calls *inside* a session are handled by the session itself.)139- **Other failed runs** (e.g. `environment_archived`, `vault_not_found`, `service_unavailable`): the run records the `error.type` — monitor runs and fix the referenced resource, or pause the deployment.140- **Agent archived or deleted:** the deployment is automatically **archived** (terminal) and no further sessions are created.141142## Manual runs143144`POST /v1/deployments/{deployment_id}/run` (SDK: `client.beta.deployments.run(id)`) creates a session immediately and writes a run with `trigger_context.type: "manual"`. Use it to **test a deployment before committing to the schedule** — and remember it works even while the deployment is paused.145