Introducing a new way to review your PRs.

Read the announcement

elsa-workflows / elsa-core

The Workflow Engine for .NET

View on GitHub

32 documents · Updated Oct 7, 2026

docs / authoring-and-expressions

Workflow authoring languages

Elsa separates workflow authoring from workflow execution. Authors can describe an executable activity graph with code, JSON, or ElsaScript, use expressions to calculate values at run time, and exchange process models through BPMN 2.0. Workflow management gives each source a versioned definition and passes the resulting executable workflow to the workflow engine; the focused language and format rules are covered in expression languages and workflow DSL and BPMN.

Authoring layers

Workflow source forms

Workflow authoring has two related layers. A workflow source form describes activities and their links. An expression describes a value that an activity input calculates later. The source form becomes an executable workflow, while expressions remain attached to inputs until an activity needs their values.

The main source forms are:

Source formMain purposeResult
Code-first workflowBuild an Elsa workflow in application codeAn activity graph with workflow metadata and data contracts
JSON workflow definitionStore or move a serializable Elsa workflow modelA definition that the JSON materializer can load
ElsaScriptWrite an Elsa-native workflow as textA workflow built from the script's activities and expressions
BPMN 2.0 XMLExchange a process model with BPMN toolsAn Elsa workflow bound to the selected BPMN process

These forms do not replace the runtime model. Each must resolve its activities and expressions through the capabilities enabled in the target host. The resulting workflow then enters the normal definition lifecycle described in workflow management.

References: src/…/IWorkflowBuilder.cs• L7-10 src/…/WorkflowDefinition.cs• L67-92 src/…/IWorkflowMaterializer.cs• L7-22

Authoring capability catalogs

Authoring clients discover the capabilities of a host through authenticated descriptor catalogs. The catalogs describe activities, expression types, variable types, output converters, installed features, and the strategies that affect definition behavior. Activity descriptors also include workflows that the host exposes as reusable activities, so the designer can open and configure those workflow-backed activities.

Most catalog reads need only an authenticated caller. Workflow definition lists and version lists still require the workflow-definition view permission because they expose stored definitions. Refreshing the activity catalog is a separate operation: it is allowed for callers who can view activity descriptors or workflow definitions, and otherwise the current registry is returned without a refresh. The descriptor permission names remain available for existing roles even where they no longer control ordinary catalog reads.

References: src/…/Endpoint.cs• L11-43 src/…/Endpoint.cs• L19-36 src/…/Endpoint.cs• L29-60 src/…/Endpoint.cs• L30-56 src/…/Endpoint.cs• L19-42 src/…/Endpoint.cs• L15-30 src/…/Endpoint.cs• L15-35 src/…/Endpoint.cs• L16-30 src/…/Endpoint.cs• L16-30 src/…/Endpoint.cs• L17-29 src/…/Endpoint.cs• L17-30 src/…/Endpoint.cs• L23-38 src/…/Endpoint.cs• L18-30 src/…/Endpoint.cs• L19-23 src/…/List.cs• L15-21 src/…/WorkflowPermissions.cs• L31-82

Workflow definition boundary

A workflow definition is the shared boundary between source data and execution. It carries the workflow identity and version together with its activity root, variables, inputs, outputs, outcomes, options, and custom data. Its materializer knows how to turn the stored source into the executable workflow selected by management.

This boundary lets the system keep source concerns separate from execution concerns. A code-first workflow is built directly. A JSON or ElsaScript definition is materialized from its source. A BPMN definition is first bound to an Elsa process scope. In all cases, management supplies the stored identity and version that downstream execution uses.

References: src/…/WorkflowDefinition.cs• L10-87 src/…/WorkflowDefinitionModel.cs• L6-85 src/…/WorkflowDefinitionMapper.cs• L28-82

Dynamic value expressions

Expression contract

An expression is a typed value description with a type name and a value. The type name selects how Elsa reads the value. The value can be a literal, a workflow reference, or source text for a language engine. This lets an activity declare what input it needs without choosing one language for the whole activity.

The common evaluator finds the descriptor for the expression type and sends the expression to its handler. Descriptors also provide authoring metadata and define whether an expression can be serialized. This registry is the extension point for built-in and custom expression types. Authoring clients can read the expression catalog as authenticated users; host-code expressions remain hidden when their descriptors are not browsable.

Built-in language types use these stable names in serialized definitions:

Type nameValue styleMain use
CSharpC# sourceGeneral host-side scripting for trusted authors
JavaScriptJavaScript sourceDynamic values and script activities
LiquidLiquid template textText rendering and value formatting
PythonPython sourceGeneral host-side scripting for trusted authors

For JavaScript authoring, the editor can request TypeScript definitions derived from the latest workflow graph. The type-definition endpoint accepts optional activity and property context to improve Monaco intellisense, and the request requires the JavaScript scripting view permission. This supports authoring assistance without changing the shared expression contract or runtime evaluation path.

Literal values and workflow-specific references use the same expression contract. For language behavior, context access, and trust controls, read expression languages.

