12#include <agents-cpp/workflow.h>
93 std::shared_ptr<AgentContext> context,
111 const String& prompt_template,
125 const String& prompt_template,
171 std::vector<Task> tasks_;
181 std::function<
JsonObject(
const std::vector<JsonObject>&)> aggregator_;
186 double voting_threshold_ = 0.5;
191 std::shared_ptr<LLMInterface> llm_;
198 std::vector<JsonObject> runTasksInParallel(
const String& input);
205 static JsonObject defaultSectioningAggregator(
const std::vector<JsonObject>& results);
212 static JsonObject defaultVotingAggregator(
const std::vector<JsonObject>& results);
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 setStrategy(Strategy strategy)
Set the strategy.
void setAggregator(std::function< JsonObject(const std::vector< JsonObject > &)> aggregator)
Set the aggregation function for task results.
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.
JsonObject run(const String &input) override
Execute the workflow with input.
Strategy
Enum for parallelization strategy.
Definition parallelization_workflow.h:33
@ VOTING
Run same task multiple times for consensus.
Definition parallelization_workflow.h:41
@ SECTIONING
Break task into independent subtasks.
Definition parallelization_workflow.h:37
void addTask(const String &name, const String &prompt_template, const JsonObject &context=JsonObject())
Add a task to the workflow with basic params.
void setVotingThreshold(double threshold)
Set the voting threshold (for VOTING mode)
void init()
Initialize the workflow.
JsonObject run()
Execute using the latest USER message from context memory.
Workflow(std::shared_ptr< AgentContext > context)
Constructor.
Worflows Namespace.
Definition workflow.h:22
Framework Namespace.
Definition agent.h:18
nlohmann::json JsonObject
JSON object type.
Definition types.h:39
std::string String
String type.
Definition types.h:27
Task definition for parallel execution.
Definition parallelization_workflow.h:48
std::function< String(const String &)> prompt_fn
The prompt function of the task.
Definition parallelization_workflow.h:64
std::function< JsonObject(const String &)> result_parser
The result parser of the task.
Definition parallelization_workflow.h:68
JsonObject context
The context of the task.
Definition parallelization_workflow.h:60
String name
The name of the task.
Definition parallelization_workflow.h:52
Task(const String &name, const String &prompt_template, const JsonObject &context=JsonObject(), std::function< String(const String &)> prompt_fn=nullptr, std::function< JsonObject(const String &)> result_parser=nullptr)
Constructor.
Definition parallelization_workflow.h:78
String prompt_template
The prompt template of the task.
Definition parallelization_workflow.h:56