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

Routing workflow using the actor model. More...

#include <routing_workflow.h>

Inheritance diagram for agents::workflows::RoutingWorkflow:
agents::workflows::Workflow

Classes

struct  RouteHandler
 Handler definition for a route. More...
 

Public Member Functions

 RoutingWorkflow (std::shared_ptr< AgentContext > context, const String &router_prompt_template="")
 Constructor with context and router prompt template.
 
void addRouteHandler (const RouteHandler &handler)
 Add a route handler.
 
void addRouteHandler (const String &name, const String &description, const String &prompt_template="", std::shared_ptr< LLMInterface > handler_llm=nullptr, std::shared_ptr< Workflow > workflow=nullptr)
 Add a route handler with basic params.
 
void init ()
 Initialize the workflow.
 
JsonObject run (const String &input) override
 Execute the workflow with input.
 
void setRouterPromptTemplate (const String &prompt_template)
 Set the router prompt template.
 
void setRouterPrompt (const String &prompt_template)
 Set the router prompt.
 
void setDefaultHandler (const RouteHandler &handler)
 Set default handler for unknown routes.
 
void setDefaultRoute (std::function< JsonObject(const String &, const JsonObject &)> handler)
 Set default route.
 
JsonObject getRoutesSchema () const
 Define available routes as a JSON schema.
 
void addRoute (const String &name, const String &description, std::function< JsonObject(const String &, const JsonObject &)> handler)
 Add a route with a direct function handler.
 
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

Routing workflow using the actor model.

This workflow classifies an input and directs it to a specialized follow-up task or handler. It allows for separation of concerns and building more specialized prompts for different types of inputs.

Examples
routing_example.cpp.

Constructor & Destructor Documentation

◆ RoutingWorkflow()

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

Constructor with context and router prompt template.

Parameters
contextThe context of the workflow
router_prompt_templateThe router prompt template

Member Function Documentation

◆ addRoute()

void agents::workflows::RoutingWorkflow::addRoute ( const String & name,
const String & description,
std::function< JsonObject(const String &, const JsonObject &)> handler )

Add a route with a direct function handler.

Parameters
nameThe name of the route
descriptionThe description of the route
handlerThe handler of the route
Examples
routing_example.cpp.

◆ addRouteHandler() [1/2]

void agents::workflows::RoutingWorkflow::addRouteHandler ( const RouteHandler & handler)

Add a route handler.

Parameters
handlerThe handler to add

◆ addRouteHandler() [2/2]

void agents::workflows::RoutingWorkflow::addRouteHandler ( const String & name,
const String & description,
const String & prompt_template = "",
std::shared_ptr< LLMInterface > handler_llm = nullptr,
std::shared_ptr< Workflow > workflow = nullptr )

Add a route handler with basic params.

Parameters
nameThe name of the route
descriptionThe description of the route
prompt_templateThe prompt template of the route
handler_llmThe LLM of the route
workflowThe workflow of the route

◆ 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

◆ getRoutesSchema()

JsonObject agents::workflows::RoutingWorkflow::getRoutesSchema ( ) const

Define available routes as a JSON schema.

Returns
The schema of the routes

◆ run()

JsonObject agents::workflows::RoutingWorkflow::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
routing_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

◆ setDefaultHandler()

void agents::workflows::RoutingWorkflow::setDefaultHandler ( const RouteHandler & handler)

Set default handler for unknown routes.

Parameters
handlerThe handler to set

◆ setDefaultRoute()

void agents::workflows::RoutingWorkflow::setDefaultRoute ( std::function< JsonObject(const String &, const JsonObject &)> handler)

Set default route.

Parameters
handlerThe handler to set
Examples
routing_example.cpp.

◆ setMaxSteps()

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

Set maximum number of steps.

Parameters
max_stepsThe maximum number of steps

◆ setRouterPrompt()

void agents::workflows::RoutingWorkflow::setRouterPrompt ( const String & prompt_template)
inline

Set the router prompt.

Parameters
prompt_templateThe prompt template to set
Examples
routing_example.cpp.

◆ setRouterPromptTemplate()

void agents::workflows::RoutingWorkflow::setRouterPromptTemplate ( const String & prompt_template)

Set the router prompt template.

Parameters
prompt_templateThe 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.