Portal Community

AI Function Node in Flow Studio

Drag the "AI Function" node from the node palette onto the workflow canvas. Configure it by selecting an AI Function from the dropdown and mapping input/output variables:

// AI Function Node configuration (stored as workflow node definition)
{
  "nodeType":     "AIFunction",
  "functionName": "calculate_leave_days",
  "inputMapping": {
    "startDate":    "workflow.leaveStartDate",
    "endDate":      "workflow.leaveEndDate",
    "annualEntitlement": "workflow.employee.leaveEntitlement",
    "usedDays":     "workflow.employee.leaveUsed"
  },
  "outputMapping": {
    "approved":      "workflow.leaveApproved",
    "remainingDays": "workflow.daysAfterLeave",
    "message":       "workflow.approvalMessage"
  }
}

AIFunctionNodeExecutor

// Flow Studio execution node for AI Functions
public class AIFunctionNodeExecutor : BaseNodeExecutor<AIFunctionNodeSettings>
{
    protected override async Task<NodeExecutionResult> ExecuteInternalAsync(
        NodeDataContext context,
        CancellationToken ct)
    {
        var settings = GetSettings(context);

        // Resolve the named function from the store
        var function = await _store.GetByNameAsync(
            settings.FunctionName,
            context.TenantId, ct)
            ?? throw new ConfigurationException($"AI Function '{settings.FunctionName}' not found");

        // Build input object from workflow variables
        var inputDict = new Dictionary<string, object?>();
        foreach (var (funcParam, workflowVar) in settings.InputMapping)
        {
            inputDict[funcParam] = context.GetVariable(workflowVar);
        }
        var inputJson = JsonSerializer.SerializeToElement(inputDict);

        // Execute the function
        var result = await _runtime.ExecuteAsync(function, inputJson, new AIFunctionContext
        {
            TenantId = context.TenantId,
            AgentId  = context.AgentId ?? Guid.Empty,
            UserId   = context.UserId ?? string.Empty
        }, ct);

        // Map outputs back to workflow variables
        foreach (var (funcOutput, workflowVar) in settings.OutputMapping)
        {
            if (result.TryGetProperty(funcOutput, out var value))
                context.SetVariable(workflowVar, value);
        }

        return NodeExecutionResult.Success();
    }
}

Comparison: AI Function Node vs. AI Agent Node

AspectAI Function NodeAI Agent Node
What executesJavaScript in sandboxFull LLM + tool call loop
DeterminismFully deterministicNon-deterministic (LLM output varies)
CostZero LLM API costLLM API cost per call
LatencyMillisecondsSeconds (LLM + tools)
Best forCalculations, transformations, validationNatural language processing, decision-making, multi-step tasks

Error Handling in Workflow

If an AI Function returns an error object or throws a runtime exception, the node sets its status to Faulted. Workflow designers can add error branches from the AI Function node to handle failure gracefully:

// Function returns structured error:
return { error: "invalid_input", message: "startDate must be before endDate" };

// Node detects error key → sets node to Faulted state
// Workflow designer routes the "Error" branch to a notification step