Agents 0.0.2
Edge AI Agents SDK
|
A workflow that runs multiple tasks in parallel. More...
#include <parallelization_workflow.h>
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< AgentContext > | getContext () 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. | |
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:
|
strong |
agents::workflows::ParallelizationWorkflow::ParallelizationWorkflow | ( | std::shared_ptr< AgentContext > | context, |
Strategy | strategy = Strategy::SECTIONING ) |
Constructor with context.
context | The context of the workflow |
strategy | The strategy of the workflow |
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.
name | The name of the task |
prompt_template | The prompt template of the task |
context | The context of the task |
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.
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 |
void agents::workflows::ParallelizationWorkflow::addTask | ( | const Task & | task | ) |
Add a task to the workflow.
task | The task to add |
|
inherited |
Get the workflow's context.
|
inherited |
Get maximum number of steps.
JsonObject agents::workflows::ParallelizationWorkflow::run | ( | ) |
Execute using the latest USER message from context memory.
|
overridevirtual |
Execute the workflow with input.
input | The input to the workflow |
Implements agents::workflows::Workflow.
|
virtualinherited |
Run the workflow with a user input asynchronously.
input | The user input |
callback | The callback |
void agents::workflows::ParallelizationWorkflow::setAggregator | ( | std::function< JsonObject(const std::vector< JsonObject > &)> | aggregator | ) |
Set the aggregation function for task results.
aggregator | The aggregation function |
|
inherited |
Set maximum number of steps.
max_steps | The maximum number of steps |
|
inherited |
Set a callback for intermediate steps.
callback | The callback |
void agents::workflows::ParallelizationWorkflow::setStrategy | ( | Strategy | strategy | ) |
Set the strategy.
strategy | The strategy |
void agents::workflows::ParallelizationWorkflow::setVotingThreshold | ( | double | threshold | ) |
Set the voting threshold (for VOTING mode)
threshold | The threshold |