Skip to main content
Agents can follow conditional flows - branch based on conditions and data.

Quick Start

1

Create a Flow

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
2

With Default Path

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

MethodDescription
.start()Set starting agent
.when()Add conditional branch
.otherwise()Set fallback handler
.run()Execute the flow

API Reference

Workflows Module

Workflow and flow patterns

Conditions Module

Conditional routing

Best Practices

Start with 2-3 branches, add complexity as needed.
Use .otherwise() to catch unmatched cases.
Verify all branches work before production.