Skip to main content
Agents can process lists of items one by one - like handling emails, analyzing files, or transforming data.

Quick Start

1

Process a List with Agent

import { Agent, loop } from 'praisonai';

const agent = new Agent({
  instructions: 'Summarize the given text concisely'
});

const texts = [
  'First article about AI...',
  'Second article about robotics...',
  'Third article about automation...'
];

const results = await loop(agent, { over: 'texts' }).run({ texts });
console.log(results);
// ['AI summary...', 'Robotics summary...', 'Automation summary...']
2

Process CSV File

const results = await loop(agent, { 
  fromCsv: './customers.csv'
}).run({});
// Each row is processed by the agent

User Interaction Flow


Configuration Levels

// Level 1: String - Simple field reference
const result = await loop(agent, { over: 'items' }).run({ items });

// Level 2: Dict - With options
const result = await loop(agent, {
  over: 'items',
  maxIterations: 100,
  continueOnError: true
}).run({ items });

// Level 3: Instance - Full control with callbacks
const result = await loop(agent, {
  over: 'items',
  onIteration: (item, index, total) => {
    console.log(`Processing ${index + 1} of ${total}`);
  },
  onError: (error, item) => {
    console.error(`Failed: ${item}`);
  }
}).run({ items });

Data Sources

SourceUse Case
over: 'items'Array in your code
fromCsv: 'file.csv'CSV file with rows
fromFile: 'list.txt'Text file (one item per line)

Common Examples

Email Processing

const emails = [
  { from: '[email protected]', body: 'Meeting request...' },
  { from: '[email protected]', body: 'Question about...' }
];

const responses = await loop(agent, { over: 'emails' }).run({ emails });

Handle Errors Gracefully

const result = await loop(agent, {
  over: 'items',
  continueOnError: true
}).run({ items });

console.log(`Success: ${result.results.length}`);
console.log(`Failed: ${result.errors.length}`);

API Reference

Loop

Loop class documentation

Best Practices

Use maxIterations to prevent runaway loops. Default is 1000.
Use continueOnError: true to process all items even if some fail.
Use onIteration callback to show progress for long-running loops.