Skip to main content

Overview

The ConcurrentWorkflow class provides a framework for executing multiple agents concurrently on the same task, with optional dashboard monitoring, streaming callbacks, and various output formatting options. It uses ThreadPoolExecutor to manage concurrent execution and provides real-time status tracking for each agent.

Key Features

  • Concurrent Execution: Run multiple agents simultaneously on the same task
  • Real-time Dashboard: Monitor agent status and outputs in real-time
  • Streaming Callbacks: Get real-time updates as agents generate outputs
  • Flexible Output Formatting: Multiple output format options
  • Auto-save Support: Automatically save conversation history
  • Error Handling: Graceful error handling with status tracking
  • Batch Processing: Process multiple tasks sequentially with concurrent agents

Installation

Class Definition

Parameters

str
default:"auto-generated"
Unique identifier for the workflow instance. Auto-generated if not provided.
str
default:"ConcurrentWorkflow"
Human-readable name for the workflow
str
default:"Execution of multiple agents concurrently"
Description of the workflow’s purpose
List[Union[Agent, Callable]]
required
List of agents to execute concurrently. Must not be None or empty.
bool
default:"True"
Whether to automatically save workflow metadata
str
default:"dict-all-except-first"
Format for output formatting. Options include “dict-all-except-first”, “dict”, “list”, “str”
int
default:"1"
Maximum number of execution loops (currently unused in concurrent execution)
bool
default:"False"
Whether to enable automatic prompt engineering for all agents
bool
default:"False"
Whether to display real-time dashboard during execution
bool
default:"True"
Whether to automatically save conversation history to workspace
bool
default:"False"
Whether to enable verbose logging

Methods

run(task, img=None, imgs=None, streaming_callback=None)

Execute all agents concurrently on the given task.
str
required
The task to be executed by all agents
Optional[str]
default:"None"
Single image path for agents that support image input
Optional[List[str]]
default:"None"
List of image paths for agents that support multiple images
Optional[Callable[[str, str, bool], None]]
default:"None"
Callback function for streaming updates. Called with (agent_name, chunk, is_final) parameters.
Union[Dict, List, str]
Formatted conversation history based on output_type

batch_run(tasks, imgs=None, streaming_callback=None)

Execute workflow on multiple tasks sequentially.
List[str]
required
List of tasks to be executed
Optional[List[str]]
default:"None"
List of image paths corresponding to each task
Optional[Callable[[str, str, bool], None]]
default:"None"
Callback function for streaming updates
List[Union[Dict, List, str]]
List of results for each task

run_with_dashboard(task, img=None, imgs=None, streaming_callback=None)

Execute agents with real-time dashboard monitoring.
str
required
The task to be executed by all agents
Optional[str]
default:"None"
Single image path for agents that support image input
Optional[List[str]]
default:"None"
List of image paths for agents that support multiple images
Optional[Callable[[str, str, bool], None]]
default:"None"
Callback function for streaming updates
Union[Dict, List, str]
Formatted conversation history based on output_type

cleanup()

Clean up resources and connections. Called automatically after each run.

reliability_check()

Validate workflow configuration. Raises:
  • ValueError: If no agents are provided or agents list is empty

activate_auto_prompt_engineering()

Enable automatic prompt engineering for all agents in the workflow.

display_agent_dashboard(title="ConcurrentWorkflow Dashboard", is_final=False)

Display real-time dashboard showing agent status and outputs.
str
default:"ConcurrentWorkflow Dashboard"
Title to display for the dashboard
bool
default:"False"
Whether this is the final dashboard display

Attributes

Usage Examples

Basic Concurrent Workflow

With Real-Time Dashboard

With Streaming Callbacks

Batch Processing

With Image Input

Custom Output Types

With Autosave

Auto Prompt Engineering

Error Handling

Dashboard Output Example

When show_dashboard=True, you’ll see real-time updates like:

Best Practices

  1. Agent Diversity: Use agents with different perspectives for richer analysis
  2. Dashboard for Monitoring: Enable dashboard during development to monitor agent progress
  3. Streaming Callbacks: Use streaming callbacks for real-time feedback in production
  4. Error Handling: Always wrap concurrent execution in try-except blocks
  5. Resource Management: Be mindful of API rate limits when running many agents
  6. Task Design: Ensure the task benefits from multiple concurrent perspectives
  7. Autosave: Enable autosave for important analyses

Common Use Cases

  • Multi-Perspective Analysis: Get technical, business, and user perspectives simultaneously
  • Consensus Building: Run multiple agents and aggregate their outputs
  • Parallel Research: Research different aspects of a topic concurrently
  • Voting Systems: Multiple agents vote on decisions
  • Quality Assurance: Multiple agents review the same content
  • Competitive Analysis: Different agents analyze competing solutions

Performance Considerations

  • CPU Utilization: Uses ~95% of available CPU cores by default
  • Concurrent Execution: All agents run truly concurrently using ThreadPoolExecutor
  • Memory Usage: Each agent maintains its own context, consider memory for many agents
  • API Rate Limits: Be aware of rate limits when using cloud-based LLMs