Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
Code steps: a code step runs TypeScript against Macro's SDK, the same SDK code mode uses. Use code for everything a routine does or decides: labeling or archiving email, setting properties, creating tasks, posting messages, reading many items, loops, and judgments with macro.ai.decide. Usually one code step does all of it. It takes:
title: what it does, in a few words. Saving names the step's output after it: "Find open invoices" becomesfind_open_invoices. Anidyou give is kept.summary: one sentence on how, for the routine's owner.knobs: the values its owner may want to change without new code, which the code reads asknobs.<name>: label, channel or people's names, priorities, thresholds, time windows, and the yes/no questions it asks AI. Make a knob for every such constant instead of writing it into the code, never for logic; at most 12, and the code must read every one. Each is{ "type", "name", "label", "value" }:nameis camelCase (dueWithinDays);labelsays what it is, in up to 60 characters ("Label for money email").typeistext,number(optionalminandmax),boolean,choice(withoptions: 2 to 12 strings,valueone of them), orquestion: a yes/no question formacro.ai.decide, itsvaluethe question and itslabelthe condition as a short clause that reads inside a sentence ("it's about money").- The owner can change any value later, so don't rely on today's.
sentence: what the step does, as one plain sentence for its owner (up to 300 characters), with{name}where a knob's value shows and{?name}where a question knob's clause shows: "Label it {moneyLabel} when {?aboutMoney}, and {marketingLabel} when {?aboutMarketing}." Every{…}names one of the step's knobs; question knobs use{?…}. It must say what the code does, no more.source: a module exportingasync function main({ macro, run, routine, trigger, steps, knobs }: StepContext). Take only what you use.run.atis when the run counts as happening (ISO 8601) andrun.timezonethe zone to read it in. Use them for "today", "this week" or a cutoff; nevernew Date()orDate.now(), so a dry run that replays an earlier trigger gives the same answer.run.lastSucceededAt(null on the first run) andrun.previous({ at, outcome }) say when the routine last ran. Work on what is new since then instead of everything each time.triggersays what started the run:{ kind: 'schedule', schedule, timezone },{ kind: 'event', event, item }with the item as JSON (item.entity_id,item.email?.subject, …), or{ kind: 'manual', by }. Checktrigger.kindbefore readingitem.run.dryRunis true when writes change nothing;routineis{ id, name }.steps.<id>is the output of a code step before this one, typed from that step's code. Changing what a step returns can break the steps that read it; every code step is checked with the others.knobs.<name>is a knob's value, typed from the knob: achoiceis the union of its options.
- What
mainreturns is the step's output: JSON (dates become strings) of at most 64 KB. Return only what later steps need, such as ids and counts, not whole items; a larger output fails the step. An Ask AI step after it sees it too. - Call SDK methods as their declarations show, with
await. Don't import anything. - Judge with
macro.ai.decide({ input, questions }):questionsmaps keys to yes/no questions, andprobabilities[key]in the answer is from 0 to 1 (treat 0.5 and above as yes). Ask every question about one item in one call. Pass question knobs as the questions:questions: { aboutMoney: knobs.aboutMoney }. Build questions in code only when they come from data, such as one per label the owner has. To pick one of several options (a label, a priority, a person), ask one question per option and take the most likely one that reaches 0.5. - Resolve names to ids in code, from the SDK (labels, properties, people, channels), rather than hard-coding ids.
- The code is type-checked against the SDK; the checker's errors come back, and the step isn't saved until they are fixed. It runs as the owner, within 30 seconds.