Trace: craft Operations-aligned work
Document information
- Canonical URL:
/docs/12_workflows/30_trace-crafting-operations-aligned-work - Version:
2026-10-09 - Tags:
operations,trace,processflow,integrations,webapps,guides
Use this guide when Trace (or another AI author) proposes integrations, ProcessFlows, WebApps, or step code that should appear in Operations My Work. Follow the same contract as tenant admins. Do not redesign the Tenant Admin Console and do not seed demo tasks into employee queues.
Non-negotiables
- Prefer
tf.operations.createApprovalGate, thenopenApproval/openAction/openException/updateProgress/complete, over rawapi.put("/api/v1/operations/requests", …)unless the user asks for a custom payload. - Never set
attention: "approval"without thehuman_request_idreturned bytf.operations.createApprovalGatewhile that gate is stillpending. Do not invent the id. Do not callrequest_human_inputto obtain it. - Set process
categorytobusinesswhen the run should appear under operator Processes (/runs). - Install path for the schema is My Work Prepare request model or
POST /api/v1/operations/request-model— not a demo DataPool seed of requests. - Empty My Work is correct until real systems write rows.
When proposing a ProcessFlow
Ask / decide:
- What event starts the case (connector webhook, schedule, WebApp)?
- Which steps are Automatic vs AI-assisted vs Human?
- Which human step is Approval vs Action required vs Exception recovery?
- What stable
external_ididentifies the case across upserts? - What copy answers
why_visibleandconsequencefor the employee?
Scaffold pattern
1. Trigger / intake (integration or WebApp → process.execute)
2. Automatic enrich (connectors) + tf.operations.updateProgress
3. Optional AI prepare → ai_summary
4. Human gate:
- Approval → tf.operations.createApprovalGate, then tf.operations.openApproval({ human_request_id, owner_user_id }), then return
- Action → tf.operations.openAction({ required_action })
5. Write-back to systems on continue
6. On failure → tf.operations.openException
7. Done → tf.operations.complete
Validate drafts with tf.operations.validate(payload) and check approve_buttons_would_show.
When proposing integrations
- Map connector fields to My Work enrichment (
party,system_refs,checks), not to a parallel task table. - Keep secrets in ProcessFlow Keystore / integration credentials.
- Surface employee-safe error text in
required_action, never stack traces on the primary panel.
When proposing WebApps
- WebApp collects input and starts or resumes a process.
- Process owns My Work upserts.
- Document the POST → process → work-kind path for the tenant admin.
Response style for Trace
When explaining to the user:
- Name concrete helpers (
tf.operations.createApprovalGate,tf.operations.openApproval) and fields (human_request_id,approver_user_id,idempotency_key,owner_user_id). - Distinguish Tenant Admin (design) from Operations (employee control surface).
- Cite Library URLs under
/docs/12_workflows/…. - If approval UX would be broken, say so before shipping the snippet.
Approval contract Trace must follow
Write this sequence in the TypeScript step. Both calls need sandbox capability api.
const gate = await tf.operations.createApprovalGate({
idempotency_key: "warranty-approval-ada@example.com-sn-100",
approver_user_id: approverUserId,
prompt: "Create a CRM contact for Ada Lovelace?",
timeout_seconds: 604800,
payload: {
name: "Ada Lovelace",
company: "Analytical Engines",
phoneNumber: "+1-555-0100",
email: "ada@example.com",
product: "Widget",
serialNumber: "SN-100"
},
continuation: {}
});
if (gate.status !== "pending") {
return {
success: true,
data: { status: gate.status, decision: gate.decision, human_request_id: gate.human_request_id }
};
}
await tf.operations.openApproval({
external_id: "warranty-ada@example.com-sn-100",
subject: "Approve CRM contact for Ada Lovelace",
process_name: "Warranty registration",
human_request_id: gate.human_request_id,
owner_user_id: approverUserId,
details: [
{ label: "Name", value: "Ada Lovelace" },
{ label: "Company", value: "Analytical Engines" },
{ label: "Phone", value: "+1-555-0100" },
{ label: "Email", value: "ada@example.com" },
{ label: "Product", value: "Widget" },
{ label: "Serial number", value: "SN-100" }
],
why_visible: "You approve new CRM contacts from warranty registration.",
consequence: "Approving starts the next run, which writes the CRM contact.",
required_action: "Approve or reject creating this contact."
});
return {
success: true,
data: {
status: "pending_approval",
human_request_id: gate.human_request_id,
external_id: "warranty-ada@example.com-sn-100"
},
message: "Registration received. An approver will review the new contact."
};
createApprovalGate request fields:
| Field | Rule |
|---|---|
idempotency_key | Required, 1–191 characters. The same key returns the existing gate. |
approver_user_id | Required active internal tenant user with Operations access. Not the WebApp execution user. |
prompt | Required, 1–4000 characters. |
payload | Optional object, max 32000 bytes. |
continuation | Omit to store the decision only. {} continues this process. { process_id } continues that process in the same tenant. |
timeout_seconds | Optional integer from 60 to 2592000. Omit it to wait until accept or deny. |
Response data includes human_request_id (phg_<uuid>), status (pending, answered, timeout), decision (approved, denied, or null), created (false when the key already existed), approver_user_id, and expires_at.
openApproval sends PUT /api/v1/operations/requests with strict: true. It fails unless that id is still pending. Keep external_id stable. Set owner_user_id to approver_user_id.
If openApproval throws, return success: false with human_request_id and idempotency_key. The retry calls createApprovalGate with the same key, then openApproval again while status is pending. After timeout, a new decision needs a new idempotency_key.
My Work Approve posts { "approved": true } to POST /api/v1/operations/human-gates/{human_request_id}/respond. Reject posts { "approved": false }. Only approver_user_id succeeds. A second response is HTTP 409. The click records the decision and does not write CRM. continuation: {} starts one new execution of this process with process_input.operations_continuation. Branch on that object before intake. Omit continuation to store the decision only. A resubmit after denial uses a new idempotency_key.
A matched CRM contact returns before createApprovalGate. CRM reads use tf.connector.execute after describe_tenant_integration.