Parallel Execution
Run multiple AI agents concurrently using standard JavaScript/TypeScript Promise.all to compare or combine responses.
Overview
Mosaic agents are designed to work seamlessly with JavaScript's native concurrency patterns. Run multiple agents in parallel to speed up execution, compare outputs from different models, or implement voting systems.
Basic Parallel Execution
Use Promise.all to run multiple agents simultaneously:
parallel-basic.ts
Comparing Results
Use parallel execution to get multiple perspectives and choose the best one:
parallel-compare.ts
Batch Processing
Process multiple items concurrently with controlled parallelism:
parallel-batch.ts
Tip
Control concurrency to avoid rate limits and manage costs. Most providers have request-per-minute limits.
Error Handling
Use Promise.allSettled when you need results even if some fail:
parallel-errors.ts