> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stateset.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Ecommerce Agent Workflows Guide

> Build a multi-agent order-to-cash pipeline with Shopify, NetSuite & DCL using StateSet's Agent & Workflow Frameworks.

# Ecommerce Agent Workflows

This guide shows how to orchestrate **Shopify → NetSuite → DCL** operations with *multiple autonomous AI Agents* powered by StateSet's **Agent Framework**, **Workflow Framework**, and **Agentic OS Connector**.

CTOs, Solutions Architects, and DevOps engineers building a resilient, observable, and fully-automated order-to-cash pipeline.

StateSet One platform orchestrates complex order operations by connecting various e-commerce and backend systems. This automation streamlines processes from order capture to fulfillment, inventory management, and customer service. Key benefits include:

* **Automated Order Flow:** Seamlessly move order data from Shopify to NetSuite and then to DCL for fulfillment.
* **Real-time Fulfillment Updates:** Keep Shopify and NetSuite synchronized with shipment and tracking information from DCL.
* **Inventory Accuracy:** Maintain consistent inventory levels between NetSuite, DCL, and Shopify.
* **Efficient Inbound Logistics:** Automate PO/ASN communication with DCL and item receipt processing in NetSuite.
* **Agentic Customer Service:** Enhance Gorgias with AI-powered responses and actions via integrations with Recharge and Shopify.
* **Centralized Orchestration:** Utilize StateSet for robust, observable, and scalable workflow management.

This guide focuses on the API-driven interactions orchestrated by the workflows defined in `workflows.js` and activities in `activities.js`.

***

## 1. Architectural Primer

| Layer                    | Purpose                                                                                                                                                       |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Agent Framework**      | Runs containerised agents that each own one business capability. Triggers → Preconditions → Actions → Post-conditions ensure deterministic, idempotent runs.  |
| **Workflow Framework**   | Declarative, version-controlled sequences of API calls with rollback, retries, and logging baked in. Every Agent owns a single Workflow implementation.       |
| **Agentic OS Connector** | A thin HTTP/gRPC façade that pushes normalised events into the Agent bus, manages secrets, schedules retries, and renders the cross-system **Work-Graph UI**. |

***

## 2. Catalog of Agents & Workflows

### Order Processing Tier

| # | Agent / Workflow            | Trigger        | Purpose                                                                             |
| - | --------------------------- | -------------- | ----------------------------------------------------------------------------------- |
| 1 | `shopifyToNetsuiteWorkflow` | Shopify Agent  | Convert Shopify Order → NetSuite Sales Order (SO); tag order `SENT_TO_NS`.          |
| 2 | `netsuiteToDCLWorkflow`     | NetSuite Agent | Transform SO and POST to DCL; set `custbody_sent_to_3pl = T`.                       |
| 3 | `dclTrackingUpdateWorkflow` | DCL Agent      | Create Item Fulfillment & optional Cash Sale in NetSuite; push tracking to Shopify. |

### Inventory Management Tier

| # | Agent / Workflow               | Trigger                                 | Purpose                                                        |
| - | ------------------------------ | --------------------------------------- | -------------------------------------------------------------- |
| 4 | `dclPoNotificationWorkflow`    | NetSuite PO/TO status `Pending Receipt` | Send ASN (Advance Ship Notice) to DCL.                         |
| 5 | `dclPoReceiptWorkflow`         | DCL Agent                               | Create Item Receipt, reconcile quantity, close PO if complete. |
| 6 | `inventorySyncWorkflow`        | Cron (\*/15 min)                        | Pull inventory from NetSuite, bulk update Shopify.             |
| 7 | `inventoryBundlesSyncWorkflow` | Cron (\*/15 min +10 sec)                | Compute bundle availability and update Shopify bundles.        |

### Financial Processing Tier

| # | Agent / Workflow      | Trigger                             | Purpose                                          |
| - | --------------------- | ----------------------------------- | ------------------------------------------------ |
| 8 | `netsuiteInvoiceFlow` | SO status `Pending Billing`         | Create Invoice, tag SO `INVOICED`.               |
| 9 | `netsuitePaymentFlow` | Invoice `Open` + payment settlement | Record payment, apply to Invoice, close Invoice. |

***

## 3. End-to-End Pipeline Walkthrough

```mermaid theme={null}
sequenceDiagram
    autonumber
    Shopify->>Agent 1: Order Created
    Agent 1->>NetSuite: Create Sales Order
    NetSuite-->>Shopify: SO ID & Tag
    NetSuite->>Agent 2: SO Approved
    Agent 2->>DCL: (Pick Pack Ship)
    DCL-->>Agent 3: Fulfillment + Tracking
    Agent 3->>NetSuite: Item Fulfillment / Cash Sale
    Agent 3->>Shopify: Fulfillment & Tracking
    NetSuite->>Agent 8: SO Pending Billing
    Agent 8->>NetSuite: Create Invoice
    Payment Gateway-->>Agent 9: Settlement File
    Agent 9->>NetSuite: Create & Apply Payment
```

***

## 4. Deployment & Operations

1. **Packaging** – Each Agent ships as a container invoking `agent run`.
2. **Versioning** – Semantic versions; upgrades spin a shadow copy replaying last 24 h of events before cut-over.
3. **Observability** – Logs & metrics stream to Grafana/Prometheus; Work-Graph UI renders lineage and retries.
4. **Error Handling** – Automatic exponential retries for idempotent calls; compensation jobs registered per Agent; Slack/E-mail hooks after N failures.

***

## 5. FAQ

**Q: Do I need all nine agents on day one?**\
No. Start with the Shopify→NetSuite workflow, then gradually enable the others as your operational maturity grows.

**Q: How are bundle quantities computed?**\
`inventoryBundlesSyncWorkflow` requests BOM data from NetSuite, then calculates `bundle_qty = MIN(component_qty[])`.

**Q: Can I extend this to Amazon or WooCommerce?**\
Yes—write a new Agent that maps their order schema to the canonical `OrderCreated` event expected by `shopifyToNetsuiteWorkflow`.

***

## 6. Triggering Workflows from the CLI

Once your Agents are deployed you can kick-off any workflow on demand via the **StateSet CLI** (a lightweight Node binary).

• **Single command** – `StateSet run --connector <workflow>` posts a JSON payload to the Agentic OS Connector REST endpoint.
• **Stateless** – The CLI simply packages your payload and returns the `workflow_id`; orchestration, retries and logging are handled by the platform.
• **Environment-driven** – Point to *prod*, *staging* or *local dev-tunnels* by changing the `STATESET_ENDPOINT` env variable or passing `--endpoint`.
• **CI/CD ready** – Works in GitHub Actions, CircleCI, or any shell, enabling synthetic orders during pipeline builds or bulk-replay of historical events.
• **Security** – Uses the same API tokens as the dashboard; no secrets are stored locally.

<Admonition type="tip" title="When to use the CLI vs. Webhooks?">
  Use the CLI for *backfills, migrations, on-demand tests or bulk operations.* Use webhooks or schedules for real-time and recurring automation.
</Admonition>

***

## Next Steps

1. Read the <Link href="/guides/agents-quickstart">Agents Quickstart</Link> to understand core Agent APIs.
2. Explore <Link href="/guides/order-operations">Order Operations</Link> for advanced order-management patterns.

Happy automating! 🚀
