Agents 0.0.2
Edge AI Agents SDK
Loading...
Searching...
No Matches
agents::workflows::ParallelizationWorkflow Class Reference

A workflow that runs multiple tasks in parallel. More...

#include <parallelization_workflow.h>

Inheritance diagram for agents::workflows::ParallelizationWorkflow:
agents::workflows::Workflow

Classes

struct  Task
 Task definition for parallel execution. More...
 

Public Types

enum class  Strategy {
  SECTIONING ,
  VOTING
}
 Enum for parallelization strategy. More...
 

Public Member Functions

 ParallelizationWorkflow (std::shared_ptr< AgentContext > context, Strategy strategy=Strategy::SECTIONING)
 Constructor with context.
 
void addTask (const Task &task)
 Add a task to the workflow.
 
void addTask (const String &name, const String &prompt_template, const JsonObject &context=JsonObject())
 Add a task to the workflow with basic params.
 
void addTask (const String &name, const String &prompt_template, std::function< String(const String &)> prompt_fn, std::function< JsonObject(const String &)> result_parser, const JsonObject &context=JsonObject())
 Add a task to the workflow with generators and parser.
 
void setAggregator (std::function< JsonObject(const std::vector< JsonObject > &)> aggregator)
 Set the aggregation function for task results.
 
void setStrategy (Strategy strategy)
 Set the strategy.
 
void init ()
 Initialize the workflow.
 
void setVotingThreshold (double threshold)
 Set the voting threshold (for VOTING mode)
 
JsonObject run (const String &input) override
 Execute the workflow with input.
 
JsonObject run ()
 Execute using the latest USER message from context memory.
 
virtual void runAsync (const String &input, std::function< void(const JsonObject &)> callback)
 Run the workflow with a user input asynchronously.
 
std::shared_ptr< AgentContextgetContext () const
 Get the workflow's context.
 
void setStepCallback (std::function< void(const String &, const JsonObject &)> callback)
 Set a callback for intermediate steps.
 
void setMaxSteps (int max_steps)
 Set maximum number of steps.
 
int getMaxSteps () const
 Get maximum number of steps.
 

Detailed Description

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.

Member Enumeration Documentation

◆ 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.

Constructor & Destructor Documentation

◆ ParallelizationWorkflow()

agents::workflows::ParallelizationWorkflow::ParallelizationWorkflow ( std::shared_ptr< AgentContext > context,
Strategy strategy = Strategy::SECTIONING )

Constructor with context.

Parameters
contextThe context of the workflow
strategyThe strategy of the workflow

Member Function Documentation

◆ addTask() [1/3]

void agents::workflows::ParallelizationWorkflow::addTask ( const String & name,
const String & prompt_template,
const JsonObject & context = JsonObject() )

Add a task to the workflow with basic params.

Parameters
nameThe name of the task
prompt_templateThe prompt template of the task
contextThe context of the task

◆ addTask() [2/3]

void agents::workflows::ParallelizationWorkflow::addTask ( const String & name,
const String & prompt_template,
std::function< String(const String &)> prompt_fn,
std::function< JsonObject(const String &)> result_parser,
const JsonObject & context = JsonObject() )

Add a task to the workflow with generators and parser.

Parameters
nameThe name of the task
prompt_templateThe prompt template of the task
prompt_fnThe prompt function of the task
result_parserThe result parser of the task
contextThe context of the task

◆ addTask() [3/3]

void agents::workflows::ParallelizationWorkflow::addTask ( const Task & task)

Add a task to the workflow.

Parameters
taskThe task to add
Examples
parallel_example.cpp.

◆ 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

Execute the workflow with input.

Parameters
inputThe input to the workflow
Returns
The output of the workflow

Implements agents::workflows::Workflow.

Examples
parallel_example.cpp.

◆ 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
inputThe user input
callbackThe callback

◆ setAggregator()

void agents::workflows::ParallelizationWorkflow::setAggregator ( std::function< JsonObject(const std::vector< JsonObject > &)> aggregator)

Set the aggregation function for task results.

Parameters
aggregatorThe aggregation function
Examples
parallel_example.cpp.

◆ setMaxSteps()

void agents::workflows::Workflow::setMaxSteps ( int max_steps)
inherited

Set maximum number of steps.

Parameters
max_stepsThe maximum number of steps

◆ setStepCallback()

void agents::workflows::Workflow::setStepCallback ( std::function< void(const String &, const JsonObject &)> callback)
inherited

Set a callback for intermediate steps.

Parameters
callbackThe callback
Examples
prompt_chain_example.cpp.

◆ setStrategy()

void agents::workflows::ParallelizationWorkflow::setStrategy ( Strategy strategy)

Set the strategy.

Parameters
strategyThe strategy

◆ setVotingThreshold()

void agents::workflows::ParallelizationWorkflow::setVotingThreshold ( double threshold)

Set the voting threshold (for VOTING mode)

Parameters
thresholdThe threshold