Flows
Processing pipelines for AI operations.
What Are Flows?
Section titled “What Are Flows?”Flows define step-by-step processing pipelines. Think Unix pipes, but for AI operations.
FLOW handle_request validate input fetch context generate response apply constraints format outputEach step transforms data. The output of one step becomes the input of the next.
Basic Syntax
Section titled “Basic Syntax”FLOW name step one step two step threeRules:
- Steps execute in order
- Each step is an indented line
- Steps are named operations
- Indentation matters (2 spaces)
How Flows Execute
Section titled “How Flows Execute”Sequential Processing
Section titled “Sequential Processing”FLOW document_analyzer extract text # First: get the text detect language # Then: identify language analyze sentiment # Then: assess tone summarize content # Finally: create summaryEach step completes before the next begins. No parallel execution.
Data Transformation
Section titled “Data Transformation”FLOW enhance_response original response # "The capital is Paris" add context # "The capital of France is Paris" add sources # "The capital of France is Paris (Source: Wikipedia)" format markdown # "The capital of France is **Paris** *(Source: Wikipedia)*"Each step enriches or transforms the data.
Common Flow Patterns
Section titled “Common Flow Patterns”Input Validation Flow
Section titled “Input Validation Flow”FLOW validate_and_process check rate limit validate schema sanitize input check permissions process requestFail fast. If any validation step fails, the flow stops.
Enhancement Flow
Section titled “Enhancement Flow”FLOW enhance_output generate base response add examples include references apply formatting add metadataProgressive enhancement. Each step adds value.
Safety Flow
Section titled “Safety Flow”FLOW safety_pipeline scan for pii check content policy validate against rules apply filters final reviewMultiple safety checks. Defense in depth.
Context Flow
Section titled “Context Flow”FLOW contextual_response fetch user history fetch relevant docs merge context generate with context personalizeBuild context before generation.
Flows with Constraints
Section titled “Flows with Constraints”Flows and constraints work together:
AGENT support
CONSTRAINTS rules NEVER expose PII MUST be helpful
FLOW support_flow identify issue # Understand the problem check knowledge # Search for solutions generate response # Create response apply constraints # Apply NEVER/MUST rules send reply # Deliver to userThe apply constraints step enforces your rules.
Real-World Examples
Section titled “Real-World Examples”Customer Service Flow
Section titled “Customer Service Flow”FLOW handle_complaint acknowledge customer extract issue check previous tickets determine severity generate solution create ticket send response schedule followupCode Review Flow
Section titled “Code Review Flow”FLOW review_code parse syntax check style guide scan security issues analyze complexity generate feedback format commentsContent Moderation Flow
Section titled “Content Moderation Flow”FLOW moderate_content detect language scan inappropriate check copyright verify facts apply policy generate decisionResearch Flow
Section titled “Research Flow”FLOW research_topic understand query search sources evaluate credibility extract facts synthesize findings cite referencesFlow Control
Section titled “Flow Control”Error Handling
Section titled “Error Handling”While Human doesn’t have explicit error handling syntax, flows naturally handle errors:
FLOW safe_process validate or fail # Stops flow if validation fails process if valid # Only runs if validation passed return result # Only runs if processing succeededConditional Steps
Section titled “Conditional Steps”Steps can be smart about when they apply:
FLOW adaptive_flow detect content type process text # Runs for text process code # Runs for code process data # Runs for data format output # Always runsTesting Flows
Section titled “Testing Flows”Test that your flow produces expected results:
FLOW parsing_flow extract entities validate entities format entities
TEST INPUT "John Smith visited New York" EXPECT CONTAINS "John Smith"
TEST INPUT "Invalid data: @#$%" EXPECT CONTAINS "error"Best Practices
Section titled “Best Practices”1. Single Responsibility
Section titled “1. Single Responsibility”Each step should do one thing:
# GoodFLOW clear_flow validate input fetch data process data format output
# BadFLOW unclear_flow validate and fetch and process do everything else2. Descriptive Names
Section titled “2. Descriptive Names”Step names should be verbs that describe actions:
# GoodFLOW descriptive authenticate user fetch permissions apply access control
# BadFLOW vague step1 process finish3. Fail Early
Section titled “3. Fail Early”Put validation and checks first:
# GoodFLOW fail_fast validate input # First check permissions # Second expensive operation # Last
# BadFLOW fail_late expensive operation # Wastes resources validate input # Should be first4. Keep Flows Focused
Section titled “4. Keep Flows Focused”One flow, one purpose:
# Good: Separate flowsFLOW validate_input check format verify completeness
FLOW process_input transform data apply business logic
# Bad: Mixed concernsFLOW do_everything validate process send email update databaseCommon Mistakes
Section titled “Common Mistakes”Missing Steps
Section titled “Missing Steps”# Bad: Jumps straight to generationFLOW incomplete generate response send response
# Good: Includes necessary stepsFLOW complete validate request check rate limit generate response apply safety checks send responseWrong Order
Section titled “Wrong Order”# Bad: Generates before validatingFLOW wrong_order generate content check if allowed
# Good: Validates firstFLOW right_order check if allowed generate contentThe Philosophy of Flows
Section titled “The Philosophy of Flows”Flows make AI behavior predictable. Instead of a black box that takes input and produces output, you have a glass pipeline where each transformation is visible.