A workflow that runs multiple tasks in parallel.
More...
#include <parallelization_workflow.h>
A workflow that runs multiple tasks in parallel.
This workflow allows LLMs to work simultaneously on a task and have their outputs aggregated. It supports two key variations:
- Sectioning: Breaking a task into independent subtasks run in parallel
- Voting: Running the same task multiple times to get diverse outputs
- Examples
- actor_agent_example.cpp, and parallel_example.cpp.
◆ Strategy
Enum for parallelization strategy.
- Note
- This is an enum for the parallelization strategy. It contains the SECTIONING and VOTING strategies.
Enumerator |
---|
SECTIONING | Break task into independent subtasks.
|
VOTING | Run same task multiple times for consensus.
|
◆ ParallelizationWorkflow()
Constructor with context.
- Parameters
-
context | The context of the workflow |
strategy | The strategy of the workflow |
◆ addTask() [1/3]
Add a task to the workflow with basic params.
- Parameters
-
name | The name of the task |
prompt_template | The prompt template of the task |
context | The context of the task |
◆ addTask() [2/3]
Add a task to the workflow with generators and parser.
- Parameters
-
name | The name of the task |
prompt_template | The prompt template of the task |
prompt_fn | The prompt function of the task |
result_parser | The result parser of the task |
context | The context of the task |
◆ addTask() [3/3]
void agents::workflows::ParallelizationWorkflow::addTask |
( |
const Task & | task | ) |
|
◆ getContext()
std::shared_ptr< AgentContext > agents::workflows::Workflow::getContext |
( |
| ) |
const |
|
inherited |
Get the workflow's context.
- Returns
- The context
◆ getMaxSteps()
int agents::workflows::Workflow::getMaxSteps |
( |
| ) |
const |
|
inherited |
Get maximum number of steps.
- Returns
- The maximum number of steps
◆ run() [1/2]
JsonObject agents::workflows::ParallelizationWorkflow::run |
( |
| ) |
|
Execute using the latest USER message from context memory.
- Returns
- The output of the workflow
◆ run() [2/2]
JsonObject agents::workflows::ParallelizationWorkflow::run |
( |
const String & | input | ) |
|
|
overridevirtual |
◆ runAsync()
virtual void agents::workflows::Workflow::runAsync |
( |
const String & | input, |
|
|
std::function< void(const JsonObject &)> | callback ) |
|
virtualinherited |
Run the workflow with a user input asynchronously.
- Parameters
-
input | The user input |
callback | The callback |
◆ setAggregator()
void agents::workflows::ParallelizationWorkflow::setAggregator |
( |
std::function< JsonObject(const std::vector< JsonObject > &)> | aggregator | ) |
|
Set the aggregation function for task results.
- Parameters
-
aggregator | The aggregation function |
- Examples
- parallel_example.cpp.
◆ setMaxSteps()
void agents::workflows::Workflow::setMaxSteps |
( |
int | max_steps | ) |
|
|
inherited |
Set maximum number of steps.
- Parameters
-
max_steps | The maximum number of steps |
◆ setStepCallback()
void agents::workflows::Workflow::setStepCallback |
( |
std::function< void(const String &, const JsonObject &)> | callback | ) |
|
|
inherited |
◆ setStrategy()
void agents::workflows::ParallelizationWorkflow::setStrategy |
( |
Strategy | strategy | ) |
|
Set the strategy.
- Parameters
-
◆ setVotingThreshold()
void agents::workflows::ParallelizationWorkflow::setVotingThreshold |
( |
double | threshold | ) |
|
Set the voting threshold (for VOTING mode)
- Parameters
-