Skip to main content

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:
These flows have no name and start executing when the first event matches.

Named Flows

Named flows can be referenced and are often used for specific scenarios:

Subflows

Subflows are reusable components called with the do keyword:

Flow Patterns

Simple Sequential Flow

The most basic pattern is a sequence of messages:

Real Example: Hello World Flow

From examples/bots/hello_world/rails.co:

Conditional Flows

Using if/else

Use if/else to branch based on context variables:
The $first_time_user variable would be set by the host application or a previous action.

Using when/else when

Use when/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

From examples/bots/abc/rails/disallowed.co:

Off-Topic Rails

Keep conversations focused on allowed topics:

Flow Control

The stop Keyword

Use stop 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:
Both flows are active. If a user input matches both patterns, both flows will process the message.

Real-World Example: Jailbreak Detection

From examples/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