Migrating from Colang 1.0 to 2.0
This guide covers how to migrate your Colang 1.0 configurations to Colang 2.x using the NeMo Guardrails CLI conversion tool.Why Migrate?
Colang 2.0 offers significant improvements over 1.0:- Better performance: Handles large event streams more efficiently
- Parallel flows: Support for concurrent actions and flows
- Multi-modal support: Not limited to text interactions
- Standard library: Pre-built flows for common patterns
- Modern syntax: Python-like conventions
- Generation operator: Dynamic LLM-based generation with
... - Explicit state management: Better control over conversation state
The Conversion Tool
The NeMo Guardrails CLI provides aconvert command that automatically transforms Colang 1.0 syntax to 2.x.
Basic Usage
Command Options
| Option | Description | Default |
|---|---|---|
--from-version | Source version: 1.0 or 2.0-alpha | 1.0 |
--verbose / --no-verbose | Output detailed logs | no-verbose |
--validate / --no-validate | Validate output using Colang parser | no-validate |
--use-active-decorator / --no-use-active-decorator | Use @active decorator | use-active-decorator |
--include-main-flow / --no-include-main-flow | Add a main flow to config | include-main-flow |
Examples
Basic conversion with validation:How the Tool Works
The converter walks through your directory, finds all.co files, and applies transformations:
Syntax Transformations
| Colang 1.0 | Colang 2.0 |
|---|---|
define flow | flow |
define subflow | flow |
define bot | flow bot |
define user | flow user |
execute | await |
else when | or when |
stop | abort |
| Snake_case actions | CamelCase + Action suffix |
| Anonymous flows | Named flows with @active |
Additional Transformations
- Quoted strings after
bot: Converted tobot sayoror bot say - Quoted strings after
user: Converted touser saidoror user said - Global variables: Adds
globalkeyword - Generation operator: Converts
...syntax - Root flows: Uses
@activedecorator for flows that need activation
Transformation Examples
Example 1: Simple Flow
Colang 1.0:Example 2: User and Bot Intents
Colang 1.0:Example 3: Actions
Colang 1.0:execute search_knowledge_base becomes await SearchKnowledgeBaseAction.
Example 4: Conditional Logic
Colang 1.0:else when becomes or when.
Example 5: The Generation Operator
Colang 1.0:... operator as a string parameter.
Example 6: Generic Matching
Colang 1.0:... wildcard for matching is replaced with explicit “something” flows.
Rails Configuration
If yourconfig.yml defines guardrails in the rails field, the tool generates a _rails.co file with those rails defined.
config.yml (Colang 1.0):
_rails.co with the appropriate flow definitions.
Manual Migration Tasks
Some changes require manual intervention:1. Add Imports
Colang 2.0 requires explicit imports:.co file.
2. Create a main Flow
Every Colang 2.0 script needs amain flow:
--include-main-flow option automatically generates this, but you may need to customize it.
3. Review Flow Names
The tool generates flow names by converting anonymous flows. Review and rename as needed:4. Update Action Names
The tool convertssnake_case action names to CamelCase with Action suffix:
execute check_input→await CheckInputActionexecute retrieve_data→await RetrieveDataAction
5. Apply Naming Conventions
Colang 2.0 has conventions for flow names:- User events: Past tense (e.g.,
user expressed greeting,user asked question) - Bot actions: Imperative (e.g.,
bot express greeting,bot answer question)
6. Update Global Variables
The tool addsglobal keywords, but you should verify placement:
7. Review Generation Operator Usage
The... operator syntax changed. Verify the instruction is correctly formatted:
Common Issues
Issue 1: Syntax Errors After Migration
Problem: The converted code has syntax errors. Solution: Use--validate to catch errors:
Issue 2: Flow Names with Special Characters
Problem: Flow names contain-, +, or reserved keywords like or, and.
Solution: The migration tool doesn’t handle this. Manually rename:
Issue 3: Missing Imports
Problem: Flows use standard library features but don’t import them. Solution: Add imports at the top:Issue 4: Global Variables Not Working
Problem: Variables aren’t accessible across flows. Solution: Ensureglobal is declared in all flows that use the variable:
Issue 5: Actions Not Found
Problem: Actions renamed by the tool don’t match Python implementations. Solution: Either:- Update Python action names to match (e.g.,
CheckInputAction) - Manually edit
.cofiles to use original names
Migration Checklist
Use this checklist to ensure a successful migration:- Backup original files (use Git or copy)
- Run conversion tool with
--validate - Review generated
mainflow - Add necessary
importstatements - Verify action name transformations
- Check global variable declarations
- Apply naming conventions (past tense for user, imperative for bot)
- Review and rename auto-generated flow names
- Test with
nemoguardrails chat - Verify all guardrails still work
- Check edge cases and error handling
Testing After Migration
After migrating, thoroughly test your configuration:1. Basic Chat Test
2. Guardrails Test
Test that safety rails still work:3. Edge Cases
Test edge cases specific to your application:- Empty inputs
- Very long inputs
- Unusual phrasing
- Multi-turn conversations
4. Performance Test
For production systems, test with realistic conversation volumes.Real Migration Example
Before: Colang 1.0
Fromexamples/bots/hello_world/rails.co:
After: Colang 2.0
- Added
import coreandimport llm - Created
mainflow with activations - Converted
define usertoflow userwithuser said - Converted
define bottoflow botwithbot say - Named anonymous flows (
greeting_flow,politics_flow) - Changed
else whentoor when - Added
@activedecorators
Best Practices
- Use version control: Always commit before running the converter
- Test incrementally: Migrate one file at a time for complex projects
- Review thoroughly: Don’t blindly trust the automated conversion
- Follow conventions: Apply naming conventions manually
- Update documentation: Document changes for your team
- Keep backups: Maintain the Colang 1.0 version until 2.0 is fully validated
When Not to Migrate
Consider staying with Colang 1.0 if:- Your application is in production and working perfectly
- You don’t need parallel flows or multi-modal support
- Your team is unfamiliar with the new syntax
- You’re waiting for Colang 2.0 to exit beta
Getting Help
If you encounter issues during migration:- Check the NeMo Guardrails documentation
- Review the GitHub repository examples
- File an issue on GitHub
- Ask in the community forums
Next Steps
Overview
Learn about Colang 2.0 features
Getting Started
Build your first Colang 2.0 bot
Language Reference
Complete Colang 2.0 syntax reference
v1 Introduction
Review Colang 1.0 concepts