Use Workforce from code and agents
Everything you can do in the dashboard you can do from code: with the HTTP API, the TypeScript SDK, the toolkit (ptkl), or, from an AI coding assistant, the MCP server.
Decisions on waiting runs (approve, deny, answer) are for people. See People in the loop.
The API
Paths below are relative to the Kortex API of your project; the SDK and ptkl add the base for you. Authenticate as for any Kortex route, with a user or API user whose permissions include the one in the table. Errors are { "status": false, "code": <http status>, "message": "..." }. Lists answer { "data": [...], "total": n, "page": n, "limit": n } and take page and limit (limit at most 100, default 20).
Permissions: R workforce::read, M workforce::manage, A workforce::approve. See Permissions.
Playbooks and versions
| Route | Perm | Purpose |
|---|---|---|
GET /playbooks |
R | List playbooks |
POST /playbooks |
M | Create (also creates the first version) |
GET /playbooks/{uuid} |
R | Read one (dev_version, live_version) |
PATCH /playbooks/{uuid} |
M | Replace name, description, run limit |
DELETE /playbooks/{uuid} |
M | Delete (refused while in use) |
GET /playbooks/{uuid}/versions |
R | List versions |
POST /playbooks/{uuid}/versions |
M | New version, copied from another |
GET /playbooks/{uuid}/versions/{version} |
R | Read a version |
PATCH /playbooks/{uuid}/versions/{version} |
M | Save the drawing |
POST /playbooks/{uuid}/versions/{version}/validate |
R | List validation problems |
POST /playbooks/{uuid}/deploy |
M | Deploy a version to dev or live |
POST /playbooks/{uuid}/rollback |
M | Roll an environment back |
GET /playbooks/{uuid}/deployments |
R | Deploy history |
Runs
| Route | Perm | Purpose |
|---|---|---|
POST /playbooks/{uuid}/runs |
M | Start a playbook run |
POST /agents/{uuid}/runs |
M | Start a free run of one agent |
POST /runs/{uuid}/rerun |
M | Repeat a run |
GET /runs |
R | List runs (filters in Deploy and run) |
GET /runs/running |
R | Runs in flight |
GET /runs/stats |
R | Run statistics (days, tz: an IANA zone such as Europe/Belgrade, default UTC; days are counted in it) |
GET /runs/{uuid} |
R | A run with its steps (after) |
GET /runs/{uuid}/steps/{index} |
R | One step in full (1-based) |
POST /runs/{uuid}/pause |
M | Pause |
POST /runs/{uuid}/resume |
M | Resume |
POST /runs/{uuid}/kill |
M | Kill |
POST /workforce/stop-all |
M | Stop everything |
POST /workforce/release-all |
M | Lift stop-everything |
GET /workforce/controls |
R | Is stop-everything on |
People in the loop
| Route | Perm | Purpose |
|---|---|---|
GET /approvals |
R | What waits on a person (kind) |
POST /runs/{uuid}/steps/{index}/approve |
A | Approve a tool call |
POST /runs/{uuid}/steps/{index}/deny |
A | Deny it (reason required) |
POST /runs/{uuid}/steps/{index}/answer |
R | Answer a question |
Agents at work and assignments
| Route | Perm | Purpose |
|---|---|---|
GET /workforce/agents |
R | Agents with Workforce settings |
POST /agents/{uuid}/workforce |
M | Put an agent to work (settings in body) |
GET /agents/{uuid}/workforce |
R | Read its settings |
PATCH /agents/{uuid}/workforce |
M | Replace its settings |
DELETE /agents/{uuid}/workforce |
M | Turn it off (keeps the settings) |
POST /agents/{uuid}/workforce/activate |
M | Set active |
POST /agents/{uuid}/workforce/pause |
M | Set paused |
GET /agents/{uuid}/workforce/probation |
R | Where each data-changing tool stands on probation |
GET /skills |
R | The tools that can be granted |
GET /workforce/forge-tools |
M | App tools that can be granted |
GET /assignments, GET /agents/{uuid}/assignments |
R | List assignments |
POST /assignments, POST /agents/{uuid}/assignments |
M | Create |
GET, PATCH, DELETE /assignments/{uuid} |
R, M, M | Read, replace, delete |
POST /assignments/{uuid}/activate, /pause |
M | Switch on or off |
POST /assignments/{uuid}/run |
M | Fire now |
GET /assignments/{uuid}/projection, POST /assignments/projection |
R | Estimate a schedule's idle cost |
{uuid} of an agent route also accepts prota, the built-in agent.
Feedback, rules and reports
| Route | Perm | Purpose |
|---|---|---|
POST /runs/{uuid}/feedback, GET /runs/{uuid}/feedback |
R | Judge a run or step; list judgements |
PATCH /feedback/{uuid} |
R | Change your own judgement |
DELETE /feedback/{uuid} |
R | Remove it (author, or workforce::manage) |
POST /feedback/{uuid}/use |
M | Use it or Stop using it ({ "on": true }) |
GET /playbooks/{uuid}/feedback/summary, GET /assignments/{uuid}/feedback/summary |
R | How a playbook or an assignment is judged |
GET /playbooks/{uuid}/feedback |
R | Judgements on a playbook's runs (node, limit) |
GET /assignments/{uuid}/feedback |
R | Judgements on an assignment's runs (limit) |
GET /feedback/export |
R | Export judgements as JSON Lines (agent, from, to, cursor) |
POST /feedback/{uuid}/promote |
M | Make a correction a rule of a playbook version or an assignment (201) |
GET /activity, GET /activity/export |
R | The activity ledger |
GET /workforce/costs |
R | What agents cost |
Reports and checks
| Route | Perm | Purpose |
|---|---|---|
GET, POST /workforce/reports/subscriptions |
R | List your reports, ask for one |
PATCH, DELETE /workforce/reports/subscriptions/{uuid} |
R | Change or stop one |
POST /workforce/reports/opt-outs, POST /workforce/reports/unsubscribe |
R | Stop a default report; follow an email's stop link |
GET /playbooks/{uuid}/versions/{version}/replays/estimate |
R | Estimate a check before going live |
POST, GET /playbooks/{uuid}/versions/{version}/replays |
M, R | Start a check; list the checks of a version |
GET /playbooks/{uuid}/versions/{version}/replays/{replay} |
R | One check with its cases |
POST /playbooks/{uuid}/versions/{version}/replays/{replay}/cancel |
M | Cancel a check |
The SDK
@ptkl/sdk (the @ptkl/sdk/beta entry point) exposes Workforce on the Kortex client, platform.kortex(). Each method maps to one route above and carries its required permission in its JSDoc. Types are exported with a Workforce prefix (WorkforceGraph, WorkforceNode, WorkforceEdge, WorkforceRun, ...).
import { Platform } from '@ptkl/sdk/beta'
const kortex = new Platform().kortex()
const { data: playbook } = await kortex.createPlaybook({ name: 'Invoice check' })
await kortex.savePlaybookVersion(playbook.uuid, '0.1.0', {
graph: { nodes: [/* ... */], edges: [] },
note: 'First draft',
})
const { data } = await kortex.validatePlaybook(playbook.uuid, '0.1.0')
if (data.problems.length === 0) {
await kortex.deployPlaybook(playbook.uuid, { version: '0.1.0', env: 'dev' })
const { data: run } = await kortex.startPlaybookRun(playbook.uuid, {
env: 'dev',
instructions: 'Check invoice INV-2041.',
input: { invoice_id: 'INV-2041' },
})
const { data: detail } = await kortex.getRun(run.uuid) // { run, steps }
}
Read a run's result
A playbook whose last step has a result schema returns data. Read it from the run once it has ended. result is keyed by last-step id and is absent when no step has a schema.
const { data: detail } = await kortex.getRun(run.uuid)
if (detail.run.status === 'completed') {
const reply = detail.run.result?.reply as { priority: string; text: string } | undefined
console.log(reply?.priority, reply?.text)
} else if (detail.run.stop_reason === 'result_invalid') {
// The agent did not return the shape the playbook asks for.
console.error(detail.run.error_message)
}
| Area | Methods |
|---|---|
| Playbooks | listPlaybooks, createPlaybook, getPlaybook, updatePlaybook, deletePlaybook, listPlaybookVersions, createPlaybookVersion, getPlaybookVersion, savePlaybookVersion(uuid, version, { graph, note }), validatePlaybook(uuid, version) (returns { problems }), deployPlaybook(uuid, { version, env }), rollbackPlaybook(uuid, { env }), listPlaybookDeployments |
| Runs | startPlaybookRun(uuid, { env, instructions?, input? }), startAgentRun, rerunRun, listRuns, listRunningRuns, getRunStats, getRun(uuid) (returns { run, steps }), getRunStep(uuid, index) (1-based), pauseRun, resumeRun, stopRun |
| People in the loop | listApprovals({ kind }), approveStep, denyStep, answerStep |
| Agents | listWorkforceAgents, enableWorkforce, getWorkforce, updateWorkforce, disableWorkforce, activateWorkforce, pauseWorkforce |
| Skills | listSkills, listForgeTools |
| Assignments | listAssignments, listAgentAssignments, createAssignment, createAgentAssignment, getAssignment, updateAssignment, deleteAssignment, activateAssignment, pauseAssignment, fireAssignment, getAssignmentProjection, previewAssignmentProjection |
| Feedback | createRunFeedback, listRunFeedback, updateFeedback, deleteFeedback, setFeedbackUse, promoteFeedback, getPlaybookFeedbackSummary, listPlaybookFeedback, getAssignmentFeedbackSummary, listAssignmentFeedback |
| Reports | listActivity, getAgentCosts |
| Emergency | stopAllRuns, releaseAllRuns, getControlStatus |
stopRun is the SDK's name for the kill route.
The toolkit
ptkl kortex playbook manages playbooks as files. Commands that take a playbook use -u, --uuid; --env is dev or live and defaults to dev. See also ptkl kortex.
| Command | What it does |
|---|---|
list [-p <page>] [-l <limit>] |
List playbooks. |
get -u <uuid> |
Show a playbook and which version runs in dev and in live. |
versions -u <uuid> |
List its saved versions. |
pull -u <uuid> [--version V] [-o file] |
Write the playbook to a JSON file { uuid, name, description, version, graph }. Without --version it takes the version deployed to live, else dev, else the newest. Without -o it prints to stdout. |
validate [-f file] [-u uuid --version V] |
Check a file for problems offline. With -u and --version it also asks the server about that saved version, which catches missing or disabled agents. Exits 1 when there are problems. |
push -f file [-u uuid] [--version name] [--note text] |
With no uuid (none given and none in the file) it creates the playbook, which needs a name in the file. Otherwise it saves the file as a new version of that playbook. A file with problems is refused and nothing is pushed. |
deploy -u <uuid> --version V --env dev\|live |
Deploy a version. |
rollback -u <uuid> --env dev\|live |
Go back to the previous version in that environment. |
deployments -u <uuid> [-p] [-l] |
List deploys and rollbacks. |
run -u <uuid> [--env dev\|live] [--instructions text] [--input file.json] [--wait] [--interval s] [--timeout s] |
Start a run of the version deployed to --env. --input is a JSON file passed to the run as input. |
runs [--playbook uuid] [--status s] [-p] [-l] |
List runs, newest first. |
run-get -u <run uuid> |
Show a run with its steps. When the run has a result, it is printed in full as JSON first; the exit code is 1 for a run that ended result_invalid. |
push names a new version itself: the newest version's patch number plus one (0.1.0 becomes 0.1.1). Pass --version only to choose the name, or when the newest name is not MAJOR.MINOR.PATCH.
Exit codes of run --wait
With --wait, run polls every --interval seconds (default 3, at least 1) until the run ends or needs a person, then prints the outcome.
| Exit code | Meaning |
|---|---|
0 |
The run completed. |
1 |
The run failed (including stop reason result_invalid), was stopped, timed out, or expired because nobody decided in time. |
2 |
The run needs a person: it is awaiting_approval, awaiting_answer or paused. The output names the step that is waiting. |
3 |
--timeout was reached while the run was still going (--timeout 0, the default, waits without limit). |
Playbooks as files
# 1. Pull the live version into a file
ptkl kortex playbook pull -u $PLAYBOOK -o invoice-check.json
# 2. Edit the "graph" in your editor, then check it
ptkl kortex playbook validate -f invoice-check.json
# 3. Save it as a new version (the server check also catches agent problems)
ptkl kortex playbook push -f invoice-check.json -u $PLAYBOOK --version 0.2.0 --note "Flag mismatches"
ptkl kortex playbook validate -u $PLAYBOOK --version 0.2.0
# 4. Deploy to dev and run it, waiting for the result
ptkl kortex playbook deploy -u $PLAYBOOK --version 0.2.0 --env dev
ptkl kortex playbook run -u $PLAYBOOK --env dev --instructions "Check invoice INV-2041." --wait
# 5. When it behaves, deploy the same version to live
ptkl kortex playbook deploy -u $PLAYBOOK --version 0.2.0 --env live
When the run returns a result, run --wait prints it as JSON after the summary, so a script can read it:
ptkl kortex playbook run -u $PLAYBOOK --env dev --wait
ptkl kortex playbook run-get -u $RUN_UUID -f jsonpath --template '$.run.result.reply'
In a script or CI job, run --wait gives you the outcome as an exit code. Exit code 2 means a person has to approve or answer; see People in the loop.
The MCP server
The MCP server gives AI coding assistants such as Claude Code or Cursor tools to build and run playbooks. The tools act as the person who connected, with that person's permissions.
Tools that change things or start work ask for confirmation: deploy, rollback, starting a run, approving or denying, and activating or running an assignment.
| Area | Tools |
|---|---|
| Playbooks | workforce_playbook_list, workforce_playbook_get, workforce_playbook_create, workforce_playbook_version_create, workforce_playbook_version_save, workforce_playbook_validate, workforce_playbook_deploy, workforce_playbook_rollback, workforce_playbook_deployments, workforce_rule_check |
| Runs | workforce_run_start, workforce_run_list, workforce_run_get, workforce_run_step_get |
| People in the loop | workforce_waiting_list, workforce_approval_decide, workforce_question_answer |
| Agents | workforce_agent_list |
| Feedback | workforce_feedback_create, workforce_feedback_list, workforce_feedback_use, workforce_feedback_promote, workforce_playbook_feedback_summary, workforce_playbook_feedback_list, workforce_assignment_feedback_summary, workforce_assignment_feedback_list |
| Assignments | workforce_assignment_list, workforce_assignment_get, workforce_assignment_create, workforce_assignment_update, workforce_assignment_activate, workforce_assignment_pause, workforce_assignment_run, workforce_assignment_preview |
The feedback tools beyond writing and reading a run's feedback:
workforce_feedback_usedecides whether a piece of feedback is given to later runs of its step:ontrue is Use it, false is Stop using it. Needsworkforce::manage.workforce_feedback_promotemakes a piece of feedback a standing rule, on a playbook version or an assignment. Needsworkforce::manage.workforce_playbook_feedback_summaryshows how a playbook is doing: per step the good and bad judgements, counts by category and the tools judged worst, and the same for whole runs.workforce_playbook_feedback_listlists the feedback on all runs of a playbook, newest first, optionally only on one step (node).workforce_assignment_feedback_summaryshows the same summary for an assignment.workforce_assignment_feedback_listlists the feedback on all runs of an assignment, newest first.
Changing an agent's tools and approval settings, deleting playbooks, are done in the dashboard, not through MCP.
The same MCP server also has the Kiln tools, so an assistant can lease machines to build and run code.
Assignments through MCP
The assignment tools manage standing work, with the same rules as the assignment API:
workforce_assignment_list(filter by agent or playbook) andworkforce_assignment_get. The next run time isnext_run_atonget.workforce_assignment_createandworkforce_assignment_update. Give exactly one ofagent_uuidorplaybook_uuid. A trigger is manual (no schedule fields) or a schedule with exactly one ofevery_minutes(at least 5) or a five-fieldcron.overlapisskip,queueorallow. Update replaces every field, so read the assignment first. A new assignment starts paused.workforce_assignment_activateandworkforce_assignment_pauseswitch the schedule on and off.workforce_assignment_runfires it now. All three ask for confirmation.workforce_assignment_previewprices a schedule before you activate it:checks_per_day,idle_runs_30d,avg_idle_credits,projected_idle_credits_per_day. Give a savedassignment_uuid, or a trigger and one ofagent_uuidorplaybook_uuid.
The format an assistant must follow
An assistant that builds a playbook through MCP follows the same rules as everyone else; see Build a playbook for the detail.
- Three step kinds:
instruction,conditionandtool(a step that makes its agent use one named tool, set intool). Approvals and questions are not steps. - Exactly one start, and lines only go forward (no loops).
- A condition has two or more lines out, each with a unique name. A condition may instead decide by rules (
decide_by: "rules"): no agent, and every line carries awhenrule overinputorotherwise: true; see the Rules reference.workforce_rule_checktries one rule. - Instruction steps fan out: every line out is followed, in parallel.
- A step with several lines in starts once all of them were followed or ruled out, and at least one was followed.
- At most 200 steps, 400 lines, 8000 characters of step text and 200 characters of title.
- Run duration 60 to 86400 seconds (default 1800). Version names are 1 to 64 characters of letters, digits, dot, underscore or dash, starting with a letter or digit (default
0.1.0). - A run only starts in an environment the playbook is deployed to.