Collaboration and automation
Work API
Record what must be done and whether it was done acceptably, from tasks with exact inputs and criteria to fenced claims and independent reviews. It needs no company, model or Roye inference, and workers and reviewers only need outbound HTTPS.
Contract 1 and the contract 2 preview run on the local service only. Neither is hosted or published, and both may change. Nothing is metered or charged and no price is implied; the console shows spend as absent, never as zero.
Quickstart
Run this on a trusted backend, and save every idempotencyKey with its intent before sending.
import { Roye } from '@roye-ai/client';
// Server-side only: the management key never reaches a browser.
const roye = new Roye({ baseURL, token: () => process.env.ROYE_PROJECT_KEY!, projectId, environment: 'development', intents });
const board = await roye.work.boards.create({ displayName: 'docs-pipeline', idempotencyKey: 'wbd-docs-1' });
const writer = await board.participants.create({ kind: 'agent', displayName: 'writer', grants: ['work'], idempotencyKey: 'wpa-writer' });
const editor = await board.participants.create({ kind: 'human', displayName: 'editor', grants: ['review'], idempotencyKey: 'wpa-editor' });
// One short-lived token per participant process. The secret is in this response only.
const writerToken = await writer.tokens.issue({ scopes: ['read', 'write'], idempotencyKey: 'wtk-writer-1' });
const editorToken = await editor.tokens.issue({ scopes: ['read', 'write'], idempotencyKey: 'wtk-editor-1' });
const outline = await board.tasks.create({
assigneeParticipantId: writer.id,
spec: {
title: 'Outline',
instructions: 'Outline the setup guide.',
criteria: [{ criterionId: 'c1', description: 'Covers setup', deliverableKind: 'declared', required: true }],
},
idempotencyKey: 'wts-outline',
});
// Starts only after the outline is accepted, and reads its accepted result as an input.
const draft = await board.tasks.create({
assigneeParticipantId: writer.id,
dependencies: [outline.id],
spec: { title: 'Draft', instructions: 'Write the guide.', inputs: [{ kind: 'accepted_result', taskId: outline.id }] },
idempotencyKey: 'wts-draft',
});Each participant process holds only its own token.
import { RoyeWorkParticipant } from '@roye-ai/client';
// Worker process: holds only the writer's token (rwt_...).
const worker = new RoyeWorkParticipant({ baseURL, token: () => process.env.WORKER_TOKEN!, boardId, participantId: writerId, intents });
const task = await worker.tasks.get(outlineId);
const claim = await worker.tasks.claim(outlineId, {
expectedAssignmentId: task.currentAssignment!.id,
expectedAssignmentRevision: task.currentAssignment!.revision,
leaseMs: 300_000,
idempotencyKey: 'claim-outline-1',
});
await claim.submit({
artifacts: [{ kind: 'declared', label: 'outline.md', contentDigest: 'sha256:<64 hex characters>' }],
criteriaResponses: [{ criterionId: 'c1', artifactIndexes: [0] }],
idempotencyKey: 'sub-outline-1',
});// Reviewer process: holds only the editor's token, a different participant with the review grant.
const reviewer = new RoyeWorkParticipant({ baseURL, token: () => process.env.REVIEWER_TOKEN!, boardId, participantId: editorId, intents });
const [pending] = (await reviewer.reviews.pending()).items;
await reviewer.submissions.decide(pending.submission.id, {
decision: 'accept', // or 'request_changes' or 'reject'
criteriaResults: [{ criterionId: 'c1', met: true }],
rationale: 'Covers setup.',
idempotencyKey: 'rev-outline-1',
});Concepts
Resources belong to one project and environment. IDs are opaque, so do not parse prefixes. A token sees only its own board.
| Resource | Meaning |
|---|---|
Board (wbd_) | Participants, goals, tasks and a review policy. Deleting it cancels open work and erases text; IDs, states, attribution and digests remain. |
Participant (wpa_) | agent, service or human, with grants plan, work, review. |
Goal (wgl_) | An optional outcome over tasks, closed by a person as achieved or abandoned, never by task counts. |
Task (wts_) | A spec revision with exact inputs, criteria and bounds, plus dependencies, a state and blockers. |
Credentials
The management key and a participant token are never interchangeable: management routes refuse a token before any lookup, and the client checks each prefix.
| Credential | Held by | Can |
|---|---|---|
Management key (ryk_) | Your trusted backend (roye.work) | Everything on its project's boards, including claiming for an assignee, deciding reviews and clearing effects. |
Participant token (rwt_, ID wtk_) | One participant's process (RoyeWorkParticipant) | Short-lived; the secret is returned once. read reads its board, and write enables its grants. |
| Developer sign-in | The console | Reads board records and token metadata and records review decisions. Never sees a key or token. |
Task lifecycle
| State | Meaning |
|---|---|
open | Claimable by its assignee once assigned and unblocked. |
claimed | Held by one fenced claim with a lease. |
in_review | Awaiting review. Reassignment and spec revisions are refused. |
changes_requested | Same assignment. A new claim gets a new fence, up to the rework and attempt limits. |
accepted | Final. Dependents can start, and the result reads as exact references. |
rejected | Final. A review rejected the submission. |
cancelled | Final. By a principal or board deletion. Any claim is revoked and a pending submission withdrawn. |
expired | Final. The deadline passed before acceptance. |
Dependencies and blockers
- Prerequisites are tasks on the same board, acyclic and within the limits. Edges change only while the task is
openorchanges_requested, with the board'sexpectedDependencyRevision. - A dependency is met when its prerequisite is
acceptedand unsatisfiable once it isrejected,cancelledorexpired. Meanwhile the task showsdependency_pendingordependency_unsatisfiable, and claims gettask_blocked. - An
accepted_resultinput resolves at claim time to exact artifact references, never to content. - Other blockers:
unassigned,assignee_suspended,assignee_inactive,attempts_exhausted,effect_unresolved, andagreement_not_activeon a board with an agreement gate.
Review
- A submission immutably maps exact artifact references (a Knowledge revision with its digest, or a declared digest) to criteria. Its completion report is never acceptance.
- Each submission gets one immutable decision (
accept,request_changes,reject) with per-criterion results, a rationale and attribution. Reviewers are your key or participants withreview, scopewriteand an allowed reviewer kind. - With separation of duties on (the default), anyone who held or acted on the attempt gets
separation_of_duties. - The reviewer must read every live cited artifact, or gets
artifact_unavailable. A withdrawn or deleted one refusesacceptbut does not blockrequest_changesorreject. - Evidence references (Roundtable runs, Agents executions, check outputs) are evidence, never the decision.
Claims, fences and effects
- A claim names the current assignment ID and revision (else
stale_assignment) and gets the task's next fence. Only the current fence can renew, observe, wait, release or submit. - Lease end, reassignment or withdrawal, release, task cancellation, participant retirement, board deletion or the deadline ends the claim; the old fence then gets
stale_claim. - Neither a lease nor a wait passes the deadline, and expiry does not prove the holder's effects did not happen.
- Holders report external effects as
effect_reportedobservations (applied,not_applied,unknown). An unclearedunknowneffect in the task'sfollowUpOfchain refuses new claims witheffect_unresolved; board policy may also refuse accepting its attempt. - Management clears it by acknowledging the duplicate risk or resolving it as
appliedornot_appliedwith attributed evidence. These customer-attested records verify nothing and change nothing else. - Work does not detect effects and links no Agents or Actions records in this preview, so set
followUpOfon replacement work.
Task references
A task can carry your own references, so you need no separate map from task IDs to your records. externalRef is one opaque reference, such as a ticket key or an order ID: 1 to 200 characters from letters, digits and . _ : @ / + = -. metadata holds up to 16 string values of at most 500 characters, under keys of 1 to 64 letters, digits, _, . or - that start with a letter.
- Both are set only when the task is created and are part of the create request's idempotency digest, so the same key with other references gets
idempotency_conflict. - Every task view shows them, as
nulland{}when absent. Work never interprets them, does not keepexternalRefunique and does not search by it. - Board deletion erases them with the rest of the task text, and project retention erases them once the task is older than the content lifetime of 30 days.
// Your ticket key and labels travel with the task; Work stores them and never interprets them.
const task = await board.tasks.create({
assigneeParticipantId: writer.id,
externalRef: 'JIRA:DOCS-1042',
metadata: { batch: '7', locale: 'ko-KR' },
spec: { title: 'Translate the setup guide', instructions: 'Translate the guide into Korean.' },
idempotencyKey: 'wts-docs-1042',
});
// task.externalRef === 'JIRA:DOCS-1042'; task.metadata.locale === 'ko-KR'.Agreement gate
A board can require one agreement to be active before anyone works on it, such as the master services agreement of a client engagement. Name the agreement and the digest of the terms you expect in requiresAgreement when you create the board, or set it with a board update; null clears it. Work asks the Agreements API in the same transaction, on every claim, renewal, resumption, submission and blocker read, whether the agreement is active. It never sees the parties, the terms or the evidence, and when the agreement is active again under the same digest, work continues with no write from you.
- Agreements must know the agreement under that terms digest, with a party in your project and environment, or the declaration gets
409 stale_reference. - The agreement may still be an offer, or a draft when your project holds its proposer, because only the proposer sees a draft.
| While the agreement is not active | What happens |
|---|---|
| Tasks | Every workable task shows the blocker agreement_not_active. |
| A new claim | 409 task_blocked |
| A held claim | Renewing, resuming and submitting get 409 task_blocked; observations, waits and release still work. Its standing.admissible is false, so Agents and Actions stop work that references it. |
| A submission pending review | Still decidable, because it was made while the agreement was active. |
| A service without Agreements | Declaring the gate gets 400 unsupported_capability, and a board that already declares one shows the blocker. |
// msa is the agreement your backend read from /v1/agreements: its id and the termsDigest both sides accept.
const engagement = await roye.work.boards.create({
displayName: 'client-engagement',
requiresAgreement: { agreementId: msa.id, termsDigest: msa.termsDigest },
idempotencyKey: 'wbd-engagement-1',
});
const contractor = await engagement.participants.create({ kind: 'human', displayName: 'contractor', grants: ['work'], idempotencyKey: 'wpa-contractor' });
// Until both parties sign, each workable task shows the blocker and a claim gets 409 task_blocked.
const ticket = await engagement.tasks.create({
assigneeParticipantId: contractor.id,
externalRef: 'CLIENT-42',
spec: { title: 'Fix the login redirect', instructions: 'Reproduce the bug and fix it.' },
idempotencyKey: 'wts-client-42',
});
ticket.blockedReasons.includes('agreement_not_active'); // true while the agreement is not active
// Clear the gate with null. The update takes the board's current revision.
await engagement.update({ requiresAgreement: null, expectedRevision: engagement.view.revision, idempotencyKey: 'wbd-engagement-ungate' });Contract 2 preview
Contract 2 adds fields and calls and removes nothing. Send Roye-Contract-Version: 2 on every contract 2 request; the response echoes it, and a request without it is contract 1.
/v1/capabilitieslists both versions aspreview,pinnable: false.roye.work.v2wraps the same calls; the participant SDK stays on contract 1.- Contract 1 refuses contract 2 fields and query parameters (
400 invalid_request). A key used under one version isidempotency_conflictunder the other.
Added fields
| View | Fields (`null` or absent when unused) |
|---|---|
| Board | companyBinding, contract2Only (true once the board has ever been bound), companyClosure |
| Participant | principalRef, appointmentRef (management view only) |
| Assignment | assignee.actorRef (actorId, appointmentRef), pinned at assignment |
| Task | cancelReason, blocked reason appointment_not_ready, the origin value controller (contract 1 tasks are always deliberate) and the controller record. A task the operating principal created has origin controller and a controller record naming its operating session, control revision and dispatch entry; other tasks have controller: null. |
| Goal | closeReason |
| Claim | holder.kind operating_principal, admittedControlRevision, carriedControlRevision |
| Submission and review | submittedBy, reviewer.attribution, reviewer.decidedVia, evidenceRefs[].digest |
New calls
The assignment list takes actorId, goal close takes an optional reason, and GET /goals/{wgl}/deliverables pages a goal's accepted tasks as exact artifact references with current Knowledge status, never content.
GET /v1/work/boards/wbd_…/assignments?actorId=<actorId>&state=active
Authorization: Bearer <management key>
X-Roye-Project: <projectId>
X-Roye-Environment: development
Roye-Contract-Version: 2
# 200, Roye-Contract-Version: 2
# { "items": [ { "id": "was_…", "state": "active",
# "assignee": { "participantId": "wpa_…", "actorRef": { "actorId": "…", "appointmentRef": { "appointmentId": "…", "revision": 1 } } }, … } ],
# "next": null }
POST /v1/work/goals/wgl_…/close
Roye-Contract-Version: 2
Content-Type: application/json
{ "idempotencyKey": "wgl-close-1", "expectedRevision": 3, "outcome": "achieved", "reason": "Shipped in the launch." }
# 200: the goal view with closeReason.Company-bound boards
Company Workspace binds boards, projects appointees as participants and closes boards after archiving, in process without HTTP routes. A board ever bound is contract 2 only: contract 1 lists omit it, and contract 1 requests on it or its records get 400 contract_version_unsupported.
- Each claim is checked against the company. A failed check sets
standing.admissibleto false, and Agents refuses or fails executions on the claim withstale_work_claim. - The operating principal creates tasks, assigns, claims for projected appointees and submits, in process.
| Condition | Claim and blocker | Meaning |
|---|---|---|
| Company not open | 409 company_not_active, blocker company_not_active | No claim is admitted. |
Company paused (mode not manual, starting or autonomous) | 409 company_not_active, blocker held_company_paused | Dispatch holds, keeping assignment, attempts and deadline. Held claims continue. |
| Projected appointment not hired and ready | 409 appointment_not_ready, same blocker | Assignees without a projected appointment are not checked. |
| Board closed after archiving | Open work ends cancelled (company_archived). No new tasks (409 company_not_active). | Work with an unresolved effect ends once it settles. A held claim may still submit; if it ends unsubmitted, the task is cancelled. Reviews decide as usual, but request_changes cancels. companyClosure shows progress. |
| Operating principal decides for a reviewer | decidedVia operating_principal, verified evidence digest | Must cite the reviewer's own completed Agents turn on this submission with that outputDigest, else stale_reference. |
Endpoints
Routes are under /v1/work; mutations take an idempotencyKey in the body. Key is the management key. Tokens need read to read, and write plus the named grant to write.
| Operation | Route | Credential |
|---|---|---|
| Boards | POST /boards, GET /boards[/{wbd}], POST /boards/{wbd}[/suspend|resume|delete], GET /boards/{wbd}/summary | Key. A token reads its own board and summary. |
| Events | GET /boards/{wbd}/events?cursor=&limit=&waitMs=: a polling page, waitMs up to 30 s, 7-day retention, no stream | Key or token |
| Participants | POST /boards/{wbd}/participants[/{wpa}[/suspend|resume|retire|grants]], GET /boards/{wbd}/participants[/{wpa}] | Key. A token reads the directory. |
| Tokens | POST, GET /boards/{wbd}/participants/{wpa}/tokens[/{wtk}], POST /tokens/{wtk}/revoke | Key |
| Goals | POST /boards/{wbd}/goals, POST /goals/{wgl}/revisions|close, GET /goals/{wgl}, GET /boards/{wbd}/goals, GET /goals/{wgl}/deliverables (contract 2) | Key or token (plan to write) |
| Tasks | POST /boards/{wbd}/tasks, POST /tasks/{wts}/revisions|cancel|dependencies, …/dependencies/{prerequisite}/remove; GET /tasks/{wts}, GET /boards/{wbd}/tasks|claimable | Key or token (plan to write) |
| Assignments | POST /tasks/{wts}/assignments, POST /assignments/{was}/reassign|withdraw; GET /assignments/{was}, GET /boards/{wbd}/assignments | Key or token (plan to write) |
| Claims | POST /tasks/{wts}/claims; GET /claims/{wcl}, GET /tasks/{wts}/claims?idempotencyKey= | Assignee token with work, or key for the assignee. Reads: holder or key. |
| Hold a claim | POST /claims/{wcl}/lease|wait|resume|release|observations | Holder, with its fence |
| Submit | POST /claims/{wcl}/submissions; GET /submissions/{wsb}, GET /tasks/{wts}/submissions | Holder. Reads: key or token. |
| Review | GET /boards/{wbd}/reviews/pending, POST /submissions/{wsb}/reviews; GET /reviews/{wrv}, GET /tasks/{wts}/acceptance | Key or token (review for the queue and decisions) |
| Effects | GET /tasks/{wts}/effects[/records[/{wef}]], POST /tasks/{wts}/effects/acknowledge|resolve | Reads: key or token. Writes: key. |
Limits
Preview values until measured costs set them.
| Limit | Value |
|---|---|
| Boards, participants, open tasks | 100 boards per project and environment. 1,000 participants and 10,000 open tasks per board. |
| Task spec | Instructions 32 KiB, text inputs 4 KiB. 32 inputs, 16 criteria, 16 capability references. |
| Dependencies | 32 prerequisites per task, depth 16. A graph check visits at most 512 tasks (dependency_limit). |
| Task bounds | Deadline 30 days (max 180), attempts 5 (max 20), rework rounds 3 (max 10), 20 reassignments. |
| Claims | Lease 30 s to 15 min. Active hold 24 h. A wait up to 7 days, 14 in total. 100 observations of 2 KiB. |
| Submissions | 16 artifacts, an 8 KiB completion report, 16 effect keys per claim. |
| Tokens | 1 hour by default, at most 24 hours. |
| Pages and replay | 32 items per page by default, at most 64. Replay window 7 days. |
Not in this preview: the automation controller, per-task spend, exports, retention purge of closed tasks, rate limits, token quotas and multiple reviewers.
Errors
Errors use the shared envelope.
| Code | HTTP | What to do |
|---|---|---|
invalid_request, payload_limit, bounds_exceeded | 400, 413 | Fix the input. |
contract_version_unsupported | 400 | Send a known version. Bound boards and contract 2 reads need Roye-Contract-Version: 2. |
unauthorized, credential_expired, credential_revoked | 401 | Get a new token from your backend. |
forbidden, separation_of_duties, reviewer_not_eligible | 403 | Use an eligible principal. There is no privileged fallback. |
not_found | 404 | Absent, or on another board or project. |
stale_claim, stale_assignment, stale_submission, stale_reference, revision_conflict, invalid_transition, task_busy, already_assigned, dependency_cycle | 409 | Re-read, then decide again with a new key. Never resubmit an old decision. |
idempotency_conflict | 409 | The key was reused with other input or version. Recover the original. |
artifact_unavailable | 409 | Cite a readable current revision, or request changes. |
task_blocked, board_not_active, participant_suspended, company_not_active, appointment_not_ready | 409 | Resolve the blocked reasons (and companyClosure on bound boards), resume, wait or reassign. |
attempts_exhausted, rework_limit, dependency_limit | 409 | Revise the bounds within limits, accept or reject, or cancel. |
quota_exceeded | 429 | A count limit is used up. Stay within it or cancel work. |
effect_unresolved | 409 | Management clears the effect. Never bypass it with a new task. |
cursor_expired | 410 | Re-read the state lists and restart from a fresh cursor. |
unavailable | 503 | Retry with the same key and input. |
Recovery
Save each idempotencyKey with its input before sending. After an uncertain call, resend the same intent with the same key, never a new one, or recover the original through POST /v1/operations/recover with the same credential.
| Situation | What happens and what to do |
|---|---|
| Lost claim | Same key and input, including the expected assignment: the original claim returns with its fence, inputs and current state, never a second attempt. |
| Lost submission or review | Same key: the original bytes return even after the task moved on. Any other decision is stale_submission. |
| Lost token issue | The replay has secretStatus not_replayable and no secret. Revoke the token and issue a new one with a new key. |
| Processor crash | The claim expires with its lease, and a new attempt follows, subject to the effect barrier. The old fence is refused. |
// Recover a lost claim with the worker's own client: recovery is scoped to the principal that sent it.
const original = await worker.operations.recover({
module: 'work',
kind: 'tasks.claims.create',
target: { taskId: outlineId },
idempotencyKey: 'claim-outline-1',
});Runnable example
apps/roye-api-examples/src/work/ runs this flow end to end, with rework, recovery and stale claims; see examples/README.md.