The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix trigger variable paths advertised to workflow AI tools (#27968)
Thomas Trompetted391e8a49337
diff --git a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/skill-metadata/create-standard-flat-skill-metadata.util.ts b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/skill-metadata/create-standard-flat-skill-metadata.util.tsindex 259517aae22..978dcf373fa 100644--- a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/skill-metadata/create-standard-flat-skill-metadata.util.ts+++ b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/skill-metadata/create-standard-flat-skill-metadata.util.ts@@ -107,7 +107,7 @@ PICK_RECORD selects one record from a candidate pool (settings.input.recordIds)CLASSIFY asks an AI model one or more typed questions about a single piece of text and returns a typed answer for each, so later steps can branch on the result. Reach for it when the user describes sorting, routing, triaging, tagging or rating something written — "route support emails to the right team", "flag angry replies", "rate how urgent this is". Prefer it over a CODE step for those: it needs no code and no logic function.settings.input takes:-- **state** — the text every question is asked about. Usually a variable, e.g. "{{trigger.record.bodyV2.markdown}}".+- **state** — the text every question is asked about. Usually a variable, e.g. "{{trigger.properties.after.bodyV2.markdown}}".- **questions** — an array. Each needs id (a UUID), name, type, instructions and criteria.- **modelId** — optional. Omit it to use the workspace's classification model, which is almost always what you want.diff --git a/packages/twenty-server/src/modules/workflow/workflow-tools/tools/create-complete-workflow.tool.ts b/packages/twenty-server/src/modules/workflow/workflow-tools/tools/create-complete-workflow.tool.tsindex bb2e0461c61..200bb001f16 100644--- a/packages/twenty-server/src/modules/workflow/workflow-tools/tools/create-complete-workflow.tool.ts+++ b/packages/twenty-server/src/modules/workflow/workflow-tools/tools/create-complete-workflow.tool.ts@@ -93,7 +93,7 @@ IMPORTANT: The tool schema provides comprehensive field descriptions, examples,- Field requirements and data types- Common object patterns and field structures- Proper relationship field formats-- Variable reference syntax: {{trigger.fieldName}} for trigger data, {{<step-id>.fieldName}} for step outputs (step-id is the step's UUID, not its name). The path mirrors the step's output schema exactly and is addressed directly; Twenty does not add a "result" wrapper. A FIND_RECORDS step exposes {{<find-step-id>.all}} and {{<find-step-id>.first.id}}, not {{<find-step-id>.result.all}}.+- Variable reference syntax: {{trigger.properties.after.fieldName}} for a DATABASE_EVENT trigger's record ({{trigger.properties.before.fieldName}} for deleted events), {{trigger.payload.fieldName}} for a MANUAL trigger's selected record, {{trigger.fieldName}} for a WEBHOOK trigger's request body, {{<step-id>.fieldName}} for step outputs (step-id is the step's UUID, not its name). The path mirrors the step's output schema exactly and is addressed directly; Twenty does not add a "result" wrapper. A FIND_RECORDS step exposes {{<find-step-id>.all}} and {{<find-step-id>.first.id}}, not {{<find-step-id>.result.all}}.- Error handling optionsThis is the most efficient way for AI to create workflows as it handles all the complexity in one call.diff --git a/packages/twenty-shared/src/workflow/schemas/database-event-trigger-schema.ts b/packages/twenty-shared/src/workflow/schemas/database-event-trigger-schema.tsindex e773fb9f3d4..f83263249d6 100644--- a/packages/twenty-shared/src/workflow/schemas/database-event-trigger-schema.ts+++ b/packages/twenty-shared/src/workflow/schemas/database-event-trigger-schema.ts@@ -20,7 +20,7 @@ export const workflowDatabaseEventTriggerSchema = baseTriggerSchemaoutputSchema: z.looseObject({}).describe(- 'Schema defining the output data structure. For database events, this includes the record that triggered the workflow accessible via {{trigger.object.fieldName}}.',+ 'Schema defining the output data structure. For database events, the record that triggered the workflow is under properties.after (properties.before for deleted events) and is accessible via {{trigger.properties.after.fieldName}}.',),objectType: z.string().optional(),fields: z.array(z.string()).optional().nullable(),@@ -36,5 +36,5 @@ export const workflowDatabaseEventTriggerSchema = baseTriggerSchema}),}).describe(- 'Database event trigger that fires when a record is created, updated, deleted, or upserted. The triggered record is accessible in workflow steps via {{trigger.object.fieldName}}.',+ 'Database event trigger that fires when a record is created, updated, deleted, or upserted. The triggered record is accessible in workflow steps via {{trigger.properties.after.fieldName}}, or {{trigger.properties.before.fieldName}} for deleted events.',);diff --git a/packages/twenty-shared/src/workflow/schemas/manual-trigger-schema.ts b/packages/twenty-shared/src/workflow/schemas/manual-trigger-schema.tsindex e2bbc81787b..345405a2255 100644--- a/packages/twenty-shared/src/workflow/schemas/manual-trigger-schema.ts+++ b/packages/twenty-shared/src/workflow/schemas/manual-trigger-schema.ts@@ -9,7 +9,7 @@ export const workflowManualTriggerSchema = baseTriggerSchemaoutputSchema: z.looseObject({}).describe(- 'Schema defining the output data structure. When a record is selected, it is accessible via {{trigger.record.fieldName}}. When no record is selected, no data is available.',+ 'Schema defining the output data structure. With SINGLE_RECORD availability, the selected record is accessible via {{trigger.payload.fieldName}}. With BULK_RECORDS availability, the selected records are accessible via {{trigger.payload.<objectNamePlural>}} (e.g., {{trigger.payload.companies}}). When no record is selected, no record data is available.',),icon: z.string().optional(),isPinned: z.boolean().optional(),@@ -33,5 +33,5 @@ export const workflowManualTriggerSchema = baseTriggerSchema}),}).describe(- 'Manual trigger that can be launched by the user. If a record is selected when launched, it is accessible via {{trigger.record.fieldName}}. If no record is selected, no data context is available.',+ 'Manual trigger that can be launched by the user. If a record is selected when launched, it is accessible via {{trigger.payload.fieldName}}. If no record is selected, no record data is available.',);diff --git a/packages/twenty-shared/src/workflow/schemas/object-record-schema.ts b/packages/twenty-shared/src/workflow/schemas/object-record-schema.tsindex 604ce2dec16..a5417d19cd2 100644--- a/packages/twenty-shared/src/workflow/schemas/object-record-schema.ts+++ b/packages/twenty-shared/src/workflow/schemas/object-record-schema.ts@@ -4,7 +4,7 @@ export const objectRecordSchema = z.record(z.string(), z.any()).describe('Record data object. Use nested objects for relationships (e.g., "company": {"id": "{{reference}}"}). Common patterns:\n' +- '- Person: {"name": {"firstName": "John", "lastName": "Doe"}, "emails": {"primaryEmail": "[email protected]"}, "company": {"id": "{{trigger.object.id}}"}}\n' ++ '- Person: {"name": {"firstName": "John", "lastName": "Doe"}, "emails": {"primaryEmail": "[email protected]"}, "company": {"id": "{{trigger.properties.after.id}}"}}\n' +'- Company: {"name": "Acme Corp", "domainName": {"primaryLinkUrl": "https://acme.com"}}\n' +'- Task: {"title": "Follow up", "status": "TODO", "assignee": {"id": "{{user.id}}"}}',);diff --git a/packages/twenty-shared/src/workflow/schemas/wait-for-event-action-settings-schema.ts b/packages/twenty-shared/src/workflow/schemas/wait-for-event-action-settings-schema.tsindex c40e0d0bdfe..edc0fe0d1e1 100644--- a/packages/twenty-shared/src/workflow/schemas/wait-for-event-action-settings-schema.ts+++ b/packages/twenty-shared/src/workflow/schemas/wait-for-event-action-settings-schema.ts@@ -14,7 +14,7 @@ export const workflowWaitForEventActionSettingsSchema =.nullable().optional().describe(- 'Only resume for this record. Usually a variable such as {{trigger.object.id}}. Leave empty to resume on any record.',+ 'Only resume for this record. Usually a variable such as {{trigger.properties.after.id}}. Leave empty to resume on any record.',),updatedFields: z.array(z.string())