Octopus
What Are AI Functions
AI Functions are the "code-as-data" extension point in Octopus. They allow administrators and developers to write lightweight JavaScript logic that agents and workflows can execute — without compiling or deploying new application code.
The Problem AI Functions Solve
Custom tool logic written in C# requires compilation, testing, and deployment — typically a development sprint. For simple transformations, calculations, or formatting operations, this is overhead without value. AI Functions address this by:
- Storing JavaScript logic in the database (immediately changeable)
- Running in a sandboxed interpreter (safe — no filesystem or network)
- Being versioned (rollback if a bad function is deployed)
- Being manageable by admin users without developer involvement
The Lifecycle of an AI Function Call
1
Function Requested
Either: LLM calls it as an MCP tool, or a Flow Studio node references it by name.
2
Function Loaded from SQL
AIFunctionStore retrieves the active function code by name and tenant. Cached in memory for the request lifetime.
3
Sandbox Initialised
AIFunctionRuntime creates a new Jint (or V8) engine instance. Global APIs are injected (see Sandbox page).
4
Function Executed
Input data passed as a JavaScript object;
execute(input) called; return value captured.
5
Output Returned
Return value serialised as JSON and returned to the caller (LLM tool result or workflow node output).
Key Properties
| Property | Value |
|---|---|
| Language | JavaScript (ES2020 subset via Jint; or full Node.js via V8 isolate) |
| Storage | SQL Server (Octopus_AIFunctions) |
| Entry point | Must export/define an execute(input) function |
| Return value | Any JSON-serialisable value (object, array, string, number, boolean) |
| Isolation | New sandbox instance per call — no shared state between calls |
| Timeout | Configurable max execution time (default 5 seconds) |
| Memory limit | Configurable heap limit per execution (default 64 MB) |
Good Use Cases
| Use Case | Example |
|---|---|
| Data formatting | Format a currency amount for the user's locale |
| Calculations | Calculate leave days remaining given dates and entitlement |
| Data transformation | Convert a raw API response into a clean structured summary |
| Simple validation | Validate an email address or phone number format |
| Text processing | Extract key facts from a template-formatted text block |
Not a Replacement for Full Tools
AI Functions cannot make HTTP calls, access the filesystem, or call databases directly (unless services are injected via the sandbox API). For database queries, external API calls, or authentication-gated operations, use a Custom C# Tool Plugin instead.