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 / ai-platform

AI platform capabilities

Elsa's AI platform gives deployments a common way to run AI chat, expose safe Elsa data and actions as tools, create workflow proposals, and keep an audit trail. The platform separates these duties into shared AI contracts, a host service, provider adapters such as Copilot, and optional EF Core storage.

Platform model

The AI platform coordinates a request from an Elsa client with an AI provider. It resolves approved Elsa context, offers only tools that the current actor may use, streams provider events back to the client, and records the conversation and audit events when the deployment enables those services.

The main contracts are:

  • An AI provider creates or resumes a provider session and runs a turn.
  • An AI tool describes one allowed operation and runs it when the provider calls it.
  • An AI context provider turns a client attachment into server-resolved context.
  • A conversation store keeps chat state. A proposal store keeps workflow change drafts.
  • An audit sink records chat and tool activity.

The platform does not apply a workflow change as a side effect of a proposal tool. It produces a reviewable proposal that a separate review flow can approve or reject.

AI host services

The AI host is the runtime boundary for chat and AI capabilities. It exposes HTTP endpoints for chat, tool discovery, and capability discovery. It also applies tenant, actor, agent, and permission checks before it gives a provider access to tools or context.

Chat flow

The chat flow turns an AIChatRequest into a stream of AIStreamEvent values. A client can start a conversation or reconnect during a short grace period after a stream disconnects.

The flow follows this order:

  1. The chat endpoint fills identity and permission data from the request context.
  2. The orchestrator selects an enabled provider from the request, agent, or host defaults.
  3. The host loads the conversation when persistence is enabled.
  4. Context attachments are resolved and sensitive values are removed.
  5. The tool registry returns tools visible to the agent, tenant, actor, and permissions.
  6. The provider runs the turn and may call the returned tools.
  7. Provider events become server stream events. The host saves the result and writes audit events.

The stream reports preparation, provider, and tool failures as conversation events. A missing provider does not create a provider turn; the host reports that no provider is configured instead.

This diagram shows how a chat request moves through the host and returns a stream.

flowchart LR
    Client[AI client] --> Chat[Chat endpoint]
    Chat --> Orchestrator[AI orchestrator]
    Orchestrator --> Context[Context providers]
    Orchestrator --> Registry[Tool registry]
    Orchestrator --> Provider[Selected AI provider]
    Provider -->|tool calls| Registry
    Registry --> Elsa[Elsa stores and services]
    Provider --> Stream[Stream events]
    Orchestrator --> Conversation[Conversation store]
    Orchestrator --> Audit[Audit sink]
    Stream --> Client

References: src/…/Endpoint.cs• L17-89 src/…/AIOrchestrator.cs• L23-219 src/…/IAIProvider.cs• L5-19

Tool access

The tool registry is the control point between a provider and Elsa operations. It lists tool definitions for discovery and resolves a tool only when its scope and permissions match the current request.

Tools can be read-only, proposal, or administrative. Read-only tools are available by default when visible. Proposal and administrative tools need explicit enablement through their governed paths. This lets a deployment expose useful inspection without giving an AI session unrestricted write access.

The host includes tool families for activity discovery, workflow grounding, workflow proposals, and runtime inspection. The capabilities endpoint reports which families are available so clients can adapt to the services registered by a deployment.

References: src/…/AIToolRegistry.cs• L16-24 src/…/AIToolRegistry.cs• L175-224 src/…/AIToolEnablementService.cs• L6-47 src/…/Endpoint.cs• L37-104

Context grounding

Grounding is the process of giving the provider small, server-selected views of Elsa data. An attachment names a context kind and reference. The matching context provider checks access, maps the Elsa object to AI-safe data, and returns a summary and structured payload.

The host supports context for workflow definitions and runtime instances. It can also support activity, diagnostics, and time-range attachments when the deployment registers the related providers. The resolver redacts sensitive keys and common secret patterns before context reaches the provider, then applies a configured size limit.

References: src/…/AIContextResolver.cs• L19-59 src/…/WorkflowDefinitionContextProvider.cs• L9-46 src/…/WorkflowInstanceContextProvider.cs• L9-45 src/…/AIGroundingModels.cs• L3-23

Workflow proposals

Workflow proposal tools let an AI session suggest a new workflow or an update to an existing version. The host validates the draft against the available activity registry and, for updates, checks the requested baseline. It stores the draft with warnings, validation diagnostics, rationale, and a graph diff for human review.

The proposal status records the review path from draft or validation through approval, rejection, application, or expiry. The proposal operation itself never persists a workflow definition, which keeps AI output separate from an approved workflow change.

References: src/…/WorkflowProposeCreateTool.cs• L7-41 src/…/WorkflowProposeUpdateTool.cs• L7-57 src/…/WorkflowDraftValidationService.cs• L6-31 src/…/AIProposal.cs• L3-62

Provider integrations

An AI provider adapts an external model or agent service to the platform contracts. The host owns the request rules and tool policy. The provider owns session setup and the translation of its native events into the platform's event types.

Copilot provider

The Copilot provider connects the host to the GitHub Copilot SDK or a headless Copilot runtime. It can create or resume a session, pass resolved Elsa context in the prompt, expose approved Elsa tools as provider functions, and translate assistant, reasoning, tool, and error events into platform events.

