Neuro-Symbolic Workflow Orchestration with Phi-3 Mini LAM
SymFlow is a declarative workflow engine that transforms RDF workflow definitions into executable bash scripts with intelligent validation powered by Phi-3 Mini.
Define workflows declaratively using RDF/Turtle syntax:
:LoadData a :Task ;
:agent "agents/data_loader.sh" ;
:agentConvention "args" ;
:input "data/raw.csv" ;
:output "output/loaded.csv" .
:CleanData a :Task ;
:dependsOn :LoadData ;
:agent "agents/data_cleaner.sh" ;
:input "output/loaded.csv" ;
:output "output/clean.csv" .Two-stage intelligent validation:
Stage 1: Rule Guards (< 1ms)
- Validates required fields (agent, name)
- Checks dependency existence
- Ensures root tasks exist
- Blocks execution on critical errors
Stage 2: Phi-3 Mini Analysis (~2-5s)
- Context-aware semantic validation
- Optimization suggestions
- Best practice recommendations
- Natural language explanations
- Confidence scoring (0-100%)
Flexible agent argument handling:
args(default): Pass inputs/outputs as command-line argumentsstdout: Redirect stdout/stderr to output fileshybrid: Combine both approaches
- Automatic dependency resolution
- Cycle detection
- Parallelization potential analysis
- Topological sorting for execution order
- ACID-compliant execution (atomic file operations)
- Automatic error handling
- Progress tracking
- Rollback on failure
- Visual Builder: Design workflows using drag-and-drop interface at https://c3anplatform.vercel.app/
- Automatic Conversion: SymFlow automatically detects C3AN JSON exports and converts them to RDF
- Seamless Execution: Run exported JSON files directly (
python3 symflow.py export.json)
# Clone repository
git clone <repository-url>
cd SymFlow
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Install Ollama and pull Phi-3 Mini
curl -fsSL https://ollama.com/install.sh | sh
ollama pull phi3:mini# Generate and execute workflow (RDF)
python3 symflow.py workflow.ttl -o script.sh
./script.sh
# Run from C3AN Platform export (JSON)
python3 symflow.py workflow.json -o script.sh
./script.sh
# Validate only (no script generation)
python3 symflow.py workflow.ttl --validate-only
# Fast mode (skip Phi-3 analysis)
python3 symflow.py workflow.ttl -o script.sh --fast-mode
# Skip LAM entirely
python3 symflow.py workflow.ttl -o script.sh --skip-lamSymFlow operates as a multi-stage compiler that transforms abstract workflow definitions into robust, executable code.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SymFlow Orchestration Pipeline β
ββββββββββββββββββββββββ¬ββββββββββββββ¬βββββββββββββββ¬βββββββββββββ¬βββββββββββββ€
β 1. INGESTION β 2. LAM β 3. GRAPH β 4. OPTIMIZ β 5. CODEGEN β
β β VALIDATION β CONSTRUCTION β -ATION β β
ββββββββββββββββββββββββΌββββββββββββββΌβββββββββββββββΌβββββββββββββΌβββββββββββββ€
β β β β β β
β [ .ttl / .json ] β [ Neuro- β [ DAG ] β [ Parallel β [ .sh ] β
β β β Symbolic ] β β β Groups ] β β β
β βΌ β β β βΌ β β β βΌ β
β ββββββββββββββββ β βββββββββ β βββββββββ β ββββββββββ β ββββββββββ β
β β RDF Parser β β β Rules β β β Nodes β β β Grp A β β β Header β β
β ββββββββ¬ββββββββ β βββββ¬ββββ β βββββ¬ββββ β ββββββββββ β βββββΌβββββ€ β
β β β β β β β β β β Atomic β β
β βΌ β βΌ β βΌ β βΌ β β Ops β β
β ββββββββββββββββ β βββββββββ β βββββββββ β ββββββββββ β βββββΌβββββ€ β
β β C3AN Adapter βββββΆβ β Phi-3 β β β Edges β β β Grp B β β β Error β β
β ββββββββββββββββ β βββββββββ β βββββ¬ββββ β ββββββββββ β βHandler β β
β β β β β β βββββ¬βββββ β
β β β βΌ β β β β
β β β βββββββββ β β βΌ β
β β β β Order β β β [ Script ] β
β β β βββββββββ β β β
β β β β β β
ββββββββββββββββββββββββ΄ββββββββββββββ΄βββββββββββββββ΄βββββββββββββ΄βββββββββββββ
- Universal Input: Accepts both RDF Turtle files (
.ttl) and C3AN JSON exports (.json). - Normalization: The
C3ANAdapterconverts JSON topologies into standard RDF triples on-the-fly. - Parsing:
RDFParserextracts Tasks, Agents, Inputs, Outputs, and Dependencies into internal objects.
- Symbolic Guardrails: Rigid checks for cycle detection, missing dependencies, and file path validity. (Speed: <1ms)
- Neural Analysis: Phi-3 Mini (3.8B LLM) analyzes the semantics of the workflow. It checks:
- Does
TrainModelactually consume data fromCleanData? - Are the agent names descriptive enough?
- Are there security risks in the defined paths?
- Does
- Result: A confidence score (0-100%) and a list of actionable optimization suggestions.
- Dependency Resolution: Builds a Directed Acyclic Graph (DAG) using
NetworkX. - Topological Sort: Determines the mathematically correct linear execution order (e.g., A must run before B).
- Cycle Detection: Guaranteed mathematical proof that the workflow will not hang in an infinite loop.
- Parallelization Detection: The DAG analyzer identifies independent sub-graphs.
- Stage Grouping: Tasks that can run simultaneously are grouped together (e.g.,
ExtractAPIandExtractDBcan run in parallel). - This ensures maximum resource utilization on the target machine.
- BashGenerator: The final compilation step.
- ACID Properties:
- Atomicity: Agents output to temporary files first (
.tmp), then purely move them on success. - Consistency: The script fails fast if any step fails.
- Isolation: Each task runs in its own process space.
- Durability: Results are persisted to disk immediately.
- Atomicity: Agents output to temporary files first (
- Outcome: A standalone, dependency-free Bash script (
.sh) ready for deployment.
core/c3an_adapter.py
- Adapts C3AN Platform JSON exports to SymFlow RDF
- Maps visual agents to executable bash scripts
- Handles agent ID sanitization and dependency mapping
SymFlow is fully integrated with the C3AN Platform, a visual workflow builder.
- Design: Create your pipeline visually at c3anplatform.vercel.app
- Drag agents (
RAGRetriever,VisionInspector, etc.) onto the canvas - Connect them to form a pipeline
- Add tools (
CNN Model,Vector DB) as needed
- Drag agents (
- Export: Click "Download Triples" to get a
.jsonfile - Run: Execute directly with SymFlow
# SymFlow automatically detects JSON and converts it
python3 symflow.py my_visual_workflow.json -o pipeline.shThe C3AN adapter (core/c3an_adapter.py) maps visual blocks to these SymFlow agents:
- RAGRetriever β
tests/agents/rag/retriever.sh - VisionInspector β
tests/agents/vision/inspector.sh - TimeSeriesAnalyzer β
tests/agents/timeseries/analyzer.sh
SymFlow's LAM is a hybrid neuro-symbolic validation system that combines:
- Symbolic: Fast, deterministic rule-based checks
- Neural: Phi-3 Mini (3.8B parameters) for semantic understanding
# Stage 1: Rule Guards (always runs)
guard_results = RuleGuards().validate(tasks)
if not guard_results['valid']:
print("β Critical errors found")
exit(1) # BLOCK EXECUTION
# Stage 2: Phi-3 Analysis (optional)
phi3_results = Phi3LAM().analyze(tasks, guard_results)
print(f"π‘ Suggestions: {phi3_results['suggestions']}")
print(f"β Confidence: {phi3_results['confidence']}%")π§ Running LAM analysis...
π€ Full mode: Rule guards + Phi-3 semantic analysis
β [WARNING] CleanData: No explicit error checking before EngineerFeatures
β Add guard clause to verify integrity of 'loaded_data.csv'
π‘ Suggestions:
BEST_PRACTICE: Include data validation steps within CleanData
Benefit: Reduces potential errors in feature generation
OPTIMIZATION: Consider parallelizing CleanData and EngineerFeatures
Benefit: Decreases overall workflow time
π Workflow follows logical dependencies but could benefit from
explicit guard clauses to ensure data integrity.
β Workflow validated (confidence: 70%)
βΉ Analysis source: phi3_lam
| Mode | Speed | Validation | Use Case |
|---|---|---|---|
| Full (default) | ~2-5s | Rule guards + Phi-3 | Production workflows |
Fast (--fast-mode) |
< 1ms | Rule guards only | CI/CD, quick validation |
Skip (--skip-lam) |
0ms | None | Trusted workflows |
@prefix : <http://symflow.org/workflow#> .
:TaskName a :Task ;
rdfs:label "Human-readable name" ;
:agent "path/to/agent.sh" ;
:agentConvention "args" ; # or "stdout", "hybrid"
:dependsOn :PreviousTask ;
:input "input/file.csv" ;
:output "output/file.csv" ;
:description "What this task does" .Args Convention (default):
# Agent receives: agent.sh INPUT OUTPUT
./data_loader.sh "input.csv" "output.csv"Stdout Convention:
# Agent writes to stdout, redirected to file
./data_loader.sh "input.csv" > "output.csv"Hybrid Convention:
# Combination: args for inputs, stdout for last output
./processor.sh "input.csv" "temp.log" > "final_output.csv":LoadData β :CleanData β :EngineerFeatures β :TrainModel β :EvaluateModelFeatures:
- Loads CSV data
- Cleans and validates
- Engineers features
- Trains ML model
- Evaluates performance
LAM Insights:
- Suggests data validation steps
- Recommends parallelization
- Identifies missing error handling
:ExtractPDF β :ChunkText β :GenerateEmbeddings β :StoreVectors β :QuerySystemFeatures:
- Extracts text from PDFs
- Chunks into segments
- Generates embeddings
- Stores in vector database
- Enables semantic search
LAM Insights:
- Validates chunk integrity
- Suggests parallel processing
- Recommends validation steps
:ExtractAPI β :TransformAPI β
:ExtractDB β :TransformDB ββ :MergeData β :LoadToDB
:ExtractFiles β :TransformFiles βFeatures:
- Parallel extraction from multiple sources
- Data transformation
- Merging and loading
LAM Insights:
- Identifies race conditions
- Suggests input validation
- Recommends error handling
Broken Workflow (invalid dependencies):
:CleanData a :Task ;
:dependsOn :LoadData, :ValidateData ; # ValidateData doesn't exist!
...LAM Output:
π§ Running LAM analysis...
β [ERROR] CleanData: Dependency "ValidateData" does not exist
β [ERROR] ProcessData: Dependency "NormalizeData" does not exist
β Workflow validation failed
Result: No bash script generated, execution blocked
Create bash agents that follow conventions:
#!/bin/bash
# data_loader.sh - Args convention
INPUT=$1
OUTPUT=$2
# Load and process data
python3 << EOF
import pandas as pd
df = pd.read_csv('$INPUT')
# ... processing ...
df.to_csv('$OUTPUT', index=False)
EOF
echo "β Loaded data: $OUTPUT"python3 symflow.py workflow.ttl --visualizeGenerates DAG visualization showing:
- Task dependencies
- Execution order
- Parallelization opportunities
python3 symflow.py workflow.ttl --validate-onlyRuns LAM analysis without generating scripts:
- Checks structural validity
- Provides Phi-3 insights
- Shows confidence score
| Metric | Value |
|---|---|
| Rule Guards | < 1ms |
| Phi-3 Analysis | ~2-5 seconds |
| DAG Building | < 10ms |
| Script Generation | < 50ms |
| Total (Full Mode) | ~2-5 seconds |
| Total (Fast Mode) | < 100ms |
# Ollama API endpoint (default: http://localhost:11434)
export OLLAMA_HOST=http://localhost:11434
# Phi-3 model (default: phi3:mini)
export PHI3_MODEL=phi3:mini- Python 3.8+
- Ollama (for Phi-3 Mini)
- Bash 4.0+
- Dependencies:
rdflib,networkx
usage: symflow.py [-h] [-o OUTPUT] [--skip-lam] [--fast-mode]
[--visualize] [--validate-only]
workflow
positional arguments:
workflow Path to RDF workflow file (.ttl)
optional arguments:
-h, --help Show help message
-o OUTPUT Output bash script path
--skip-lam Skip LAM validation entirely
--fast-mode Use fast mode (rule guards only)
--visualize, -v Generate DAG visualization
--validate-only Only validate, don't generate script
0: Success1: Validation failed (LAM blocked)2: RDF parsing error3: DAG cycle detected4: Script generation error
π Detailed Guide: See EXAMPLES.md for a comprehensive breakdown of all example workflows and their logic.
Example workflows are provided in tests/workflows/:
data_science_pipeline.ttl- ML workflowdocument_processing_pipeline.ttl- RAG systemetl_parallel_pipeline.ttl- Data integrationllm_content_pipeline.ttl- Content generationmonitoring_pipeline.ttl- System monitoringbroken_workflow.ttl- Demonstrates LAM error detection
Run all tests:
for workflow in tests/workflows/*.ttl; do
echo "Testing: $workflow"
python3 symflow.py "$workflow" --validate-only
doneMIT License - See LICENSE file for details
- Phi-3 Mini by Microsoft Research
- Ollama for local LLM inference
- RDFLib for RDF parsing
- NetworkX for graph algorithms
SymFlow: Declarative workflows meet intelligent validation π