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

# Workers

> Workers are background tasks your factory spawns and manages on its own. Track progress, stream live output, read history, and steer them mid-flight.

A **Worker** is a background task that your factory spins up to execute real work—calling connected apps, reading files, pausing for human approvals, and reporting back when done.

You don't start Workers manually through the API; your factory creates and manages them automatically in response to Events and conversations. With the Factory API, you can inspect any Worker's status, read its transcript, stream live progress, or steer it with new instructions.

In the support example, when Ticket 4821 reports a duplicate charge, the factory launches a Worker (*"Check order 1188 and refund the duplicate charge"*). The Worker inspects the charge, pauses for a support lead's approval, issues the refund, and reports back—so the factory can reply cleanly in the ticket's Room.

![Worker lifecycle: Factory spawns a Worker, it runs and streams output, pauses in waiting for human Review, completes to idle, and reports back so the factory posts the Room response.](https://mintcdn.com/worklayer-17401167/cpUXFKQRIMsNdzrq/images/diagrams/workers-lifecycle-light.svg?fit=max\&auto=format\&n=cpUXFKQRIMsNdzrq\&q=85\&s=a7fe5f82b7c0b9f8a3c3ce90e77096af)

## How Workers run

* **Self-managed:** the factory assigns each Worker a title and a clear brief.
* **Factory-scoped permissions:** Workers use the factory's [connected apps](https://docs.myworklayer.com/apps.md), skills, memory, and files, acting with the factory owner's permissions and configured tool policies.
* **Parallel execution:** up to **20 Workers** per factory can run simultaneously.
* **Clean reporting:** when a Worker finishes, fails, or is stopped, its outcome goes back to the factory—not directly into [Room History](https://docs.myworklayer.com/rooms.md#room-history). The factory decides how and what to communicate in the Room.

## What Workers can and cannot do

Understanding a Worker's execution boundaries helps you—and your coding agent—design the right split between Worklayer and external tools.

### What a Worker can do

* **Call connected apps, custom MCP servers, and OpenAPI tools:** A Worker can invoke any enabled tool connected to the factory (for example, GitHub, Sentry, PostHog, Stripe, Slack, PostgreSQL, Cursor Cloud Agents, or your own internal API). See [Apps & integrations](https://docs.myworklayer.com/apps.md).
* **Run sandboxed JavaScript and TypeScript orchestration scripts:** When a task requires chaining calls, paginating APIs, looping, retrying, or filtering large payloads, a Worker can execute a JavaScript/TypeScript script inside an isolated sandbox (up to 2 minutes per script). Large intermediate results stay inside the script so only concise outputs return to the model.
* **Work with factory files, memory, skills, and databases:** Workers have a virtual shell (`grep`, `rg`, `jq`, and standard text utilities) over scoped workspace directories:
  * `/scratch` — per-Worker temporary working files and large tool outputs.
  * `/files` — persistent factory files shared across sessions (reports, evidence bundles, CSVs, HTML artifacts).
  * `/memory` — long-term factory knowledge persisted across tasks.
  * `/skills` — read-only reusable playbooks (modified via Skills tools).
  * Structured factory databases for tabular records the factory needs to query, filter, or count.
* **Create self-managed Monitors:** A Worker can set up a timer-based check (for example, watching a pull request's CI checks, waiting on a coding agent run, or polling a shipment status) and wake up automatically when state changes.
* **Pause for human Review:** Whenever a tool policy is set to **Ask** (or a Worker needs clarification or a missing app connection), it pauses safely in `waiting` state and creates a [Review](https://docs.myworklayer.com/review.md).

### What a Worker cannot do directly

* **No general-purpose VM, local shell, or direct git repository execution:** Worklayer's built-in code sandbox executes TypeScript/JavaScript orchestration scripts against connected tools—it does **not** provide a Linux dev container, package installer, or local git checkout. A Worker cannot clone a repository, edit code on disk, or run a test suite directly inside Worklayer.
* **No arbitrary outbound HTTP from sandbox code:** Sandbox scripts have no direct internet access and no host filesystem access. Any external API call must go through a built-in app, an uploaded OpenAPI spec, or a custom remote MCP server so credentials and approval policies stay enforced.
* **No bypassing tool policies or accessing private user accounts:** Workers cannot invoke disabled tools, skip **Ask** approval policies, or read personal app accounts belonging to individual team members.

> [!TIP]
>
> **Want your factory to write code, open PRs, and ship fixes?** Connect a coding agent (such as **Cursor Cloud Agents**, a GitHub workflow that triggers `@codex`, or a custom remote MCP server attached to your dev environment) alongside **GitHub** and your observability tools. The Worker investigates the issue, dispatches the coding agent, monitors CI and diffs, pauses for a human approval [Review](https://docs.myworklayer.com/review.md) before merging or rolling back, and verifies the fix.

## Follow progress

**1. List Workers in a Room**

```bash theme={null}
curl "https://api.myworklayer.com/v1/rooms/$ROOM_ID/workers"       -H "Authorization: Bearer $WORKLAYER_API_KEY"
```

Results are ordered by most recent activity. By default, the endpoint returns only active Workers (`running` or `waiting`). Pass `status=all` to retrieve every Worker, or pass a specific status value to filter.

**2. Check Worker status**

| `status` | Meaning |
| - | - |
| `running` | Actively executing work. |
| `waiting` | Paused and waiting on human input—such as a [Review](https://docs.myworklayer.com/review.md). |
| `idle` | Not currently running (a completed Worker transitions to `idle`). |
| `failed` | Stopped due to an error. |
| `stopped` | Manually stopped by a person or the factory. |

To receive real-time transitions without polling, subscribe to the `worker.status` [Subscription event](https://docs.myworklayer.com/subscriptions.md).

**3. Read Worker messages**

Call `GET /v1/rooms/{roomId}/workers/{workerId}/messages` to fetch the Worker's saved transcript in AI SDK `UIMessage` format (`id`, `role` of `user` or `assistant`, and `parts`). Set `order=asc` (oldest first, default) or `order=desc` (newest first).

In an API-created Room, you can access only Workers spawned by that Room. In the [main Room](https://docs.myworklayer.com/rooms.md#the-main-room) (`web`), you can access all Workers across the factory. Requesting a Worker outside the Room's scope returns `404`.

### What Worker history omits

* Tool calls appear as `dynamic-tool` parts with `input: null`. `output` is also `null`, except when the Worker presents files to a user (in which case `output` contains the file list).
* Failed tool calls include `errorText: "Tool failed."`.
* Certain internal execution steps are omitted from the public transcript.

If a single history group is too large to serialize in the response, the API returns `422` with `code: "worker_history_group_too_large"`.

## Steer a Worker

Send a message directly to a Worker to add context, redirect its work, or kick off a follow-up on an `idle` Worker:

```bash theme={null}
curl -X POST "https://api.myworklayer.com/v1/rooms/$ROOM_ID/workers/$WORKER_ID/messages"   -H "Authorization: Bearer $WORKLAYER_API_KEY"   -H "Content-Type: application/json"   -d '{"text": "Also email the customer a confirmation once the refund goes through.", "delivery": "steer"}'
```

* `text`: 1 to 16,000 non-blank characters.
* `delivery`:
  * `queue` (default) — runs as a new request once the Worker's current work completes.
  * `steer` — injects guidance mid-flight during the Worker's active work.
  * `context` is **not supported** for Workers (it is only for [Room Events](https://docs.myworklayer.com/events.md#choose-when-the-factory-reads-an-event)) and returns `400` with `Supply nonblank text within the composer limit and a valid delivery.`

A `201 Created` response returns the saved `messageId` and an optional `status`:

| Response `status` | Meaning | Recommended action |
| - | - | - |
| *(omitted)* | The message was saved and the Worker started processing it. | None—follow via stream, messages, or webhooks. |
| `"execution_unconfirmed"` | The message was saved, but the API could not confirm that execution started. | Don't resend. Inspect the Worker's status or messages. |
| `"not_started"` | The message was saved, but execution did not start. Inspect `failure` for a reason code. | Resolve the reported failure before sending more messages. |

If the message could not be saved and execution could not start, the API returns `503` (safe to retry later) or `402` (billing issue—retrying will not resolve it).

## Stream a run

Stream a Worker's live output over Server-Sent Events with `GET /v1/rooms/{roomId}/workers/{workerId}/stream`:

* If the Worker is not actively running, the API returns `204 No Content` with an empty body.
* If the Worker is running, the API returns `200 OK` with `Content-Type: text/event-stream` and `x-vercel-ai-ui-message-stream: v1`, formatted as an AI SDK UI message stream.

Each event is a `data: <JSON chunk>` line, terminated by `data: [DONE]`:

```text theme={null}
data: {"type":"start","messageId":"msg_02"}

data: {"type":"text-start","id":"txt_0"}

data: {"type":"text-delta","id":"txt_0","delta":"The refund for order 1188 is complete."}

data: {"type":"text-end","id":"txt_0"}

data: {"type":"finish"}

data: [DONE]
```

You can attach to a stream at any point—the server snapshots the current state of the active assistant message first, then streams incremental deltas. The stream closes once the run completes, fails, pauses for Review, or rolls into a new assistant message (reconnect to follow the next message). A failed run emits `{"type":"error","errorText":"Worker run failed."}`.

Consume stream chunks promptly: if a slow reader forces the server to buffer more than **4 MiB**, Worklayer closes the connection.

## When a Worker finishes

Once a Worker completes its work, its status returns to `idle` and its report is handed back to the factory. To show the final outcome to end users, read [Room History](https://docs.myworklayer.com/rooms.md#room-history) or listen for the `room.response` [Subscription event](https://docs.myworklayer.com/subscriptions.md). You can also send a new message to an `idle` Worker anytime to continue working in the same Worker context.

Workers that fail or are stopped also report back to the factory so it can decide how to recover or inform your team.

> [card] [Review](https://docs.myworklayer.com/review.md)
>
> Unblock Workers waiting for human approval, answers, or app connections.

> [card] [Rooms](https://docs.myworklayer.com/rooms.md#room-history)
>
> Read the factory's user-facing responses in Room History.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.