Agents 0.0.2
Edge AI Agents SDK
Loading...
Searching...
No Matches
orchestrator_workflow.h
1
10#pragma once
11
12#include <agents-cpp/workflow.h>
13#include <functional>
14#include <map>
15#include <utility>
16#include <vector>
17
18namespace agents {
19namespace workflows {
20
29public:
35 struct Worker {
51 std::shared_ptr<LLMInterface> llm;
55 std::function<JsonObject(const String&, const JsonObject&)> handler;
56
66 const String& name,
67 const String& description,
69 std::shared_ptr<LLMInterface> llm = nullptr,
70 std::function<JsonObject(const String&, const JsonObject&)> handler = nullptr
73 };
74
81 std::shared_ptr<AgentContext> context,
82 const String& orchestrator_prompt_template = ""
83 );
84
89 void addWorker(const Worker& worker);
90
99 const String& name,
100 const String& description,
101 const String& prompt_template,
102 std::shared_ptr<LLMInterface> worker_llm = nullptr
103 );
104
108 void init();
109
115 JsonObject run(const String& input) override;
116
121 void setMaxIterations(int max_iterations);
122
127 void setSynthesizer(std::function<JsonObject(const std::vector<JsonObject>&)> synthesizer);
128
133 void setOrchestratorPrompt(const String& orchestrator_prompt_template);
134
140
141private:
145 String orchestrator_prompt_template_;
146
150 std::vector<Worker> workers_;
151
155 std::function<JsonObject(const std::vector<JsonObject>&)> synthesizer_;
156
160 std::map<String, Worker> worker_map_;
161
165 int max_iterations_ = 5;
166
170 JsonObject defaultSynthesizer(const std::vector<JsonObject>& results);
171
176 String createOrchestratorSystemPrompt() const;
177
181 JsonObject executeWorker(
182 const String& worker_name,
183 const String& task,
184 const JsonObject& context_data
185 );
186};
187
188} // namespace workflows
189} // namespace agents
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 getWorkersSchema() const
Get the schema for available workers.
void addWorker(const Worker &worker)
Add a worker to the workflow.
JsonObject run(const String &input) override
Execute the workflow with input.
void setOrchestratorPrompt(const String &orchestrator_prompt_template)
Set the orchestrator prompt template.
void setSynthesizer(std::function< JsonObject(const std::vector< JsonObject > &)> synthesizer)
Set the result synthesizer function.
OrchestratorWorkflow(std::shared_ptr< AgentContext > context, const String &orchestrator_prompt_template="")
Constructor with context and orchestrator prompt.
void setMaxIterations(int max_iterations)
Set the max number of iterations.
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
Worker definition.
Definition orchestrator_workflow.h:35
String description
The description of the worker.
Definition orchestrator_workflow.h:43
String prompt_template
The prompt template of the worker.
Definition orchestrator_workflow.h:47
Worker(const String &name, const String &description, const String &prompt_template, std::shared_ptr< LLMInterface > llm=nullptr, std::function< JsonObject(const String &, const JsonObject &)> handler=nullptr)
Constructor.
Definition orchestrator_workflow.h:65
String name
The name of the worker.
Definition orchestrator_workflow.h:39
std::shared_ptr< LLMInterface > llm
The llm of the worker.
Definition orchestrator_workflow.h:51
std::function< JsonObject(const String &, const JsonObject &)> handler
The handler of the worker.
Definition orchestrator_workflow.h:55