Flow
Create conditional agent workflows
Agents can follow conditional flows – branch based on conditions and data.
Quick Start
- Simple Usage
typescript import { Agent, Flow, when } from 'praisonai'; const classifier = new Agent({ instructions: 'Classify requests' }); const support = new Agent({ instructions: 'Handle support' }); const sales = new Agent({ instructions: 'Handle sales' }); const flow = new Flow() .start(classifier) .when('support', support) .when('sales', sales); await flow.run('I need help with billing'); // Classifier routes to appropriate agent - With Configuration
typescript const flow = new Flow() .start(classifier) .when('support', support) .otherwise(generalAgent);
User Interaction Flow
Configuration Levels
// Level 1: Method chain - Simple flow
const flow = new Flow()
.start(classifier)
.when('A', agentA)
.when('B', agentB);
// Level 2: Array - Multiple conditions
const flow = new Flow({
routes: [
{ condition: 'support', agent: support },
{ condition: 'sales', agent: sales }
]
});
// Level 3: Instance - Full control
const flow = new Flow({
start: classifier,
routes: [
{
condition: (output) => output.includes('urgent'),
agent: urgentHandler,
priority: 1
}
],
fallback: generalAgent
});Flow Methods
| Method | Description |
|---|---|
.start() | Set starting agent |
.when() | Add conditional branch |
.otherwise() | Set fallback handler |
.run() | Execute the flow |
API Reference
Workflows ModuleWorkflow and flow patterns
Conditions ModuleConditional routing
Best Practices
Keep flows simple
Start with 2-3 branches, add complexity as needed.
Always have a fallback
Use .otherwise() to catch unmatched cases.
Test each path
Verify all branches work before production.