⚪AsyncWorkflow
The AsyncWorkflow
class represents an asynchronous workflow that executes tasks concurrently using multiple agents. It allows for efficient task management, leveraging Python's asyncio
for concurrent execution.
Key Features
Concurrent Task Execution: Distribute tasks across multiple agents asynchronously.
Configurable Workers: Limit the number of concurrent workers (agents) for better resource management.
Autosave Results: Optionally save the task execution results automatically.
Verbose Logging: Enable detailed logging to monitor task execution.
Error Handling: Gracefully handles exceptions raised by agents during task execution.
Attributes
name
str
The name of the workflow.
agents
List[Agent]
A list of agents participating in the workflow.
max_workers
int
The maximum number of concurrent workers (default: 5).
dashboard
bool
Whether to display a dashboard (currently not implemented).
autosave
bool
Whether to autosave task results (default: False
).
verbose
bool
Whether to enable detailed logging (default: False
).
task_pool
List
A pool of tasks to be executed.
results
List
A list to store results of executed tasks.
loop
asyncio.EventLoop
The event loop for asynchronous execution.
Description: Initializes the AsyncWorkflow
with specified agents, configuration, and options.
Parameters: - name
(str
): Name of the workflow. Default: "AsyncWorkflow". - agents
(List[Agent]
): A list of agents. Default: None
. - max_workers
(int
): The maximum number of workers. Default: 5
. - dashboard
(bool
): Enable dashboard visualization (placeholder for future implementation). - autosave
(bool
): Enable autosave of task results. Default: False
. - verbose
(bool
): Enable detailed logging. Default: False
. - **kwargs
: Additional parameters for BaseWorkflow
.
_execute_agent_task
_execute_agent_task
Description: Executes a single task asynchronously using a given agent.
Parameters: - agent
(Agent
): The agent responsible for executing the task. - task
(str
): The task to be executed.
Returns: - Any
: The result of the task execution or an error message in case of an exception.
Example:
run
run
Description: Executes the specified task concurrently across all agents.
Parameters: - task
(str
): The task to be executed by all agents.
Returns: - List[Any]
: A list of results or error messages returned by the agents.
Raises: - ValueError
: If no agents are provided in the workflow.
Example:
Production-Grade Financial Example: Multiple Agents
Example: Stock Analysis and Investment Strategy
Last updated