Skip to main content
Parallelization enables concurrent execution of multiple agent tasks, dramatically improving performance for independent operations and complex workflows.

Overview

The Parallelization primitive allows you to run multiple agent requests simultaneously rather than sequentially. By executing independent tasks in parallel, you can significantly reduce total execution time, improve resource utilization, and build more responsive applications. Parallelization is essential for:
  • Performance Optimization: Reduce total execution time by running tasks concurrently
  • Scalable Workflows: Handle high-throughput scenarios with parallel processing
  • Independent Operations: Execute unrelated tasks simultaneously
  • Data Processing: Process multiple data items or files in parallel
  • Multi-Source Aggregation: Gather information from multiple sources simultaneously

Concurrent Execution

Run multiple agent requests at the same time instead of waiting for each to complete

Independent Sessions

Each parallel task runs in its own isolated session with independent state

Flexible Coordination

Combine parallel execution with sequential workflows for complex patterns

Result Aggregation

Collect and combine results from all parallel tasks

How Parallelization Works

When you execute multiple agent requests in parallel:
  1. Dispatch: All requests are sent simultaneously
  2. Parallel Execution: Each agent task runs independently in its own session
  3. Isolation: Tasks don’t share state or interfere with each other
  4. Completion: Tasks complete at their own pace based on complexity
  5. Aggregation: Results are collected and can be combined as needed
Independence Requirement: Parallelized tasks should be independent - they shouldn’t depend on each other’s results. For dependent tasks, use sequential execution or workflows.

Code Examples

Basic Parallel Execution

Parallel Data Processing

Parallel Web Scraping

Parallel with Different Modes

Result Aggregation

Use Cases

1. Batch Data Processing

Process large datasets by splitting them across parallel agents:

2. Multi-Source Research

Gather information from multiple sources simultaneously:

3. Content Generation at Scale

Generate multiple content pieces in parallel:

4. Testing and Validation

Run parallel test scenarios:

5. Multi-Language Translation

Translate content to multiple languages simultaneously:

6. Distributed Analysis

Analyze different dimensions of data in parallel:

Best Practices

Task Independence

Resource Management

Concurrency Limits: While Agentbase can handle many parallel requests, consider implementing concurrency limits for very large batches to avoid overwhelming your application.

Error Handling

Performance Optimization

Batch Appropriately

Group tasks into reasonable batch sizes (10-50 per batch)

Use Right Mode

Match agent mode to task complexity for optimal resource use

Monitor Resources

Track performance metrics to optimize batch sizes

Cancel Unnecessary

Cancel remaining tasks if you have enough results

Integration with Other Primitives

With Multi-Agent

Parallelize across different agent specialists:
Learn more: Multi-Agent Primitive

With Custom Tools

Parallel tool execution:
Learn more: Custom Tools Primitive

With Sessions

Each parallel task gets its own session:
Learn more: Sessions Primitive

Performance Considerations

Speedup Calculation

Theoretical speedup with parallel execution:
Example:

Optimal Batch Sizing

Find the sweet spot for your use case:
  • Too Small (1-5 tasks): Underutilizes parallelization
  • Optimal (10-50 tasks): Good balance of throughput and manageability
  • Too Large (100+ tasks): May overwhelm system, consider batching

Memory Considerations

Monitor memory usage with large parallel operations:

Troubleshooting

Problem: Some parallel tasks fail while others succeedSolution: Use Promise.allSettled and handle failures gracefully
Problem: Parallel execution not as fast as expectedPossible Causes:
  • Tasks aren’t actually independent
  • Too many tasks overwhelming system
  • One slow task bottlenecking others
Solutions:
  • Verify task independence
  • Implement concurrency limits
  • Identify and optimize slow tasks
  • Consider different batch sizes
Problem: Running out of memory with large parallel batchesSolution: Implement streaming or chunked processing
Problem: Task depends on results from another parallel taskSolution: Use sequential execution or workflow patterns

Workflows

Structured DAGs for complex task dependencies

Multi-Agent

Coordinate multiple specialized agents

Sessions

Each parallel task gets its own session

Custom Tools

Parallel tool execution across tasks

Additional Resources

API Reference

Complete API documentation

Best Practices

Optimization best practices

Use Cases

Parallel execution examples
Remember: Parallelization is most effective for independent tasks of similar complexity. Use it to dramatically reduce execution time for batch operations, multi-source data gathering, and scalable processing.