What is a binding
A binding is something the platform runs for you, handed to your code on ctx. You don’t create the database, set up the SMS account, or hold the API keys. You call the binding, and the platform does the work with your organization’s storage and credentials.
Storage
| Binding | What it holds | Shared by |
|---|---|---|
ctx.USER | The people your loops serve: metadata, memory, and their scans. | Every loop in the organization |
ctx.FACIAL_SCAN | The face scan for this run: the link, the results, and the PDF. | One run |
Messaging
| Binding | What it sends |
|---|---|
ctx.SMS | Text messages, one or up to 500 at a time. |
ctx.WHATSAPP | WhatsApp text and approved templates, from your own number. |
ctx.EMAIL | Email from your verified domain, with replies going to the loop’s agent. |
Commerce
| Binding | What it reaches |
|---|---|
ctx.SHOPIFY | Your connected store’s products, orders, customers, subscriptions, and discounts. |
Where ctx is
ctx is passed to every step.do. A binding call inside a step is saved with the step, so a replay doesn’t repeat it.
import { workflow } from "@loops/sdk";
type Welcome = { patientId: string; name: string };
export const welcomeWorkflow = workflow<Welcome>({
id: "welcome",
execute: async ({ step, event }) => {
await step.do("Save the patient", async ({ ctx }) => {
const user = await ctx.USER.getUser({ id: event.body.patientId });
await user.setMetadata({ name: event.body.name });
});
},
});Bindings are not on ctx anywhere else. Code at the top of execute, outside a step, can run again on replay, so a message there could be sent twice.
An agent’s tools don’t get ctx. An agent reaches a binding by starting a workflow from a tool. See Calling a workflow.
Turning bindings on
A loop can call only the bindings switched on in its Controls. Calling one that is off throws, for example SMS is off for this loop. Turn it on under Controls → Tools. Sending to many people, refunds, and discounts can also be set to wait for a person’s approval.