A workflow file is a declaration of blocks and connections, not a program. Sim reads it statically and never runs it, so the file holds a fixed set of forms. This page lists them. A form outside it is refused with E_UNSUPPORTED_SYNTAX and a hint that names the supported form. The types for every builder are in .sim/sdk/ after a get, and sim workflows source params <builder> prints one builder's params.
An example
A webhook receives a ticket, an agent classifies it, billing tickets are logged to a table, and the team hears about every ticket in Slack. This is the file sim workflows source get prints for it:
How to read it:
- Each
constis a block.agent,condition,table.insertRow, andslack.sendMessageare the blocks you know from the workflow builder, with the same settings. classify.categoryis a typed reference to another block's output, the same as<classify.category>in the builder.twrites text with references in it;jswrites code.table('tickets')andcredential('support-slack')name workspace resources by a stable key. Renaming the table in Sim keeps the key.env.TICKETS_WEBHOOK_TOKENreads an environment variable. Secret values are never printed: a key pasted into a password field prints asstored(), which keeps the saved value..to()connects blocks,byCategory.billingis one branch of the condition, and.onError()follows the error path.notifyhas three incoming edges and runs once, after the branch that was taken.- A webhook answers its caller as soon as the request is accepted and runs the workflow in the background, so the caller never sees a
responseblock's output.responseMode: 'custom'sets that fixed answer (here202with{ "ok": true }; without it,200with{ "message": "Webhook processed" }). To answer with values the run computes, start the workflow withtrigger.startand call it through the API; aresponseblock then sets what the caller receives.
The file
- Line 1 is
// @sim-sdk N. Without it the file is refused withE_SDK_HEADER; a number other than the one the server reads isE_SDK_MAJOR. - Imports are named imports from
'@sim/workflow-sdk'only. Aliases are allowed. - The file has exactly one
export default workflow(name, options?, body)(E_WORKFLOW_EXPORT).optionsis{ description?, variables? }.bodyis() => { … }or({ vars }) => { … }. - Variables are
variables: { <key>: { name?, type, value } }.typeisstring,number,boolean,object,arrayorplain, and bothtypeandvalueare required;valueis plain JSON. The key is the variable's key: lowercased, with spaces and dots removed.nameis written only when it differs, and must normalize to the key (E_VARIABLE_NAME_MISMATCH). Read one asvars.<key>. - The body holds block declarations and wiring statements. Helpers, loops, conditionals and imports of your own have no stored form and are refused. Use
loop,parallel,conditionandrunWorkflowblocks instead.
Blocks
const x = builder('Name', params?, meta?)declares a block; a barebuilder(…)statement does too. The builder is the block's dotted path in the catalog:agent,slack.sendMessage,table.insertRow,trigger.gmail.poller. An unknown path isE_UNKNOWN_BUILDER, with a did-you-mean. Builders underlegacy.are old block versions a workflow may already hold; do not write new ones.block(type, 'Name', params?, meta?)writes any block type, including a custom or legacy one that no builder fits. Params are checked against the catalog when it knows the type, and kept as written when it does not.- A name is a non-empty string literal (
E_NAME_NOT_LITERAL,E_EMPTY_NAME), unique once normalized (E_DUPLICATE_NAME), and notloop,parallelorvariable(E_RESERVED_NAME). A name with a look-alike character, such as a Cyrillic letter inside a Latin word, isE_LOOKALIKE_NAME, and one with a bidirectional control or zero-width character isW_SUSPICIOUS_CHARACTER. response(name, { body, status?, headers? })is the Response block. Any other key isE_UNKNOWN_PARAM.
Params
- A param is a setting of the block, named as
sim workflows source params <builder>lists it. For a setting the builder shows as a basic or advanced pair, you write the shared name, not either member. Writing a member by its own name isE_UNKNOWN_PARAM, and the hint names the right one. - An omitted param is the default the workflow builder fills in, so a block with no params is stored like one made in the builder.
nullfor a whole param stores it as absent. - A param the builder already fixes, such as
operation, isE_FIXED_PARAM. - A param that is not visible under the block's other settings is
W_FIELD_NOT_APPLICABLE. It never runs, so the apply keeps the stored value and the nextgetleaves the line out. - A required field left empty, or written as
todo(), isW_REQUIRED_MISSING. A value of the wrong JSON type isW_VALUE_KIND; it is never converted.
Selecting a resource or typing an ID
For a field that offers a selector in the builder, a resource helper (credential('key'), table('key') and the others in the next section) or a non-empty array of them selects the resource. Anything else, such as channel: 'C0123', is the value typed into the field. The kind of value alone decides which one you mean.
meta
The optional third argument holds what belongs to the block, not to its settings.
Values
-
Literals, objects, arrays and negative numbers are written as in TypeScript. A number too large to store is
E_NUMBER_NOT_FINITE, and one whose digits a number cannot hold isW_NUMBER_PRECISION: write it as a string. -
A string is
'…', an untagged template without${}, or a tagged template:
Resource helpers
A key is the resource's stable key in the workspace; .sim/sdk/workspace.d.ts lists them. A key with no live resource is E_MAT_UNKNOWN_RESOURCE on apply.
In a workspace directory, sim workspaces source check reports a key the directory does not declare; see Manage a workspace as code.
Secrets and stored()
A secret is never printed. A literal value in a password field prints as stored(), which compiles to the value the stored workflow already holds for the same block and param. A new block, another block type or an empty field has nothing stored: stored() there is E_STORED_VALUE_MISSING. To set a secret, write env.NAME and keep the value in the workspace's environment variables. A literal key in the file is W_LITERAL_SECRET.
References
block.output,block['x-y']andblock.items[0]read another block's output; they are stored as<key.output>,<key.x-y>and<key.items[0]>. The path is typed from the block's outputs. A path no output has isW_UNKNOWN_OUTPUT_PATH, which the apply refuses as an error on a block the edit changed.- An agent's declared
responseFormatfields and a Start, API or Input trigger's declaredinputFormatfields count as outputs. An input the trigger does not declare, andx.erroron a block with no error edge, areW_OUTPUT_PATH_UNDECLARED: a warning the apply never refuses, because a caller may still pass the input. - A reference to a block declared later is
W_FORWARD_REFand still resolves. A reference into a sibling loop or parallel's child isE_OUT_OF_SCOPE. An identifier that names nothing isE_UNKNOWN_IDENTIFIER, with a did-you-mean. vars.xreads a workflow variable; an undeclared one isE_UNKNOWN_VARIABLE.ref('Raw.path')writes the reference text<Raw.path>as you gave it. Hand-written<Name.path>text whose head is not a block key isW_REF_NOT_NORMALIZED.
JSON fields
A field that holds JSON text, such as responseFormat, a table row's data or a response body, takes an object or array literal and stores it as formatted JSON. Each bare reference inside is quoted when the output is a string and left bare otherwise, because the run splices a bare string as JSON when it reads as JSON (12345 would become a number) and quoted text always as text. A Function's result, or a field of it, has the type its JavaScript certainly returns there (a string literal, String(…), .toISOString().slice(…) and the like are text; arithmetic, comparisons and literals are not); a Function result or an API data whose code or response may be text is untyped unless the code says. A reference no output type is known for is stored bare with W_JSON_REF_UNTYPED. A template is a JSON string, which is how a value becomes text on purpose. source get prints a stored quoted reference as the bare reference only when a declaration (the catalog, a variable's type, an input or response format) types it a string; one typed only by what a Function's code or a child workflow returns prints as t`${ref}` , so editing that code never changes how a field that reads it is stored. A resource helper inside the literal is E_UNSUPPORTED_SYNTAX.
Input formats and tools
inputFormatis a record:name: 'string'declares a string input, andname: { type, … }declares one with options. An entry with no type, such ascount: 5, is refused.- An agent's
toolsis an array of:slack.tool.sendMessage(params): an integration operation, written as the block's namespace,tool, and the operation;customTool('key'): a workspace custom tool;mcp('key').tool('name', { args? }): one tool of an MCP server, with the arguments the workflow fixes;childWorkflow('key').asTool(): a child workflow;raw(tool): any other stored tool, which agetwrites when a tool does not fit the forms above.
- A tool's secret prints as
params: { key: stored() }, resolved like a block'sstored(). A tool that no rule matches to a stored one isE_STORED_VALUE_MISSING, so a deleted or reordered tool never takes another tool's secret.
Function code
Code that does not fit a block goes in a Function block, kept in its own file:
The path is ./functions/<name>.<extension>, relative to workflow.ts, and the extension matches the block's language: js for JavaScript (the default), py for Python, sh for shell. Any other path is E_CODE_FILE_PATH, and a file that was not sent is E_CODE_FILE_MISSING. When code cannot be kept in a file, a get writes it inline as js`…` and reports W_CODE_FILE_INLINED.
In a JavaScript file, $ref.block.path reads another block's output and $env.NAME reads an environment variable. block is the block's key: its name lowercased with all whitespace and every . removed ($ref.triageagent.content for "Triage Agent", $ref.v2result.text for "V2. Result"). Inside a loop body, $ref.loop.currentItem and $ref.loop.index read the iteration's item and position; inside a parallel body, $ref.parallel.currentItem and $ref.parallel.index. A $ref that names no block is refused in a file you edited, because it would not resolve when the workflow runs. Python and shell files are saved as written, so $ref and $env mean nothing there: read an output as <block.path> (<triageagent.content>) and an environment variable as {{NAME}}; a $ref in one is W_CODE_FILE_REF_SYNTAX.
Branches
- A condition's params object lists its rows in order, each a string or template. Write
else: truelast for the empty else. Two or more rows must end withelse(E_BRANCH_ELSE_LAST). - A router's rows are
routes: { key: text }. - A branch key is unique (
E_DUPLICATE_BRANCH_KEY) and may not be an output name,tooronError(E_BRANCH_KEY_COLLIDES). - A branch that no edge leaves ends the run on that path;
checkreports it asW_BRANCH_UNWIRED.
Loops and parallel blocks
bodyis(p) => { … }, wherep.to(x)connects the container's start to a block inside it, or(p) => block(…), which does the same for one block.p.index,p.currentItemandp.itemsread the iteration; any other property isE_UNKNOWN_SUBFLOW_PROPERTY. They are stored as<loop.x>or<parallel.x>.- A
countthat is not a whole number of at least 1, or abatchSizeoutside 1 to 20, isW_SUBFLOW_COUNT: the run replaces or clamps it.
Wiring
Refused: .to() on a condition or router itself (E_NO_DEFAULT_OUTPUT; wire a branch), a branch that does not exist (E_UNKNOWN_BRANCH), an edge into a trigger (E_TARGET_TRIGGER), onError on a block with no error port (E_ERROR_PORT_UNSUPPORTED), an edge to or from a note (E_EDGE_NOTE), an edge across loop or parallel scopes (E_EDGE_SCOPE), a repeated edge (E_DUPLICATE_EDGE) and a cycle (E_EDGE_CYCLE). Repeat work with a loop instead.
Comments
Comments you write are kept and written back where they were. One inside an expression moves to the statement it belongs to (W_COMMENT_MOVED). One whose block no longer exists is dropped (W_COMMENT_DROPPED).