Colang 1.0 Flows
Flows are the heart of Colang 1.0. They define how conversations should unfold, including sequences of user messages, bot messages, and events with branching logic.What Are Flows?
A flow is a sequence of messages and events that models a conversational pattern. Flows can be:- Named flows: Explicitly defined flows that activate when patterns match
- Anonymous flows: Unnamed flows defined inline with
define flow - Subflows: Reusable flows that must be called explicitly
Flow Types
Anonymous Flows
Anonymous flows activate automatically when their initial pattern matches:Named Flows
Named flows can be referenced and are often used for specific scenarios:Subflows
Subflows are reusable components called with thedo keyword:
Flow Patterns
Simple Sequential Flow
The most basic pattern is a sequence of messages:Real Example: Hello World Flow
Fromexamples/bots/hello_world/rails.co:
Conditional Flows
Using if/else
Useif/else to branch based on context variables:
$first_time_user variable would be set by the host application or a previous action.
Using when/else when
Usewhen/else when to branch based on the next user message or event:
Guardrail Flows
Flows are commonly used to implement safety and topical guardrails.Input Rails
Input rails check and potentially block user inputs:Real Example: Disallowed Topics
Fromexamples/bots/abc/rails/disallowed.co:
Off-Topic Rails
Keep conversations focused on allowed topics:Flow Control
The stop Keyword
Usestop to halt execution of the current flow:
Flow Completion
Flows complete naturally when they reach their end:Working with Variables
Setting Variables in Flows
Using Action Results
Conditional Logic with Variables
Multi-Step Flows
Complex interactions can span multiple turns:Parallel Flows
Multiple flows can be active simultaneously. When a user message matches multiple flow patterns, all matching flows execute:Real-World Example: Jailbreak Detection
Fromexamples/configs/jailbreak_detection/flows.co:
Best Practices
1. Keep Flows Focused
Each flow should handle one conversational pattern:2. Use Descriptive Names
Name flows and messages clearly:3. Organize by Function
Group related flows together:4. Leverage Subflows for Reusability
5. Handle Edge Cases
Common Patterns
Question-Answer Pattern
Refusal Pattern
Information Gathering Pattern
Clarification Pattern
Next Steps
Examples
See complete examples with multiple flows
Syntax Reference
Review the full syntax guide