Copilot configuration can select a local runtime or remote runtime, a model, a working directory, and the credentials needed by that runtime. The provider uses the platform tool invoker for every Elsa tool call, so Copilot does not bypass the host's visibility, permission, audit, and result-size rules.

For the Copilot-specific session and tool composition model, see AI copilot composition.

References: src/…/CopilotProvider.cs• L14-72 src/…/CopilotProvider.cs• L100-179 src/…/ElsaCopilotToolFunction.cs• L10-49 src/…/CopilotOptions.cs• L3-18

Other AI services

The provider contract allows a deployment to add another AI service without changing the host's chat flow. Provider configuration supplies a logical name, provider type, model, endpoint, and secret reference. The host chooses one enabled provider through the request, agent mapping, or default setting.

The repository also supplies agent extensions for OpenAI and Azure OpenAI through the Elsa Agents area. Those extensions are separate from the Copilot provider and show that model-service integration can be added as an extension rather than built into the host.

References: src/…/IAIProvider.cs• L5-10 src/…/AIOrchestrator.cs• L273-307 src/…/AIHostOptions.cs• L38-55 src/…/Elsa.Agents.OpenAI.csproj• L1-23 src/…/Elsa.Agents.AzureOpenAI.csproj• L1-24

EF Core persistence providers

The EF Core AI persistence layer gives the host durable storage for conversations, proposals, and audit records. It uses a dedicated AIDbContext and provider-specific migrations so AI data can use the same database family choices as the wider Elsa deployment.

Durable AI records

The persistence layer maps the platform stores to three record groups:

Record groupPurpose
ConversationsStores identity, status, provider session state, retention, and chat messages.
ProposalsStores workflow drafts, baselines, validation results, graph diffs, and review actors.
Audit recordsStores actor, tenant, conversation, proposal, tool, time, and event data.

Conversation reads enforce expiry and writes enforce tenant and user ownership. Stored messages are bounded so a long chat cannot grow without limit. A background service removes expired conversations on a schedule.

References: src/…/AIDbContext.cs• L7-63 src/…/EFCoreAIConversationStore.cs• L11-59 src/…/EFCoreAIProposalStore.cs• L10-51 src/…/EFCoreAIAuditSink.cs• L9-34 src/…/EFCoreAIConversationCleanupService.cs• L10-55

Database choices

The shared persistence feature wires the AI stores to Entity Framework Core. Separate provider packages select the database engine and its migrations. The available choices are SQLite, SQL Server, PostgreSQL, MySQL, and Oracle.

Each database choice has the same platform role: store the AI records and support the same host contracts. The choice affects the database connection and provider behavior, not the meaning of conversations, proposals, or audit events.

References: src/…/AIPersistenceFeature.cs• L9-21 src/…/SqliteAIPersistenceFeatureExtensions.cs• L9-30 src/…/SqlServerAIPersistenceFeatureExtensions.cs• L9-29 src/…/PostgreSqlAIPersistenceFeatureExtensions.cs• L9-29 src/…/MySqlAIPersistenceFeatureExtensions.cs• L9-29 src/…/OracleAIPersistenceFeatureExtensions.cs• L9-29

Change checklist

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

  • When an AI request, stream event, or provider event changes, check the provider adapter, event mapper, chat endpoint, and reconnect behavior together.
  • When a tool definition or mutability rule changes, check tool listing, tool resolution, enablement, agent permissions, and the capabilities response.
  • When a context attachment changes, check its provider, supported attachment kinds, redaction rules, and the resolved-context size limit.
  • When proposal states or fields change, check validation, review handling, EF Core mapping, and the client-facing capability contract.
  • When AI retention or record fields change, update all EF Core provider migrations and keep tenant and user ownership checks aligned across stores.

Important failure modes

TriggerConsequenceGuard
More than one provider is enabled without a default providerThe host cannot select a provider for chatSet a default provider or leave only one provider selectable.
A provider or durable conversation store is missingThe capabilities response marks streaming or persistence as unavailableRegister the required service and inspect /ai/capabilities.
A tool is visible but not enabled for its mutability levelThe provider cannot invoke the toolEnable proposal tools through the host feature and use a governed path for administrative tools.
A context attachment names an unavailable or unauthorized objectThe provider receives an unavailable or not-found context resultRegister the matching context provider and preserve tenant checks.
An AI proposal contains an unknown activity or stale update baselineThe proposal is blocked or carries validation diagnosticsValidate drafts before review and compare updates with the current baseline.
The AI database cannot save a conversation or audit eventThe chat may continue with a warning, while durable history or audit data is missingKeep the selected EF Core provider, connection, and migrations available.

Key files

FileWhy to read it
src/…/IAIProvider.csDefines the provider and orchestration boundary.
src/…/IAITool.csDefines tool discovery and execution.
src/…/IAIContextProvider.csDefines server-side context resolution.
src/…/AIConversation.csDefines chat requests, messages, sessions, and stream events.
src/…/AIProposal.csDefines the reviewable workflow proposal model and state.
src/…/AIOrchestrator.csShows the end-to-end host chat flow.
src/…/AIToolRegistry.csShows tool visibility and permission rules.
src/…/AIContextResolver.csShows attachment resolution and secret redaction.
src/…/Endpoint.csShows how a deployment reports available AI features.
src/…/CopilotProvider.csShows how Copilot becomes a platform provider.
src/…/AIDbContext.csShows the durable AI record model.
src/…/EFCoreAIConversationStore.csShows conversation retention and ownership behavior.