Skip to content

Slickflow.AI 5.0.0

Latest

Choose a tag to compare

@besley besley released this 03 Mar 09:37
· 6 commits to master since this release

Slickflow Workflow Auto-Execution – Technical Guide (Brief)

1. What is Auto-Execution?

Slickflow.NET is a .NET 8 workflow engine.
Besides traditional human-approval workflows (user tasks, countersign, etc.), it also supports auto-executed workflows:

  • After the process is started, the engine automatically executes service / AI / script tasks in sequence.
  • No human interaction is required until the process reaches an end event or a configured step limit.

Typical scenarios:

  • Data pipelines and ETL flows
  • AI orchestration (chatbot, RAG, LLM tools)
  • Backend automation and batch processing

Key difference from human workflows:

  • Human workflow stops at each user task and waits for a user / API call to continue.
  • Auto-execution keeps running automatically as long as there are executable activities.

2. Architecture Overview

Main components for auto-execution:

  • Slickflow.Graph.Model.Workflow
    Code-based process definition. Supports Start, Task, ServiceTask, RagService, LlmService, Agent, Parallels, Branch, End, etc.

  • ProcessXmlBuilder
    Converts the graph model into BPMN 2.0 XML.

  • WorkflowExecutorExtensions.UseProcess(Workflow)
    Builds an in-memory ProcessEntity via BuildInMemory(), caches it by ProcessId:Version, and binds it to the runtime executor.
    No database read/write is required.

  • WorkflowExecutor (engine runtime)
    Fluent API: UseAppUseProcessAddVariableRun.

  • ServiceTaskDelegateRegistry
    Registry for LocalMethod delegates. Used to map a delegate key in process definition to a .NET method.

  • Auto-execution context
    Uses an in-memory variables dictionary to pass inputs/outputs between steps.

Execution loop (conceptual):

  1. Start process and create an instance.
  2. While there are executable activities:
    • Collect next activities.
    • Execute each activity (LocalMethod / service class / AI / external API).
    • Move the process forward.
  3. Return execution result (status, message, variables, AI response, etc.).

3. Defining a Workflow in Code

3.1 Basic syntax

using Slickflow.Graph.Model;

var wf = new Workflow("Order Process", "OrderProcess_Code");

wf.Start("Start")
  .ServiceTask("Validate Order", "Validate001", "ValidateOrder")   // LocalMethod
  .ServiceTask("Calculate Amount", "Calc001", "CalcAmount")       // LocalMethod
  .RagService("RAG Reply", "RAG001")                              // RAG AI node
  .LlmService("LLM Enrich", "LLM001")                             // General LLM node
  .ServiceTask<SaveOrderService>("Save Order", "Save001")         // Local service class
  .End("End");

Notes:

  • new Workflow(string name, string code)
    name is the process name, code is the business code.
    ProcessId is generated internally as process_xxx, default Version is 1.

  • ServiceTask(name, code, delegateKey)
    Binds a LocalMethod. delegateKey must be registered in ServiceTaskDelegateRegistry.

  • RagService(name, code) / LlmService(name, code)
    AI service tasks (RAG / general LLM).

  • ServiceTask<TService>(name, code)
    Binds a local external service class.

3.2 Parallel and branch helpers

For simple parallel branches:

wf.Start("Start")
  .AndSplit("Parallel Gateway")
  .Parallels(
      ("Task A", "TaskA"),
      ("Task B", "TaskB"),
      ("Task C", "TaskC"))
  .AndJoin("Parallel Join")
  .End("End");

For custom branches with code-defined bodies:

wf.Start("Start")
  .Split("Condition Gateway")
  .Branch(
      () => wf.Task("Condition 1", "Cond1"),
      () => wf.Task("Condition 2", "Cond2"))
  .End("End");

3.3 Build vs. BuildInMemory

Method Description Database
wf.Build() Serialize and insert into wf_process Writes
wf.BuildInMemory() Build an in-memory ProcessEntity only No DB

UseProcess(Workflow workflow) internally calls BuildInMemory() and caches ProcessEntity by ProcessId:Version.
This is ideal for tests, demos, and embedding workflows without touching the database.


4. Running a Workflow with WorkflowExecutor

using Slickflow.Engine.Executor;
using Slickflow.Engine.Core.Result;
using Slickflow.Graph.Model;

// 1. Define workflow in code
var wf = new Workflow("OrderCalcProcess", "OrderCalcProcess_Code");
wf.Start("Start")
  .ServiceTask("Validate Order", "Validate001", "ValidateOrder")
  .ServiceTask("Calculate Amount", "Calc001", "CalcAmount")
  .ServiceTask("Notify Result", "Notify001", "NotifyResult")
  .End("End");

// 2. Register LocalMethod delegates (once at startup)
ServiceTaskDelegateRegistry.Global.Register("ValidateOrder", ValidateOrder);
ServiceTaskDelegateRegistry.Global.Register("CalcAmount", CalcAmount);
ServiceTaskDelegateRegistry.Global.Register("NotifyResult", NotifyResult);

// 3. Execute in auto-execution mode
var result = await new WorkflowExecutor()
    .UseApp("OrderApp-001", "OrderApp")
    .UseProcess(wf)                          // Use in-memory workflow
    .AddVariable("OrderId", "ORD-2025-001")
    .AddVariable("Quantity", "3")
    .AddVariable("UnitPrice", "99.50")
    .Run();

if (result.Status == WfExecutedStatus.Success)
{
    Console.WriteLine(result.Message);

    if (result.Variables != null &&
        result.Variables.TryGetValue("Var_OrderTotal", out var total))
    {
        Console.WriteLine($"OrderTotal: {total}");
    }
}

Key points:

  • Input variables are passed via .AddVariable(key, value).
  • Output variables can be written inside LocalMethod / AI nodes by updating the context variables or returning ServiceTaskResult.WithVariable(...).
  • The engine automatically executes all tasks in order until the process finishes.

5. AI Orchestration Example (RAG + Services)

A typical AI flow:

  • Start → RAG reply → Extract contact → Save customer → Save conversation → End.

Usage pattern:

  • RagService or LlmService reads input variables (such as user_message, history, context ids).
  • Calls the configured LLM provider (OpenAI, DeepSeek, QianWen, etc.).
  • Writes the AI response into ai_response or a configured variable.
  • Downstream ServiceTask<TService> nodes parse and persist structured data (customer info, conversation logs, etc.).

This allows you to:

  • Keep the entire AI conversation pipeline in one executable workflow.
  • Reuse the same graph definition in console apps, web APIs, or background services.

6. Recommended Usage

  • For development and testing
    Use UseProcess(Workflow) + BuildInMemory() to avoid database dependencies, and drive processes entirely in memory.

  • For LocalMethod-based automation
    Register delegates in ServiceTaskDelegateRegistry and keep business logic in normal .NET methods.

  • For AI / LLM workflows
    Use RagService / LlmService nodes together with SetNotifyClient (on WorkflowExecutor) to stream model outputs to clients (web, SignalR, etc.).

This guide is intended as a concise reference for packaging the latest Slickflow auto-execution features into a GitHub Release.