Skip to main content
Model a kit containing two mugs, then record production of three kits: one in the first batch and two in the second. Read the work order after each batch and inspect component and finished stock independently. This complete example uses @stateset/embedded 1.35.1 with a temporary local database. No API key, production equipment, or external warehouse service is required.
Work-order completion records production progress. In this example it neither consumes mug inventory nor adds finished kits to inventory. Those movements require a separate process with its own verification and recovery behavior.

Prerequisites

Use Node.js 20.20.0+ and npm 10+:
See SDK installation for native-module troubleshooting.

Run the complete example

Save this as manufacturing-demo.mjs:
Success: all assertions pass and the output is:

Understand the records and quantities

The component requirement for this example is six mugs: two per kit times three kits. That calculation describes the plan; it is not evidence that six mugs were reserved or consumed. The inventory assertions verify that no such movements happened in this program. Do not pass the cumulative total to the second completion call. The demonstrated calls add one and then two; passing three after the first batch would report another three units.

Define the production policy before automating

The example follows planned → in_progress → partially_completed → completed. This is the path it exercises, not a promise that the SDK rejects every invalid transition. In the published version, start accepts a cancelled work order. Enforce your allowed transitions and permissions in the application rather than assuming a cancelled job cannot restart. Before recording real production, verify the selected product, approved BOM revision, units of measure, material availability, accepted output count, and any required quality checks. Decide which system owns scrap, rework, lots/serials, and production evidence. The published Node WorkOrderOutput is a progress summary; it does not supply all of that operational evidence. Keep the BOM identity and revision with the production record. Do not treat the existence of an active BOM as proof that a specific production run passed review or that its materials are available.

Connect production to inventory

Choose the process that consumes components and receives finished goods, and retain its movement IDs alongside the work-order and batch IDs. Read both sides after processing. For this demonstration plan, a full run would require accounting for six mugs and three kits. Real counts can differ because of scrap or rework; record observed quantities under the configured policy rather than deriving all movements from the planned quantity. The inventory quickstart demonstrates adjustments, reservations, and read-back. Combining several adjustments with workOrders.complete does not make those calls an atomic manufacturing transaction. Design recovery for each partial outcome: Use connect your operation to map manufacturing, warehouse, and accounting ownership. Labor costing, machine telemetry, and quality-release integrations are outside this example.

Handle retries and concurrent writers

The published Node completion signature has no idempotency-key parameter, and completion quantities accumulate. Retrying a batch after a lost response can double-count production. Retain a durable batch/event identity, the work-order ID, additional quantity, and observed outcome in your integration. Read the work order and reconcile the original batch evidence before replaying a completion. A cumulative quantity alone may be ambiguous when several workers report progress. Coordinate writers for each work order; a separate read followed by a write is not an atomic guard. See error handling and retries and the integration test plan before unattended operation.

Give an agent a production task

Start with a read-only task: provide the work-order ID, BOM ID, and relevant inventory SKUs; ask for the target quantity, completed quantity, state, BOM components, and separately observed stock. Require the agent to identify missing material, quality, or movement evidence. For a write, specify the allowed transition, batch identity, additional accepted quantity, and authorization. Permission to record progress does not authorize changing the BOM, adjusting inventory, or releasing a quality hold. Discover the installed tool schemas rather than guessing MCP names from Node methods. Follow the agent operating procedure. Report production progress and inventory-posting status separately, with the IDs and read-back results supporting each outcome.

Troubleshooting

Next steps

Last modified on September 20, 2026