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

An evaluator-optimizer workflow where one LLM optimizes output based on another's feedback. More...

#include <evaluator_workflow.h>

Inheritance diagram for agents::workflows::EvaluatorWorkflow:
agents::workflows::Workflow

Public Member Functions

 EvaluatorWorkflow (std::shared_ptr< AgentContext > context, const String &optimizer_prompt_template="", const String &evaluator_prompt_template="")
 Constructor with LLM interfaces for optimizer and evaluator.
 
void init ()
 Initialize the workflow.
 
JsonObject run (const String &input) override
 Execute the workflow with input.
 
void setEvaluationCriteria (const std::vector< String > &criteria)
 Set the evaluation criteria for the evaluator.
 
void setMaxIterations (int max_iterations)
 Set the max number of feedback iterations.
 
void setImprovementThreshold (double threshold)
 Set the improvement threshold (minimum score to accept a response)
 
void setMinimumAcceptableScore (double threshold)
 Set the minimum acceptable score.
 
void setOptimizerPromptTemplate (const String &prompt_template)
 Set the optimizer prompt template.
 
void setOptimizerPrompt (const String &prompt_template)
 Set the optimizer prompt.
 
void setEvaluatorPromptTemplate (const String &prompt_template)
 Set the evaluator prompt template.
 
void setEvaluatorPrompt (const String &prompt_template)
 Set the evaluator prompt.
 
void setOptimizer (std::function< String(const String &, const JsonObject &)> optimizer)
 Set the optimizer function.
 
void setEvaluator (std::function< JsonObject(const String &, const String &)> evaluator)
 Set the evaluator function.
 
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

An evaluator-optimizer workflow where one LLM optimizes output based on another's feedback.

In this workflow, one LLM call generates a response while another provides evaluation and feedback in a loop. This pattern is effective when we have clear evaluation criteria and iterative refinement provides value.

Examples
evaluator_optimizer_example.cpp.

Constructor & Destructor Documentation

◆ EvaluatorWorkflow()

agents::workflows::EvaluatorWorkflow::EvaluatorWorkflow ( std::shared_ptr< AgentContext > context,
const String & optimizer_prompt_template = "",
const String & evaluator_prompt_template = "" )

Constructor with LLM interfaces for optimizer and evaluator.

Parameters
contextThe context to use
optimizer_prompt_templateThe optimizer prompt template
evaluator_prompt_templateThe evaluator prompt template

Member Function Documentation

◆ 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()

JsonObject agents::workflows::EvaluatorWorkflow::run ( const String & input)
overridevirtual

Execute the workflow with input.

Parameters
inputThe input to execute the workflow with
Returns
The result of the workflow execution

Implements agents::workflows::Workflow.

Examples
evaluator_optimizer_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

◆ setEvaluationCriteria()

void agents::workflows::EvaluatorWorkflow::setEvaluationCriteria ( const std::vector< String > & criteria)

Set the evaluation criteria for the evaluator.

Parameters
criteriaThe evaluation criteria to set
Examples
evaluator_optimizer_example.cpp.

◆ setEvaluator()

void agents::workflows::EvaluatorWorkflow::setEvaluator ( std::function< JsonObject(const String &, const String &)> evaluator)

Set the evaluator function.

Parameters
evaluatorThe evaluator function to set
Examples
evaluator_optimizer_example.cpp.

◆ setEvaluatorPrompt()

void agents::workflows::EvaluatorWorkflow::setEvaluatorPrompt ( const String & prompt_template)
inline

Set the evaluator prompt.

Parameters
prompt_templateThe evaluator prompt to set
Examples
evaluator_optimizer_example.cpp.

◆ setEvaluatorPromptTemplate()

void agents::workflows::EvaluatorWorkflow::setEvaluatorPromptTemplate ( const String & prompt_template)

Set the evaluator prompt template.

Parameters
prompt_templateThe evaluator prompt template to set

◆ setImprovementThreshold()

void agents::workflows::EvaluatorWorkflow::setImprovementThreshold ( double threshold)

Set the improvement threshold (minimum score to accept a response)

Parameters
thresholdThe improvement threshold to set

◆ setMaxIterations()

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

Set the max number of feedback iterations.

Parameters
max_iterationsThe max number of feedback iterations to set
Examples
evaluator_optimizer_example.cpp.

◆ setMaxSteps()

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

Set maximum number of steps.

Parameters
max_stepsThe maximum number of steps

◆ setMinimumAcceptableScore()

void agents::workflows::EvaluatorWorkflow::setMinimumAcceptableScore ( double threshold)
inline

Set the minimum acceptable score.

Parameters
thresholdThe minimum acceptable score to set
Examples
evaluator_optimizer_example.cpp.

◆ setOptimizer()

void agents::workflows::EvaluatorWorkflow::setOptimizer ( std::function< String(const String &, const JsonObject &)> optimizer)

Set the optimizer function.

Parameters
optimizerThe optimizer function to set
Examples
evaluator_optimizer_example.cpp.

◆ setOptimizerPrompt()

void agents::workflows::EvaluatorWorkflow::setOptimizerPrompt ( const String & prompt_template)
inline

Set the optimizer prompt.

Parameters
prompt_templateThe optimizer prompt to set
Examples
evaluator_optimizer_example.cpp.

◆ setOptimizerPromptTemplate()

void agents::workflows::EvaluatorWorkflow::setOptimizerPromptTemplate ( const String & prompt_template)

Set the optimizer prompt template.

Parameters
prompt_templateThe optimizer prompt template to set

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