Building workflows with the Noxus SDK is a programmatic approach to creating visual AI automations. You define nodes, configure them, and connect them together to create sophisticated data processing pipelines.
# Compose multiple text inputscomposer = workflow_def.node("ComposeTextNode").config( template="""# Report Title: ((Title))## Summary((Summary))## Details((Details))Generated on: {{current_date}}""")# Extract text from filesextractor = workflow_def.node("ExtractTextNode").config( preserve_formatting=True, extract_tables=True, extract_images=False)# Filter data based on conditionsfilter_node = workflow_def.node("FilterNode").config( condition="length > 100", # Filter text longer than 100 characters filter_type="text_length")
Connections define how data flows between nodes. The basic pattern is:
Copy
Ask AI
# Basic connection: output of one node to input of anotherworkflow_def.link(source_node.output(), target_node.input())# Named connections for specific inputs/outputsworkflow_def.link( source_node.output("result"), target_node.input("data"))# Variable inputs (for nodes that accept multiple named inputs)workflow_def.link( input_node.output(), ai_node.input("variables", "User Input"))
# Create a linear chain of nodesnodes = [input_node, processor1, processor2, processor3, output_node]# Connect them in sequencefor i in range(len(nodes) - 1): workflow_def.link(nodes[i].output(), nodes[i + 1].input())# Or use the convenience methodworkflow_def.link_many(input_node, processor1, processor2, processor3, output_node)
# Check for common issuesdef validate_workflow(workflow_def): nodes = workflow_def.nodes # Check for orphaned nodes connected_nodes = set() for edge in workflow_def.edges: connected_nodes.add(edge.source_node_id) connected_nodes.add(edge.target_node_id) orphaned = [node for node in nodes if node.id not in connected_nodes] if orphaned: print(f"Warning: Orphaned nodes found: {[n.label for n in orphaned]}") # Check for missing required configurations for node in nodes: if node.type == "TextGenerationNode" and not node.config.get("template"): print(f"Warning: Node '{node.label}' missing template") return len(orphaned) == 0# Validate before savingif validate_workflow(workflow_def): workflow = client.workflows.save(workflow_def)else: print("Please fix validation errors before saving")
# Save and test the workflowworkflow = client.workflows.save(workflow_def)# Test with sample datatest_input = { "User Input": "What are the benefits of renewable energy?"}# Run the workflowrun = workflow.run(body=test_input)result = run.wait(interval=2)print(f"Test result: {result.output}")print(f"Execution time: {result.execution_time}ms")
# ❌ Bad - unclear purposenode1 = workflow_def.node("TextGenerationNode").config(label="Node 1")# ✅ Good - clear purposequestion_answerer = workflow_def.node("TextGenerationNode").config( label="Question Answerer")
Template Design
Create clear, well-structured templates:
Copy
Ask AI
# ✅ Good template with clear structuretemplate = """You are an expert analyst. Please analyze the following:Content: ((Input Content))Focus Area: ((Analysis Focus))Please provide:1. Key insights2. Recommendations3. Next stepsFormat your response clearly with headers."""
Error Handling
Plan for potential failures: python # Add validation nodes validator = workflow_def.node("ConditionalNode").config( condition="not_empty", condition_type="text_validation" ) # Add fallback paths error_handler = workflow_def.node("TextGenerationNode").config( template="Unable to process input. Please provide valid text content." ) workflow_def.link(validator.output("false"), error_handler.input())
Performance Optimization
Optimize for efficiency:
Copy
Ask AI
# Use appropriate model sizesquick_task = workflow_def.node("TextGenerationNode").config( model=["gpt-4o-mini"], # Faster for simple tasks max_tokens=100)complex_task = workflow_def.node("TextGenerationNode").config( model=["gpt-4o"], # More capable for complex tasks max_tokens=500)
# Get available node configuration optionsnodes = client.get_nodes()text_gen_node = next(n for n in nodes if n["type"] == "TextGenerationNode")print(f"Available config: {text_gen_node['config_schema']}")