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

# Loops

# Loops

**Loops** are the atomic unit of the Better Data platform: governed workflows with **actor attribution**, **guard enforcement**, **evidence**, and an **audit trail**.

## What is a loop?

A loop is a **finite state machine** with governed transitions. Every transition:

* Names the **actor** responsible (`human` | `automation` | `ai-agent`)
* Evaluates **guard policies** before the transition is allowed
* Attaches structured **evidence** (documents, scans, confidence scores)
* Emits an **immutable audit event** (who / what / when / correlation id)

Guards are enforced in the **runtime and policy layer** — not by prompt instructions alone.

## Agents and Loop Engine (C12)

**Agents** (in the commerce sense) are **not** a separate product or autonomous AI platform. They **use Loop Engine to govern** decisions after **Registry** discovery and **Gateway** execution — the same control plane as human and automation actors.

* **Never** describe agents as an “agent system” separate from the gateway, or as a standalone agent product.
* **Always** tie agent behavior to **Registry → Gateway → Loop Engine** and, for illustration, [Commerce Demo](/getting-started/introduction) governed mode or [Build an agent](/guides/build-an-agent).

## Hosted loop engine

Better Data operates a hosted loop runtime at **[loops.betterdata.co](https://loops.betterdata.co)**. Compared to self-hosting `@loop-engine/sdk`, hosted adds:

* Multi-tenant **organization isolation**
* **Metering** aligned to loop outcomes
* **Industry Pack** policy overlays
* **TenantCapabilitySnapshot**-driven RBAC
* **Drift detection** workers
* **Outbox relay** for cross-module delivery
* Managed **upgrades** and **SLA**

**OSS:** [loopengine.io](https://loopengine.io) · `@loop-engine/sdk`\
**Hosted:** [Hosted Loop Engine](/hosted/loops) · [hello@betterdata.co](mailto:hello@betterdata.co)

## Loop types in the CCO platform

| Loop ID             | Module | What it governs                           |
| ------------------- | ------ | ----------------------------------------- |
| `scm.procurement`   | SCM    | PO lifecycle, receipts, invoice alignment |
| `scm.fulfillment`   | SCM    | Reservation → pick/pack/ship              |
| `scm.quality`       | SCM    | Inspection, deviation, disposition        |
| `scm.replenishment` | SCM    | Demand-driven reorder                     |
| `dcm.demand`        | DCM    | Demand signals and replenishment triggers |
| `dcm.order`         | DCM    | Order confirmation, allocation, shipment  |
| `dcm.returns`       | DCM    | RMA, receipt, credit, restock             |

Canonical IDs and events ship in [`@loop-engine/definitions`](/oss/loop-definitions).

## Actors and guards

Each transition declares:

* **allowedActors** — who may initiate or approve
* **guards** — e.g. confidence thresholds, human-only steps, evidence-required gates

When a guard fails, the loop **does not advance**; the runtime records the denial for audit.

## Audit trail

Each transition emits a **LoopTransitionedEvent**-shaped record: actor, signal, from/to state, evidence payload, timestamp, **correlationId**.\
The hosted platform aggregates these into operational dashboards and **compliance exports**.

→ [Audit trail](/platform/audit-trail)

## Self-host vs hosted

|         | OSS                                    | Hosted                                             |
| ------- | -------------------------------------- | -------------------------------------------------- |
| Runtime | `@loop-engine/sdk`                     | [loops.betterdata.co](https://loops.betterdata.co) |
| Contact | [loopengine.io](https://loopengine.io) | [hello@betterdata.co](mailto:hello@betterdata.co)  |
