OpenFlow Protocol

Variables

Variable System

The OpenFlow Protocol uses a powerful variable interpolation system that allows dynamic data flow between nodes and workflow inputs.

Variable Syntax

All variables are referenced using double curly braces: {{variable_name}}

Variable Types

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"]
    }
  ]
}

Supported Variable Types

TypeDescriptionExamplesUse Cases
stringText values"Hello world", "{{user_input}}"Text processing, prompts, IDs
numberNumeric values42, 3.14, {{max_tokens}}Limits, counters, scores
booleanTrue/false valuestrue, false, {{enable_feature}}Flags, conditions, toggles
arrayLists of values["file1.txt", "file2.txt"]Batch processing, collections
objectComplex structures{"key": "value", "nested": {}}Configuration, metadata
fileFile references"/path/to/document.pdf"Document processing, uploads

File Manager Integration

The OpenFlow SDK implements a sophisticated file management system that handles multimedia content through the FileManager singleton pattern:

File Registration Process

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
}

File Access Methods

The FileManager provides multiple access patterns for registered files:

MethodReturn TypeUse CaseExample
getFileBuffer()BufferRaw binary data accessBinary processing, file operations
getFileBase64()stringBase64 encoded contentLLM image analysis, data transmission
getFileDataUrl()stringData URL formatDirect browser display, web integration
isImage()booleanImage type validationConditional processing workflows
isDocument()booleanDocument type validationText extraction workflows

Supported File Types

CategoryExtensionsMIME TypesProcessing Capabilities
ImagesJPEG, PNG, GIF, WebP, SVGimage/*Vision model analysis, page conversion
DocumentsPDF, DOC, DOCX, TXT, MDapplication/pdf, text/*Text extraction, page splitting
DataJSON, XML, CSV, HTMLapplication/json, text/xmlStructured data parsing

File Variable Usage

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}}"
          }
        ]
      }
    }
  ]
}

File Processing Workflow

  1. Registration: FileManager.registerFile() creates UUID and temp copy
  2. Reference: File ID passed to flow variables as {{variable.fileId}}
  3. Processing: Nodes access file via FileManager methods
  4. Cleanup: FileManager.cleanup() removes all temporary files

File Security & Cleanup

  • 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

Variable Reference Examples

Reference TypeSyntaxDescriptionOutput Type
Flow Variable{{user_input}}Direct flow variable accessAs declared
Flow Variable{{max_retries}}Numeric flow variablenumber
Flow Variable{{config_data}}Object flow variableobject
Node Output{{node_id.output}}Complete node outputAs produced
Node Property{{llm_processor.output.text}}Specific output propertystring
Array Property{{document_splitter.output.images}}Array output propertyarray
Nested Property{{embedding_node.output.values}}Nested object propertyAs declared
Array Index{{vector_search.output.results[0].metadata}}Array element propertyobject

Variable Resolution

AspectImplementationExamplePurpose
Runtime ResolutionJust-in-time when nodes executeVariable resolved at node startEnsure fresh values
Scoped RegistryFlow-specific variable storagePer-execution namespacePrevent conflicts
Registry FormatHierarchical dot notationnode_id.output.propertyStructured access
Context IsolationPer-flow execution contextSeparate variable spacesConcurrent execution safety

Variable Reference Rules

Reference TypeValidationExampleStatus
Previous NodeMust execute before current{{llm_processor.output}}✅ Valid
Flow VariableMust be declared in variables array{{user_input}}✅ Valid
Future NodeReferences node that executes later{{future_node.output}}❌ Invalid
Self ReferenceNode references its own output{{current_node.output}}❌ Invalid
Undefined VariableReferences non-existent variable{{missing_var}}❌ Invalid

Input Variables

Runtime Variable Passing

AspectPurposeImplementationBenefits
Flow DefinitionDeclare expected inputsvariables + input arraysClear interface
Runtime ExecutionPass actual valuesexecuteFlow(flow, inputs)Dynamic data
Type SafetyValidate input typesSchema validationError prevention
Default ValuesFallback for missing inputsdefault propertyRobust 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
});

Input Variable Precedence

PrioritySourceOverride BehaviorExample
1 (Highest)Runtime inputsOverrides defaultsexecuteFlow(flow, {user_input: "runtime"})
2Variable defaultsUsed if no runtime input{default: "fallback value"}
3 (Lowest)Validation errorRequired without defaultExecution fails

On this page