Variables
The OpenFlow Protocol uses a powerful variable interpolation system that allows dynamic data flow between nodes and workflow inputs.
All variables are referenced using double curly braces: {{variable_name}}
Flow Variables: Access any variable defined in the workflow's variables array. Variables can be typed:
{
variables: [
{
id: "user_input",
type: "string",
default: "Hello world"
},
{
id: "max_retries",
type: "number",
default: 3
},
{
id: "config_data",
type: "object",
default: {key: "value"}
},
{
id: "file_paths",
type: "array",
default: ["file1.txt", "file2.txt"]
}
]
}
| Type | Description | Examples | Use Cases |
|---|
string | Text values | "Hello world", "{{user_input}}" | Text processing, prompts, IDs |
number | Numeric values | 42, 3.14, {{max_tokens}} | Limits, counters, scores |
boolean | True/false values | true, false, {{enable_feature}} | Flags, conditions, toggles |
array | Lists of values | ["file1.txt", "file2.txt"] | Batch processing, collections |
object | Complex structures | {"key": "value", "nested": {}} | Configuration, metadata |
file | File references | "/path/to/document.pdf" | Document processing, uploads |
The OpenFlow SDK implements a sophisticated file management system that handles multimedia content through the FileManager singleton pattern:
Files are registered with unique UUID identifiers and managed through the following lifecycle:
// File registration creates a FileReference
FileReference {
id: string // UUID identifier
originalPath: string // Source file location
tempPath: string // Temporary file location
filename: string // Original filename
extension: string // File extension (.pdf, .jpg, etc.)
size: number // File size in bytes
mimeType?: string // Detected MIME type
created: Date // Registration timestamp
}
The FileManager provides multiple access patterns for registered files:
| Method | Return Type | Use Case | Example |
|---|
getFileBuffer() | Buffer | Raw binary data access | Binary processing, file operations |
getFileBase64() | string | Base64 encoded content | LLM image analysis, data transmission |
getFileDataUrl() | string | Data URL format | Direct browser display, web integration |
isImage() | boolean | Image type validation | Conditional processing workflows |
isDocument() | boolean | Document type validation | Text extraction workflows |
| Category | Extensions | MIME Types | Processing Capabilities |
|---|
| Images | JPEG, PNG, GIF, WebP, SVG | image/* | Vision model analysis, page conversion |
| Documents | PDF, DOC, DOCX, TXT, MD | application/pdf, text/* | Text extraction, page splitting |
| Data | JSON, XML, CSV, HTML | application/json, text/xml | Structured data parsing |
File variables integrate seamlessly with the variable interpolation system:
{
"variables": [
{
"id": "input_document",
"type": "file",
"default": "/path/to/document.pdf"
}
],
"nodes": [
{
"id": "document_splitter",
"type": "DOCUMENT_SPLITTER",
"config": {
"file": "{{input_document}}"
}
},
{
"id": "llm_analysis",
"type": "LLM",
"config": {
"messages": [
{
"type": "image",
"role": "user",
"text": "Analyze this page",
"image_data": "{{current.fileId}}"
}
]
}
}
]
}
- Registration:
FileManager.registerFile() creates UUID and temp copy
- Reference: File ID passed to flow variables as
{{variable.fileId}}
- Processing: Nodes access file via FileManager methods
- Cleanup:
FileManager.cleanup() removes all temporary files
- Isolated Processing: Each file copied to temporary directory
- Automatic Cleanup: FileManager tracks all registered files
- Resource Management: Cleanup should be called in try/catch finally blocks
- Singleton Pattern: Ensures consistent cleanup across flow executions
| Reference Type | Syntax | Description | Output Type |
|---|
| Flow Variable | {{user_input}} | Direct flow variable access | As declared |
| Flow Variable | {{max_retries}} | Numeric flow variable | number |
| Flow Variable | {{config_data}} | Object flow variable | object |
| Node Output | {{node_id.output}} | Complete node output | As produced |
| Node Property | {{llm_processor.output.text}} | Specific output property | string |
| Array Property | {{document_splitter.output.images}} | Array output property | array |
| Nested Property | {{embedding_node.output.values}} | Nested object property | As declared |
| Array Index | {{vector_search.output.results[0].metadata}} | Array element property | object |
| Aspect | Implementation | Example | Purpose |
|---|
| Runtime Resolution | Just-in-time when nodes execute | Variable resolved at node start | Ensure fresh values |
| Scoped Registry | Flow-specific variable storage | Per-execution namespace | Prevent conflicts |
| Registry Format | Hierarchical dot notation | node_id.output.property | Structured access |
| Context Isolation | Per-flow execution context | Separate variable spaces | Concurrent execution safety |
| Reference Type | Validation | Example | Status |
|---|
| Previous Node | Must execute before current | {{llm_processor.output}} | ✅ Valid |
| Flow Variable | Must be declared in variables array | {{user_input}} | ✅ Valid |
| Future Node | References node that executes later | {{future_node.output}} | ❌ Invalid |
| Self Reference | Node references its own output | {{current_node.output}} | ❌ Invalid |
| Undefined Variable | References non-existent variable | {{missing_var}} | ❌ Invalid |
| Aspect | Purpose | Implementation | Benefits |
|---|
| Flow Definition | Declare expected inputs | variables + input arrays | Clear interface |
| Runtime Execution | Pass actual values | executeFlow(flow, inputs) | Dynamic data |
| Type Safety | Validate input types | Schema validation | Error prevention |
| Default Values | Fallback for missing inputs | default property | Robust execution |
// Flow definition with input variables
const flow = {
variables: [
{ id: "user_prompt", type: "string" },
{ id: "max_tokens", type: "number" }
],
input: ["user_prompt", "max_tokens"],
// ... rest of flow
};
// Execute with input variables
await executor.executeFlow(flow, {
user_prompt: "Analyze this document",
max_tokens: 1000
});
| Priority | Source | Override Behavior | Example |
|---|
| 1 (Highest) | Runtime inputs | Overrides defaults | executeFlow(flow, {user_input: "runtime"}) |
| 2 | Variable defaults | Used if no runtime input | {default: "fallback value"} |
| 3 (Lowest) | Validation error | Required without default | Execution fails |