The open alternative to Salesforce, designed for AI.
Workflows
Use when the app needs to ship a workflow, or when a logic function should be invocable from the workflow builder.
See logic.md for post-install hooks. See app-structure.md for source layout.
Mental Model
Declare app workflows with defineWorkflow from twenty-sdk/define: one call per workflow, holding a trigger and its steps. Install creates it active; installing a new app version updates it in place. Users can't edit an installed workflow — they duplicate it.
Workflows created at runtime through the workspace API are a Workflow plus at least one WorkflowVersion. Creating a Workflow auto-creates its draft v1; never create a WorkflowVersion directly.
defineWorkflow
- The workflow and each step need a stable
universalIdentifier. The trigger's is optional. nextStepIdswires the graph: the trigger points to the first steps, each step to the steps after it.- Trigger types:
MANUAL,CRON,DATABASE_EVENT,WEBHOOK. Step types exclude the builder'sCODE— useLOGIC_FUNCTION. - Reference objects, fields, logic functions and agents by universal identifier, never by name or id.
- Triggers take optional
name,positionandoutputSchema; steps take optionalpositionandoutputSchema. They only shape the builder view. Omit them to get the derived defaults. position: nullmeans no position.outputSchema: {}means an empty schema; omitoutputSchemato derive it.twenty app pullon the workspace Custom application writes builder workflows in this form, keeping the builder's trigger name, positions and output schemas.
AI Agent Steps
AI_AGENTis one of two kinds. Never mix them: an agent brings its own instructions, model and permissions.- Generate step: no agent. It carries its own
instructions,modelId,modelConfigurationandscopeand runs once, with no conversation, no human input and no waiting. - Agent step: runs one of the app's agents, named with
agentUniversalIdentifier. Only this kind takeshumanInputInstructionsandconversation; a Generate step with either fails validation.
- Generate step: no agent. It carries its own
- Both kinds take the step's
prompt,responseFormatandworkspaceMemberId(the member the agent's conversation is with). scopeis what the step's AI may reach on top of the permissions of whoever runs the workflow: a role's permissions (canReadAllObjectRecords,objectPermissions,fieldPermissions,permissionFlagUniversalIdentifiers, ...) without its identity or row-level predicates. 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 unlisted fields follow their object. A Generate step without ascopegets no data tools; an Agent step runs with its agent's role.- A step can only name an agent the app exports.
twenty app pullreports as unsupported a workflow on any other agent, or with a stored step that has human input instructions or a conversation but no agent.
Email and Calendar Steps
SEND_EMAIL,DRAFT_EMAILandCREATE_CALENDAR_EVENTname their account with exactly one ofconnectedAccountIdorconnectedAccountHandle.- Use
connectedAccountHandle(the account's email address) in app code: ids only exist in one workspace. Apply resolves it to the oldest active account with that address that is shared with the workspace (WORKSPACEscope) and can run the step, and fails if none can. A member's private account can't be named by handle. twenty app pullwrites a shared account's id as its handle. Private account ids, variables and workspace member ids stayconnectedAccountId.
Send to Inbox Steps
SEND_CHAT_MESSAGEpoststitleandtextto the inbox ofworkspaceMemberId, optionally with atoolCallthe member approves before the run goes on, and an optionalconversation.- Member ids only exist in one workspace: in app code, pass a variable such as
{{trigger.properties.after.assigneeId}}.
Manual Record Trigger
- Trigger type: manual record selection.
- The selected record is the trigger payload — no wrapping
recordfield. - Reference fields with
{{trigger.<field>}}. Do not use{{trigger.record.<field>}}.
Lifecycle Through the Workspace API
Only for workflows created at runtime, e.g. from a post-install hook, instead of defineWorkflow. Always: create → configure draft → activate. Never publish a draft directly.
- Find or create the
Workflowby stable name or slug.createWorkflowproduces the draftv1. - Set the trigger on the draft via
updateWorkflowVersion. - Add steps via the workflow-step mutations.
createWorkflowVersionStepreturns astepsDiff, not the step — read the diff for the new step id, then callupdateWorkflowVersionStepwith the full payload. - Activate via
activateWorkflowVersion.
Forbidden:
- Do not write
Workflow.statuses— it is computed from the active version's status. - Do not create
WorkflowVersionrows directly.
Idempotency
Find by deterministic name or slug before creating. Single-record queries throw on absence in some Twenty versions — treat not-found as "needs create."
Permissions
Seeders need workflow settings permissions on the app role. Grant via defineRole. If a typed mutation is rejected from the app context, fix the role — falling back to raw GraphQL signals the wrong scope.
Invoking Locally
twenty app exec
twenty app apply skips install hooks. Run it again after rebuilding to verify idempotency.