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

A workflow where a central orchestrator delegates tasks to workers. More...

#include <orchestrator_workflow.h>

Inheritance diagram for agents::workflows::OrchestratorWorkflow:
agents::workflows::Workflow

Classes

struct  Worker
 Worker definition. More...
 

Public Member Functions

 OrchestratorWorkflow (std::shared_ptr< AgentContext > context, const String &orchestrator_prompt_template="")
 Constructor with context and orchestrator prompt.
 
void addWorker (const Worker &worker)
 Add a worker to the workflow.
 
void addWorker (const String &name, const String &description, const String &prompt_template, std::shared_ptr< LLMInterface > worker_llm=nullptr)
 Add a worker with basic params.
 
void init ()
 Initialize the workflow.
 
JsonObject run (const String &input) override
 Execute the workflow with input.
 
void setMaxIterations (int max_iterations)
 Set the max number of iterations.
 
void setSynthesizer (std::function< JsonObject(const std::vector< JsonObject > &)> synthesizer)
 Set the result synthesizer function.
 
void setOrchestratorPrompt (const String &orchestrator_prompt_template)
 Set the orchestrator prompt template.
 
JsonObject getWorkersSchema () const
 Get the schema for available workers.
 
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 where a central orchestrator delegates tasks to workers.

In this workflow, a central LLM (orchestrator) dynamically breaks down tasks, delegates them to worker LLMs, and synthesizes their results. This is well-suited for complex tasks where subtasks can't be predetermined.

Examples
orchestrator_example.cpp.

Constructor & Destructor Documentation

◆ OrchestratorWorkflow()

agents::workflows::OrchestratorWorkflow::OrchestratorWorkflow ( std::shared_ptr< AgentContext > context,
const String & orchestrator_prompt_template = "" )

Constructor with context and orchestrator prompt.

Parameters
contextThe context of the workflow
orchestrator_prompt_templateThe orchestrator prompt template

Member Function Documentation

◆ addWorker() [1/2]

void agents::workflows::OrchestratorWorkflow::addWorker ( const String & name,
const String & description,
const String & prompt_template,
std::shared_ptr< LLMInterface > worker_llm = nullptr )

Add a worker with basic params.

Parameters
nameThe name of the worker
descriptionThe description of the worker
prompt_templateThe prompt template of the worker
worker_llmThe llm of the worker

◆ addWorker() [2/2]

void agents::workflows::OrchestratorWorkflow::addWorker ( const Worker & worker)

Add a worker to the workflow.

Parameters
workerThe worker to add
Examples
orchestrator_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

◆ getWorkersSchema()

JsonObject agents::workflows::OrchestratorWorkflow::getWorkersSchema ( ) const

Get the schema for available workers.

Returns
The schema for available workers

◆ run()

JsonObject agents::workflows::OrchestratorWorkflow::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
orchestrator_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

◆ setMaxIterations()

void agents::workflows::OrchestratorWorkflow::setMaxIterations ( int max_iterations)

Set the max number of iterations.

Parameters
max_iterationsThe max number of iterations

◆ setMaxSteps()

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

Set maximum number of steps.

Parameters
max_stepsThe maximum number of steps

◆ setOrchestratorPrompt()

void agents::workflows::OrchestratorWorkflow::setOrchestratorPrompt ( const String & orchestrator_prompt_template)

Set the orchestrator prompt template.

Parameters
orchestrator_prompt_templateThe orchestrator prompt template
Examples
orchestrator_example.cpp.

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

◆ setSynthesizer()

void agents::workflows::OrchestratorWorkflow::setSynthesizer ( std::function< JsonObject(const std::vector< JsonObject > &)> synthesizer)

Set the result synthesizer function.

Parameters
synthesizerThe synthesizer function
Examples
orchestrator_example.cpp.