Octopus
Flow Studio Node
The AI Function Node in Flow Studio lets workflow designers call an AI Function as a processing step within any workflow. Input data is mapped from workflow variables into the function; output data is mapped back into workflow variables for downstream nodes.
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
| Aspect | AI Function Node | AI Agent Node |
|---|---|---|
| What executes | JavaScript in sandbox | Full LLM + tool call loop |
| Determinism | Fully deterministic | Non-deterministic (LLM output varies) |
| Cost | Zero LLM API cost | LLM API cost per call |
| Latency | Milliseconds | Seconds (LLM + tools) |
| Best for | Calculations, transformations, validation | Natural 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