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

A workflow that chains multiple prompts together. More...

#include <prompt_chaining_workflow.h>

Inheritance diagram for agents::workflows::PromptChainingWorkflow:
agents::workflows::Workflow

Classes

struct  Step
 Step in the workflow. More...
 

Public Member Functions

 PromptChainingWorkflow (std::shared_ptr< AgentContext > context)
 Constructor with context.
 
void addStep (const Step &step)
 Add a step to the workflow.
 
void addStep (const String &name, const String &prompt_template, std::function< bool(const JsonObject &)> validator=nullptr, std::function< JsonObject(const JsonObject &)> transformer=nullptr)
 Add a step to the workflow with basic params.
 
JsonObject run (const String &input) override
 Execute the workflow with input.
 
JsonObject run ()
 Execute the workflow 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 chains multiple prompts together.

This workflow decomposes a task into a sequence of steps, where each LLM call processes the output of the previous one. It can add programmatic checks between steps to ensure the process is on track.

Examples
actor_agent_example.cpp.

Constructor & Destructor Documentation

◆ PromptChainingWorkflow()

agents::workflows::PromptChainingWorkflow::PromptChainingWorkflow ( std::shared_ptr< AgentContext > context)

Constructor with context.

Parameters
contextThe context to use

Member Function Documentation

◆ addStep() [1/2]

void agents::workflows::PromptChainingWorkflow::addStep ( const Step & step)

Add a step to the workflow.

Parameters
stepThe step to add

◆ addStep() [2/2]

void agents::workflows::PromptChainingWorkflow::addStep ( const String & name,
const String & prompt_template,
std::function< bool(const JsonObject &)> validator = nullptr,
std::function< JsonObject(const JsonObject &)> transformer = nullptr )

Add a step to the workflow with basic params.

Parameters
nameThe name of the step
prompt_templateThe prompt template for the step
validatorThe validator function for the step
transformerThe transformer function for the step

◆ 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::PromptChainingWorkflow::run ( )

Execute the workflow using the latest USER message from context memory.

Returns
The result of the workflow execution

◆ run() [2/2]

JsonObject agents::workflows::PromptChainingWorkflow::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.

◆ 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

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