Agents 0.0.2
Edge AI Agents SDK
Loading...
Searching...
No Matches
routing_workflow.h
1
10#pragma once
11
12#include <agents-cpp/workflow.h>
13#include <functional>
14#include <map>
15
16namespace agents {
17namespace workflows {
18
26class RoutingWorkflow : public Workflow {
27public:
32 struct RouteHandler {
48 std::shared_ptr<LLMInterface> llm; // Optional separate LLM for this route
52 std::shared_ptr<Workflow> workflow; // Optional workflow to delegate to
56 std::function<JsonObject(const String&, const JsonObject&)> handler; // Optional function handler
57
68 const String& name,
69 const String& description,
70 const String& prompt_template = "",
71 std::shared_ptr<LLMInterface> llm = nullptr,
72 std::shared_ptr<Workflow> workflow = nullptr,
73 std::function<JsonObject(const String&, const JsonObject&)> handler = nullptr
76 };
77
84 std::shared_ptr<AgentContext> context,
85 const String& router_prompt_template = ""
86 );
87
92 void addRouteHandler(const RouteHandler& handler);
93
103 const String& name,
104 const String& description,
105 const String& prompt_template = "",
106 std::shared_ptr<LLMInterface> handler_llm = nullptr,
107 std::shared_ptr<Workflow> workflow = nullptr
108 );
109
113 void init();
114
120 JsonObject run(const String& input) override;
121
126 void setRouterPromptTemplate(const String& prompt_template);
127
132 void setRouterPrompt(const String& prompt_template) { setRouterPromptTemplate(prompt_template); }
133
138 void setDefaultHandler(const RouteHandler& handler);
139
144 void setDefaultRoute(std::function<JsonObject(const String&, const JsonObject&)> handler);
145
151
159 const String& name,
160 const String& description,
161 std::function<JsonObject(const String&, const JsonObject&)> handler
162 );
163
164private:
168 String router_prompt_template_;
169
173 std::map<String, RouteHandler> route_handlers_;
174
178 std::optional<RouteHandler> default_handler_;
179
184 String createRouterSystemPrompt() const;
185};
186
187} // namespace workflows
188} // namespace agents
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 addRoute(const String &name, const String &description, std::function< JsonObject(const String &, const JsonObject &)> handler)
Add a route with a direct function handler.
void setDefaultHandler(const RouteHandler &handler)
Set default handler for unknown routes.
JsonObject getRoutesSchema() const
Define available routes as a JSON schema.
RoutingWorkflow(std::shared_ptr< AgentContext > context, const String &router_prompt_template="")
Constructor with context and router prompt template.
void init()
Initialize the workflow.
void setDefaultRoute(std::function< JsonObject(const String &, const JsonObject &)> handler)
Set default route.
void setRouterPrompt(const String &prompt_template)
Set the router prompt.
Definition routing_workflow.h:132
JsonObject run(const String &input) override
Execute the workflow with input.
void addRouteHandler(const RouteHandler &handler)
Add a route handler.
void setRouterPromptTemplate(const String &prompt_template)
Set the router prompt template.
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
Handler definition for a route.
Definition routing_workflow.h:32
std::shared_ptr< Workflow > workflow
The workflow of the route handler.
Definition routing_workflow.h:52
std::function< JsonObject(const String &, const JsonObject &)> handler
The handler of the route handler.
Definition routing_workflow.h:56
RouteHandler(const String &name, const String &description, const String &prompt_template="", std::shared_ptr< LLMInterface > llm=nullptr, std::shared_ptr< Workflow > workflow=nullptr, std::function< JsonObject(const String &, const JsonObject &)> handler=nullptr)
Constructor.
Definition routing_workflow.h:67
String name
The name of the route handler.
Definition routing_workflow.h:36
String prompt_template
The prompt template of the route handler.
Definition routing_workflow.h:44
String description
The description of the route handler.
Definition routing_workflow.h:40
std::shared_ptr< LLMInterface > llm
The LLM of the route handler.
Definition routing_workflow.h:48