Native Tasks: creation, interaction and recovery
Use the native Task API when your backend needs direct control of Agent tasks, interactive input and the durable task event log. This guide connects submission, observation, replies and recovery; it requires project permissions beyond a minimal Invocation integration.
Contract and prerequisites
Download the Native Task v1 OpenAPI. It extracts public Task, Input Request and approval operations and their schema dependencies from the generated Control Plane OpenAPI. CI checks consistency. REST paths use /api/v1; the documentation release marker identifies the published document snapshot. The file describes HTTP JSON; SSE replay rules are specified below.
An administrator prepares the project, Workspace, Agent, Environment and a Workspace binding to their immutable versions. Store the permitted workspace_id and workspace_agent_binding_id on your backend; check the binding using GET /api/v1/workspaces/{workspace_id}/agents. A product login does not automatically grant platform project access.
| Operation | Required permissions |
|---|---|
| Create a Task | workspaces:write and tasks:write on the Workspace project |
| Read Tasks, events and input requests | tasks:read; reading bindings additionally needs workspaces:read |
| Reply or control a Task | tasks:write |
| Read or decide approvals | approvals:read or approvals:write |
| Use input or response attachments | Applicable Artifact permissions and ownership checks |
Send Authorization: Bearer ... and the correct X-OrbitSpace-Tenant when selecting a team with a compatible credential. Both OAuth/Token scopes and project grants apply. Keep credentials with broad project access on your backend.
Create and correlate a Task
Replace the placeholders in native-task.json with authorized UUIDs. Native Tasks take idempotency_key in the JSON body; the Invocation example's header does not replace this field.
curl --fail-with-body 'https://api.orbitspace.dev/api/v1/tasks' \
-H "Authorization: Bearer $ORBITSPACE_ACCESS_TOKEN" \
-H "X-OrbitSpace-Tenant: $ORBITSPACE_TENANT_ID" \
-H 'Content-Type: application/json' \
--data-binary @native-task.jsonPersist the payload and key before submitting. Key lookup is tenant-wide: namespace keys by customer, business conversation and operation. Reuse the original key and payload after a timeout; do not use one fixed key across customers. Save the returned id, workspace_id, worktree_id, agent_version_id, environment_version_id and state_version, and associate them with your own business session.
A binding resolves immutable Agent and Environment versions. Independent Tasks without a binding may supply both version IDs directly; Chat Tasks with conversation_id require an active binding. Generate and authorize conversation UUIDs on your backend rather than treating a user-entered customer identifier as one. See identity and context boundaries before sharing execution resources.
Task, Run and Input Request identities
| Identity | Meaning | Continuation behavior |
|---|---|---|
Task id | Durable execution intent | Explicit failure retry retains the Task ID |
Event run_id | One execution attempt | Retry creates another Run; pause/resume and input replies continue the same Run |
Input Request id | One question from a Run | A reply applies only to that request |
scope_task_id | Task used for operator authorization | May be the parent Task; child identity alone does not establish authority |
Task/request state_version | Optimistic concurrency for that resource | Read the resource being changed; their versions are not interchangeable |
Read Run identity from event run_id, not from model round counters, execution_id or UI counts. Read current Task state using GET /api/v1/tasks/{id}.
Receive and answer a question
Workers must explicitly enable ORBITSPACE_AGENT_INPUT_REQUESTS_ENABLED=true and register orbitspace.input_request=v2; the default is disabled. Operators must qualify actual questioning, cleanup and continuation with their selected engine. Creating a Task does not enable this capability, and this guide does not claim that a production deployment has passed real-model Codex interactive qualification.
- Observe
input.requested, takeinput_request_id, and readGET /api/v1/input-requests/{id}. After reconnecting, you can also useGET /api/v1/tasks/{task_id}/input-requests. - Check
task_idandscope_task_idagainst your business mapping and requirestatus=pending. The list returns the latest 100 receipts, including requests scoped from child Tasks. It is not an unlimited history API; never assume the first request belongs to the current user. - Render
messageandresponse_schema. Read the request's currentstate_versionand adapt input-reply.json; response fields come from the actual question schema.
curl --fail-with-body \
"https://api.orbitspace.dev/api/v1/input-requests/$INPUT_REQUEST_ID:reply" \
-H "Authorization: Bearer $ORBITSPACE_ACCESS_TOKEN" \
-H "X-OrbitSpace-Tenant: $ORBITSPACE_TENANT_ID" \
-H 'Content-Type: application/json' --data-binary @input-reply.jsonUse that request's expected_state_version, a stable reply idempotency_key and a schema-valid response; attachments receive separate Artifact checks. The same actor/key/payload can recover its existing receipt. Competing or changed replies conflict and require a fresh read. Replying completes the original tool call and queues the same Run after execution cleanup is acknowledged; it does not create a Task or reset budgets.
Expiry records a failed tool result and schedules continuation without fabricating an answer. Task cancellation cancels pending questions. WAITING_INPUT can also involve pending tool execution, so the status alone is insufficient to display an arbitrary reply form. A terminal report asking for more information is not a pending Input Request.
Historical backfill and live events
Native Task events differ from the Invocation projection. This request reads persisted PostgreSQL Task events:
curl --fail-with-body \
"https://api.orbitspace.dev/api/v1/tasks/$TASK_ID/events?after_sequence=0&page_size=100" \
-H "Authorization: Bearer $ORBITSPACE_ACCESS_TOKEN" \
-H 'Accept: application/json'The response contains events and next_sequence, without an Invocation snapshot. Process ascending events, deduplicate by event_id, and atomically commit your business updates and cursor. Request the next page using its returned next_sequence. Stop on an empty page and retain your committed cursor: the current empty response has next_sequence="0". Do not use tail=true for audit backfill.
The event envelope includes schema_version, type, task_id, run_id, sequence, occurred_at and payload. REST JSON uses decimal strings for 64-bit sequences and versions; retain precision. Record unknown event types and skip their business projection rather than resetting the cursor.
curl --no-buffer --fail-with-body \
"https://api.orbitspace.dev/api/v1/tasks/$TASK_ID/events" \
-H "Authorization: Bearer $ORBITSPACE_ACCESS_TOKEN" \
-H 'Accept: text/event-stream' \
-H "Last-Event-ID: $LAST_COMMITTED_SEQUENCE"Task SSE starts with an ID-less stream.ready, acknowledging the requested cursor rather than providing a snapshot or latest watermark. It then replays events greater than the cursor and follows new events. Last-Event-ID overrides after_sequence. Save the SSE id string rather than a potentially rounded JSON payload sequence. Closing the subscription leaves the Task running.
Snapshots, retention and control limits
The state_version returned by GET /tasks/{id} controls Task state writes; event schema_version versions the envelope. There is no public atomic mapping from a Task snapshot version to a last event sequence. Backfill history, read the current Task for UI state, and continue your original event cursor with deduplication. Applying a snapshot does not prove that business events were processed.
The current API does not advertise an earliest retained sequence, fixed retention duration or dedicated expired-cursor/history-gap response. If cleanup, restore or migration leaves a gap, mark history incomplete, stop effects requiring a complete ledger and reconcile with operators. Advancing to the newest cursor is not proof of complete history. Keep your own durable ledger for long-term auditing and agree retention with the platform operator.
Controls use POST /api/v1/tasks/{id}/pause, /resume, /cancel and /retry with {"expected_state_version":"CURRENT_TASK_VERSION"}. Retry creates a Run; pause/resume retains it. Input replies cannot reopen completed or cancelled Tasks. Approval decisions use the separate approval workflow.