Colang 2.0 Overview
Colang 2.0 represents a complete overhaul of both the language and runtime, introducing powerful new features while maintaining the event-driven interaction model.Version Timeline
Colang 2.0 was introduced in NeMo Guardrails version 0.8 and has evolved through two phases:| NeMo Guardrails Version | Colang Version | Status |
|---|---|---|
| 0.1 - 0.7 | 1.0 | Stable |
| 0.8 | 2.0-alpha | Legacy |
| >= 0.9 | 2.0-beta | Current |
Colang 1.0 remains the default until Colang 2.0 completes its beta phase. You must explicitly enable Colang 2.0 in your configuration.
What’s New in 2.0
Colang 2.0-alpha Features
Key enhancements include:- More powerful flows engine: Supports multiple parallel flows and advanced pattern matching over event streams
- Standard library: Simplifies bot development with pre-built flows
- Smaller set of core abstractions: Flows, events, and actions
- Explicit entry point: Through the
mainflow with explicit activation - Asynchronous actions: Non-blocking action execution
- Python-like syntax: Reduced learning curve for developers
Colang 2.0-beta Additions
- Import mechanism: For the standard library to streamline development
- Generation operator (
...): Dynamic runtime generation using LLMs - Standalone and flow parameter expression evaluation: More flexible parameter handling
Current Limitations
Major Changes from 1.0
Terminology
To reduce the learning curve, Colang 2.0 borrows terminology from Python:- Every bit of Colang code is called a script
- A single
.cofile is called a module - A folder of Colang files is called a package
- Modules and packages can be imported
Syntax Changes
Removed keywords:define- No longer neededexecute- Replaced withawait
flow- Define flows (replacesdefine flow)match- Match eventssend- Send eventsstart- Start flows/actions without waitingawait- Start and wait for completionactivate- Activate flows to run in background
- Support for decorators (e.g.,
@active) when/or wheninstead ofwhen/else when- Dropped subflows (use regular flows instead)
Defining User and Bot Intents
The specialdefine user ... and define bot ... syntax is no longer supported.
Colang 1.0:
user gesture "wave").
Flow Naming Conventions
Colang 2.0 adopts specific naming conventions:- User flows (events from outside): Use past tense (e.g.,
user said,user expressed greeting) - Bot flows (actions to take): Use imperative form (e.g.,
bot say,bot express greeting,bot refuse to respond)
The Generation Operator
Colang 2.0 introduces the... operator for dynamic generation at runtime, typically using an LLM:
... operator enables natural language flows where the docstring generates the content dynamically.
Active Flows and Entry Point
Colang 1.0: All flows are active by default, no clear entry point. Colang 2.0:- The
mainflow is the entry point - Flows must be activated explicitly
- Use
activateto enable flows
Import Mechanism
Colang 2.0 adds Python-like imports:COLANGPATH can be imported. Currently, Colang 2.0 only supports module/package-level imports (not individual flows).
Standard Library
Colang 2.0 includes a comprehensive standard library:core: Core flows for user and bot utterances (e.g.,user said,bot say)llm: Flows for LLM-driven interactionstiming: Time-dependent flows (e.g.,wait,user was silent $time_s)guardrails: Support for adding guardrails (input/output checking)avatars: Support for controlling interactive avatarsutils: Utility flows
Event-Driven Interaction Model
The core event-driven model remains consistent between Colang 1.0 and 2.0:- User saying something generates events
- LLM generating a response creates events
- Triggering an action produces events
- Action results are events
- Guardrail triggers are events
Runtime Improvements
Colang 2.0’s runtime addresses Colang 1.0 limitations: Colang 1.0 limitations:- No explicit state object
- Performance degrades with many events
- No support for parallel flows
- Explicit state management
- Better performance with large event streams
- Native support for parallel flows
- Advanced pattern matching
- Asynchronous action execution
Use Cases
Colang 2.0 excels at:- Multi-modal interactions: Voice, gestures, posture, images
- Interactive avatars: Coordinating speech, gestures, and expressions
- Complex agents: Multiple concurrent action streams
- Real-time systems: Efficient event processing
- Natural language workflows: Using the
...operator for LLM generation
Migration Path
If you have existing Colang 1.0 configurations, you can migrate using the CLI tool:--validate to check for syntax errors after migration.
When to Use Colang 2.0
Choose Colang 2.0 when you need:- ✅ Parallel flows and concurrent actions
- ✅ Multi-modal interactions
- ✅ Better performance with many events
- ✅ Natural language generation with
... - ✅ Modern Python-like syntax
- ✅ Standard library flows
- ✅ You have existing 1.0 configurations working well
- ✅ You need fully stable, production-tested features
- ✅ Your use case is simple text-based guardrails
Next Steps
Getting Started
Build your first Colang 2.0 bot
Language Reference
Complete syntax and feature reference
Migration Guide
Migrate from Colang 1.0 to 2.0
v1 Introduction
Learn about Colang 1.0