Define a workflow
Apps can ship workflows. EachdefineWorkflow() call describes one workflow: a trigger and the steps it runs. On install, Twenty creates it as an active workflow in the workspace, ready to run.
This workflow runs when a company is created. It calls one of the app’s logic functions, then writes the result on the company:
src/workflows/score-new-companies.ts
- The workflow and each step need their own
universalIdentifier, and the trigger can have one. Keep them stable across releases: they are how Twenty matches the installed workflow on the next install. nextStepIdswires the graph. The trigger points to the first steps, and each step points to the steps that run after it.- A step reads earlier output with
{{trigger.<path>}}or{{<step universalIdentifier>.<path>}}. - The build validates the whole definition: unsupported trigger or step types, broken step links and references to unknown steps fail it.
isSystem(optional, defaults tofalse) hides the workflow from the lists that leave out system workflows. It only changes what is displayed.
Referencing other entities
Steps and triggers point at metadata by universal identifier, never by name or id:- Objects and fields: your app’s own, or standard ones through
STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS. The example above assumes the app also defines aleadScorenumber field on Company withdefineField(): a record step that writes a field missing from the workspace fails the install. - Logic functions: your app’s own, exposed as a workflow action with
workflowActionTriggerSettings. The workspace Custom application can also reference the workflow actions of the other apps installed in the workspace, as workflows built in the app can. - Agents: your app’s own, from
defineAgent().
Triggers
A manual workflow without
availability gets no command menu entry.
Every trigger also takes optional name, position and outputSchema, which only shape how the workflow looks in the builder. Without them, Twenty uses a name such as Manual trigger, places the trigger at the top of the canvas and computes the output schema from the settings.
A webhook workflow listens on https://<your-twenty-domain>/webhooks/workflows/<workspaceId>/<workflowId>, where workflowId is the id of the installed workflow. The request body is available as {{trigger.<path>}}.
Steps
Application workflows support these step types:LOGIC_FUNCTION, CODE, AI_AGENT, HTTP_REQUEST, CLASSIFY, CREATE_RECORD, UPDATE_RECORD, UPSERT_RECORD, DELETE_RECORD, FIND_RECORDS, PICK_RECORD, FILTER, IF_ELSE, ITERATOR, FORM, DELAY, WAIT_FOR_EVENT, SEND_EMAIL, DRAFT_EMAIL, CREATE_CALENDAR_EVENT, SEND_CHAT_MESSAGE and EMPTY.
Their inputs match the steps of the workflow builder, with universal identifiers in place of names:
-
Record steps take
objectUniversalIdentifierinstead of an object name. -
Filters and sorts point at fields with
fieldMetadataUniversalIdentifier. -
Filter operands take
ViewFilterOperandvalues. Filter group operators takeStepLogicalOperatorvalues in step filters andRecordFilterGroupLogicalOperatorvalues in record filters, bothANDorOR.twenty-sdk/defineexports all three, along withViewFilterOperandDeprecatedfor the operands older workflows still store. -
Form fields of type
RECORDname their object withsettings.objectUniversalIdentifier. Fields of typeSELECTandMULTI_SELECToffer the options of an existing field of the same type, named withsettings.selectedFieldUniversalIdentifier. -
A
CODEstep carries its TypeScript source ininput.code: a module exporting amainfunction, which receivesinput.logicFunctionInput. To share code across workflows, use aLOGIC_FUNCTIONstep instead.twenty app pullwrites each code step’s source to its own file, next to the workflow, and the workflow reads it when the app is built:src/workflows/greet-new-pets.workflow.ts -
AI_AGENTsteps come in two kinds, which you can’t mix:- A Generate step has no agent. It carries its own
instructions,modelId,modelConfigurationandscope, and runs once: no conversation, no human input, no waiting. - An Agent step runs one of your app’s agents, named with
agentUniversalIdentifier, which brings its own instructions, model and permissions. Only an Agent step takeshumanInputInstructionsandconversation.
promptandresponseFormat, andworkspaceMemberIdfor the member the agent’s conversation is with. - A Generate step has no agent. It carries its own
-
An
AI_AGENTstep’sscopetakes a role’s permissions without its identity or row-level predicates:canReadAllObjectRecords,objectPermissionsandfieldPermissionsby universal identifier,permissionFlagUniversalIdentifiers, and so on. It only restricts: the step’s AI never reaches more than whoever runs the workflow. It resolves like a role whose all-records flags default to off: object actions and permission flags it doesn’t grant are denied, system objects stay readable unless it grants more, and a field it doesn’t list follows its object. A Generate step without ascopegets no data tools; an Agent step runs with its agent’s role. -
Email and calendar steps run only if your app’s role has the matching permission flag:
SystemPermissionFlag.SEND_EMAIL_TOOLforSEND_EMAILandDRAFT_EMAIL,SystemPermissionFlag.CREATE_CALENDAR_EVENT_TOOLforCREATE_CALENDAR_EVENT. The workspace grants it by installing the app, and the step can then use any connected account in the workspace, like a workflow built in the app. -
Connected account ids are local to each workspace, so don’t hardcode one. Name the account in one of two ways:
connectedAccountHandle: the account’s email address, such as'sales@example.com'. When the app is synced, the handle resolves to an account with that address that is shared with the workspace (WORKSPACEscope) and can run the step. A member’s private account can’t be named by handle: pull keeps it as itsconnectedAccountId. If several accounts share the address, for example one mailbox connected by two members or through two providers, the oldest one wins. If none matches, the sync fails and names the handle. This is notfromHandle, which picks an alias to send from.connectedAccountId: a variable, such as{{trigger.properties.after.connectedAccountId}}. Email steps also take a workspace member id, such as{{trigger.properties.after.assigneeId}}, which resolves to that member’s first account able to send.
-
SEND_CHAT_MESSAGEposts to a workspace member’s inbox, set withworkspaceMemberId. Member ids are local to each workspace too, so an app passes a variable, such as{{trigger.properties.after.assigneeId}}. Members mentioned in itstext, such as those in a note body passed as{{trigger.properties.after.bodyV2.markdown}}, are notified, as with inbox messages.
After install
- The workflow is active as soon as the app is installed, and its runs appear with the workspace’s other workflow runs.
- Installing a new version of the app updates the workflow in place.
- Users can’t edit an installed workflow. To customize one, they duplicate it: the copy is theirs to edit.
Workflows of the workspace Custom application
The workspace Custom application owns the workflows built in the workflow builder, and code is as authoritative for them as the builder:twenty app pullwrites each one from its active version, the one the builder last published. A workflow whose active version uses settings adefineWorkflow()file can’t express, such as a record filter on a field of a related record, is reported and left in place. So is a Code step created before steps stored their source, until it is edited once in the builder or upgraded.- A pulled workflow keeps what the builder stored: a trigger without a
universalIdentifier, the trigger’s builder name, apositionofnullfor a node the builder never placed, and anoutputSchemathat differs from the computed one. These fields need twenty-sdk 2.53.0 or later, applied to a server on 2.53.0 or later: older versions reject them as unknown keys. Code steps need twenty-sdk 2.56.0 or later, applied to a server on 2.56.0 or later: older versions reject them as an unsupported step type. twenty app applypublishes like the builder. A workflow whose definition matches its active version is left alone. Otherwise the active version is archived and the definition becomes a new active version, so past runs keep the version they ran.- Users keep editing these workflows in the builder, and the next pull brings their changes back.