References: src/…/Expression.cs• L8-44 src/…/ExpressionDescriptor.cs• L10-68 src/…/ExpressionEvaluator.cs• L7-27 src/…/IExpressionDescriptorRegistry.cs• L7-40 src/…/Endpoint.cs• L14-59 src/…/JavaScriptPermissions.cs• L11-25 src/…/Endpoint.cs• L14-60

Expression evaluation context

The expression context connects a language engine to one workflow activity. It provides workflow memory, scoped services, temporary values, cancellation, and a parent context for nested scopes. Context helpers make workflow inputs, variables, activity outputs, and execution data available to expressions.

When an activity requests an input, Elsa evaluates its expression in this context and converts the result to the input's expected type. The same path supports ordinary expression-backed inputs and language-specific script activities. This keeps data calculation separate from the activity's work.

The evaluation path is:

flowchart LR
    A[Stored activity input] --> B[Typed expression]
    B --> C[Expression descriptor]
    C --> D[Expression handler]
    D --> E[Workflow expression context]
    D --> F[Typed input value]
    F --> G[Activity execution]

References: src/…/ExpressionExecutionContext.cs• L9-40 src/…/IExpressionEvaluator.cs• L8-28 src/…/ExpressionEvaluatorExtensions.cs• L13-29

Text workflow authoring

Code-first workflows

Code-first authoring uses the workflow builder API to declare the workflow root and its contract. Application code can set identity and metadata, add variables and inputs or outputs, and choose the activity structure. This form is useful when workflow definitions are part of a host application's compiled code.

The builder produces the same kind of executable workflow used by other source forms. As a result, code-first workflows still use the common activity input and expression model. The source is code rather than a stored text document, so source import and export expectations differ from serialized definitions.

References: src/…/IWorkflowBuilder.cs• L7-10 src/…/IWorkflowBuilder.cs• L52-80 src/…/IWorkflowBuilder.cs• L214-222 src/…/WorkflowBase.cs• L6-45

ElsaScript source

ElsaScript is a text language for describing one Elsa workflow. It gives authors named workflows, activity calls, variables, control flow, listeners, and flowchart links without requiring application code. It also allows source to choose a default expression language and to select a language for an individual expression.

The ElsaScript path reads source into a workflow-shaped syntax tree, resolves activity names against the activity registry, and creates an executable workflow. Its expression values use the common Elsa expression system rather than a separate script runtime. The materializer then restores the stored definition identity and version so source metadata cannot change the version selected by workflow management.

References: src/…/ElsaScriptParser.cs• L15-111 src/…/WorkflowNode.cs• L6-28 src/…/ElsaScriptCompiler.cs• L31-111 src/…/ElsaScriptWorkflowMaterializer.cs• L8-35

Process model interchange

BPMN import

BPMN 2.0 XML is an interchange format for process models. Elsa can preview a document, select a process when the document contains more than one, check whether the host can run the required BPMN features, and bind the process to Elsa work before saving a workflow definition.

BPMN defines process structure but does not define what every service task should do in Elsa. Elsa-specific activity bindings fill that gap inside the BPMN document. Known BPMN work can map to Elsa behavior directly. A task with no defined work needs an elsa:activityBinding that names the Elsa activity and carries its configured inputs. The import path rejects a model when the binding or required host capability is missing.

The import flow is:

flowchart LR
    A[BPMN 2.0 XML] --> B[Analyze document]
    A --> C[Read and select process]
    C --> D[Check host capabilities]
    D --> E[Bind BPMN work to Elsa activities]
    E --> F[Save versioned workflow definition]
    F --> G[Normal workflow execution]

References: src/…/BpmnInterchangeDocumentService.cs• L111-166 src/…/BpmnWorkBinder.cs• L13-18 src/…/BpmnWorkBinder.cs• L59-152 src/…/Endpoint.cs• L11-85

BPMN export

BPMN export returns the original BPMN document retained during import. It preserves diagram layout, foreign content, and Elsa activity bindings instead of rebuilding a smaller document from the Elsa activity graph.

Export is therefore a source round trip, not a general conversion from every Elsa workflow to BPMN. Elsa exports only when the definition still has its imported source and the source was recorded for the current definition version. If a later edit makes the source stale or removes it, the system refuses export rather than returning a process model that misrepresents the current workflow.

References: src/…/BpmnInterchangeDocumentService.cs• L26-55 src/…/BpmnInterchangeDocumentService.cs• L169-228 src/…/Endpoint.cs• L13-79 src/…/BpmnActivityBindingFormat.cs• L11-25

Format relationships

Authoring choices

The source form determines what an author can express directly and what kind of round trip the system can promise. Code-first workflows favor compiled application ownership. ElsaScript favors readable Elsa-native source. JSON favors portable serialized definitions. BPMN favors exchange with process-model tools and preserves the imported document when it remains current.

NeedBest fitMain boundary
Define a workflow as part of host codeCode-first workflowWorkflow builder
Write an Elsa workflow as textElsaScriptElsaScript compiler and materializer
Save or move an Elsa workflow modelJSON definitionWorkflow definition model and JSON materializer
Exchange a process diagramBPMN 2.0BPMN reader, Elsa bindings, and retained source
Calculate a value during executionExpressionShared evaluator and expression context

