Skip to main content
AgentFlow enables complex multi-step pipelines with routing, parallel execution, and context sharing between steps.
AgentFlow replaces Workflow and Pipeline as the recommended class name. The old names still work as silent aliases.

Quick Start

1

Install

npm install praisonai
2

Create Flow

import { Agent, AgentFlow } from 'praisonai';

const researcher = new Agent({
  instructions: 'Research the topic'
});

const writer = new Agent({
  instructions: 'Write based on research'
});

const flow = new AgentFlow('content-pipeline')
  .agent(researcher, 'Research AI trends')
  .agent(writer, 'Write article based on research');

const { output } = await flow.run('AI in 2025');

How It Works

ComponentDescription
StepsIndividual processing units (agents or functions)
ContextShared state between steps
OutputFinal result from the last step
ResultsAll intermediate step results

Configuration Options

Step Configuration

flow.addStep({
  name: 'process',
  execute: async (input, context) => {
    return processData(input);
  },
  condition: (context) => context.get('shouldRun'),
  onError: 'retry',
  maxRetries: 3
});
OptionTypeDefaultDescription
namestringrequiredStep identifier
executefunctionrequiredAsync function to process input
conditionfunctionundefinedCondition to run the step
onError'fail' | 'skip' | 'retry''fail'Error handling behavior
maxRetriesnumber0Maximum retry attempts

Common Patterns

import { Agent, AgentFlow } from 'praisonai';

const researcher = new Agent({ instructions: 'Research topics' });
const writer = new Agent({ instructions: 'Write content' });

const flow = new AgentFlow('research-pipeline')
  .agent(researcher, 'Research the topic')
  .agent(writer, 'Write based on research');

const { output } = await flow.run('AI trends');

Workflow Helpers

Parallel Execution

import { parallel } from 'praisonai';

const [sentiment, summary, keywords] = await parallel([
  async () => sentimentAgent.chat(document),
  async () => summaryAgent.chat(document),
  async () => keywordAgent.chat(document)
]);

Conditional Routing

import { route } from 'praisonai';

const result = await route([
  {
    condition: () => query.includes('technical'),
    execute: async () => techAgent.chat(query)
  },
  {
    condition: () => query.includes('billing'),
    execute: async () => billingAgent.chat(query)
  }
], async () => generalAgent.chat(query));  // Default fallback

Loop Pattern

import { loop } from 'praisonai';

const result = await loop(
  async (context) => improverAgent.chat(context.get('draft')),
  (result) => result.includes('DONE'),  // Condition to stop
  { maxIterations: 5 }
);

Best Practices

Store intermediate results in context rather than return values.
context.set('research', researchData);
// Later steps can access via context.get('research')
Use onError and maxRetries for resilient flows.
.addStep({
  name: 'api-call',
  execute: async (input) => callApi(input),
  onError: 'retry',
  maxRetries: 3
})
Skip steps conditionally based on context state.
.addStep({
  name: 'optional',
  condition: (ctx) => ctx.get('needsProcessing'),
  execute: async (input) => process(input)
})

Backward Compatibility

All old names work as silent aliases with no deprecation warnings.
// All of these are equivalent
import { AgentFlow, Workflow, Pipeline } from 'praisonai';

const flow1 = new AgentFlow('my-flow');
const flow2 = new Workflow('my-flow');
const flow3 = new Pipeline('my-flow');

// They are the same class
console.log(AgentFlow === Workflow);   // true
console.log(AgentFlow === Pipeline);   // true