No source form bypasses the host's activity registry, expression support, or workflow management lifecycle. The format-specific boundary creates the executable workflow. The workflow engine then applies the common execution rules.

References: src/…/JsonWorkflowMaterializer.cs• L7-37 src/…/ElsaScriptWorkflowMaterializer.cs• L8-35 src/…/BpmnInterchangeDocumentService.cs• L131-166 src/…/ExpressionEvaluator.cs• L16-27

Source-to-runtime flow

Authoring ends when a source form has become a versioned workflow definition that management can materialize. Expressions are evaluated later inside the execution context, so a source can describe dynamic data without running language code during authoring.

This separation gives each system a clear role:

  • Authoring formats describe workflow structure and source intent.
  • Expression languages produce values or script results from workflow state.
  • Workflow management owns identity, versions, validation, import, and export boundaries.
  • The workflow engine executes the resulting activity graph.

References: src/…/IWorkflowMaterializer.cs• L7-22 src/…/WorkflowDefinitionService.cs• L59-175 src/…/ExpressionExecutionContext.cs• L9-40 src/…/WorkflowRunner.cs• L20-27

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep serialized expression type names aligned with descriptor registration, language features, and any source syntax aliases.
  • When a source format adds an activity or input shape, keep its materializer, activity registry lookup, and expression serialization rules compatible.
  • When WorkflowDefinition source fields change, preserve the relationship between OriginalSource, StringData, the materializer name, and the stored definition version.
  • When changing JavaScript type-definition generation or its workflow graph inputs, keep Monaco authoring metadata aligned with the latest workflow shape and the JavaScript scripting permission.
  • When changing descriptor catalogs, keep authenticated discovery aligned with the permissions that still control protected definition reads and activity-registry refresh.
  • When changing activity descriptor refresh behavior, preserve the cluster refresh path and the distinction between returning the current registry and rebuilding it.
  • When changing BPMN binding names or input serialization, review previously exported BPMN documents and any external authoring tool that writes the elsa: extension.
  • When changing BPMN import behavior, keep analysis, capability checks, binding, and retained-source export on the same document rules.
  • When enabling host-code access for C# or Python expressions, review the trust boundary and the visibility of those languages to authors.

Important failure modes

TriggerConsequenceGuard
A definition uses an expression type whose feature is not enabled.The evaluator cannot resolve the expression descriptor.Enable the matching expression feature before loading or running the definition.
A source names an activity that the host does not provide.Elsa cannot create the executable activity graph.Keep the source activity names aligned with the installed activity registry.
C# or Python execution is used without trusted-host configuration.Evaluation is blocked or exposes an unsafe host boundary if enabled without review.Treat host-code languages as a trusted-author capability and configure them deliberately.
A JavaScript editor request lacks the scripting view permission.The editor cannot retrieve type definitions for intellisense.Grant the workflow author the JavaScript scripting view permission through the normal authorization path.
A JavaScript type-definition request names a missing workflow definition.The endpoint returns an error instead of editor type definitions.Request definitions for an existing workflow definition and refresh the editor context after a definition change.
A BPMN task has no Elsa activity binding.Import rejects the process because BPMN does not define the task's work.Add a valid elsa:activityBinding or change the process model.
A BPMN document needs a capability that the deployment does not provide.Import stops before the definition is stored.Deploy the required BPMN capability or remove the dependent process behavior.
Imported BPMN source is missing or belongs to an older definition version.BPMN export is refused rather than returning a misleading document.Preserve source metadata and re-import after a source-level workflow change.

Key files

FileWhy to read it
src/…/WorkflowDefinition.csDefines the shared source, version, metadata, and materializer boundary.
src/…/IWorkflowMaterializer.csDefines how a source representation becomes an executable workflow.
src/…/IWorkflowBuilder.csShows the code-first workflow authoring contract.
src/…/Expression.csDefines the common typed expression shape.
src/…/ExpressionEvaluator.csShows how expression types reach their handlers.
src/…/ExpressionExecutionContext.csShows the workflow state boundary available during evaluation.
src/…/Endpoint.csShows how JavaScript editor type definitions are produced from a workflow graph.
src/…/JavaScriptPermissions.csDefines the authorization contract for JavaScript editor type definitions.
src/…/Endpoint.csShows how expression capabilities are exposed to authenticated authoring clients and how host-code visibility is represented.
src/…/Endpoint.csShows how the activity catalog supports designer discovery and controlled registry refresh.
src/…/WorkflowPermissions.csDefines the permission boundary for definition access and descriptor compatibility.
src/…/ElsaScriptParser.csDefines the main ElsaScript source concepts.
src/…/ElsaScriptCompiler.csShows how ElsaScript becomes a workflow without changing the common expression model.
src/…/BpmnInterchangeDocumentService.csOwns BPMN analysis, import, source retention, and export rules.
src/…/BpmnActivityBindingFormat.csDefines the Elsa extension that makes BPMN task work executable in Elsa.
src/…/BpmnWorkBinder.csShows the boundary from BPMN work declarations to Elsa activities.