Agents 0.0.2
Edge AI Agents SDK
Loading...
Searching...
No Matches
autonomous_agent.h
1
10#pragma once
11
12#include <agents-cpp/agent.h>
13#include <agents-cpp/coroutine_utils.h>
14#include <atomic>
15#include <condition_variable>
16#include <mutex>
17#include <thread>
18
19namespace agents {
20
28class AutonomousAgent : public Agent {
29public:
51
77
82 AutonomousAgent(std::shared_ptr<AgentContext> context);
83
87 ~AutonomousAgent() override = default;
88
92 void init() override;
93
99 Task<JsonObject> run(const String& task) override;
100
104 void stop() override;
105
110 void provideFeedback(const String& feedback) override;
111
116 void setSystemPrompt(const String& system_prompt);
117
123
128 std::vector<Step> getSteps() const;
129
134 void setStepCallback(std::function<void(const Step&)> callback);
135
142 Task<String> waitForFeedback(const String& message, const JsonObject& context) override;
143
144private:
145 String system_prompt_;
146 PlanningStrategy planning_strategy_ = PlanningStrategy::REACT;
147 std::vector<Step> steps_;
148 std::function<void(const Step&)> step_callback_;
149
150 // Execution state
151 std::atomic<bool> should_stop_{false};
152
156 std::promise<String> feedback_promise_;
157
163 Task<JsonObject> executeTask(const String& task);
164
171 Task<Step> executeStep(const String& step_description, const JsonObject& context);
172
177 void recordStep(const Step& step);
178
183 String getToolDescriptions() const;
184
190 Task<JsonObject> planZeroShot(const String& task);
191
197 Task<JsonObject> planTreeOfThought(const String& task);
198
204 Task<JsonObject> planAndExecute(const String& task);
205
211 Task<JsonObject> planReflexion(const String& task);
212
218 Task<JsonObject> planReact(const String& task);
219
225 std::vector<std::string> split_by_newline(const std::string& text) {
226 std::vector<std::string> lines;
227 std::istringstream iss(text);
228 std::string line;
229
230 // Read lines from the stringstream until the end, delimited by '\n'
231 while (std::getline(iss, line, '\n')) {
232 lines.push_back(line);
233 }
234 return lines;
235 }
236};
237
238} // namespace agents
Agent(std::shared_ptr< AgentContext > context)
Constructor.
void setPlanningStrategy(PlanningStrategy strategy)
Set the planning strategy.
void setStepCallback(std::function< void(const Step &)> callback)
Set a callback for when a step is completed.
std::vector< Step > getSteps() const
Get the steps executed so far.
void stop() override
Stop the agent.
Task< JsonObject > run(const String &task) override
Run the agent with a task using coroutines.
void provideFeedback(const String &feedback) override
Provide human feedback.
PlanningStrategy
Planning strategy for the agent.
Definition autonomous_agent.h:55
@ PLAN_AND_EXECUTE
Generate a plan then execute it.
Definition autonomous_agent.h:67
@ ZERO_SHOT
Generate actions without explicit planning.
Definition autonomous_agent.h:59
@ REACT
Reasoning and acting.
Definition autonomous_agent.h:75
@ TREE_OF_THOUGHT
Generate multiple reasoning paths.
Definition autonomous_agent.h:63
@ REFLEXION
Reflect on past steps for improvement.
Definition autonomous_agent.h:71
AutonomousAgent(std::shared_ptr< AgentContext > context)
Constructor.
~AutonomousAgent() override=default
Destructor.
void init() override
Initialize the agent.
void setSystemPrompt(const String &system_prompt)
Set the system prompt.
Task< String > waitForFeedback(const String &message, const JsonObject &context) override
Wait for feedback using coroutines.
Provide a future-based fallback for Task.
Definition coroutine_utils.h:115
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
Step in the agent's execution.
Definition autonomous_agent.h:33
JsonObject result
The result of the step.
Definition autonomous_agent.h:45
bool success
Whether the step was successful.
Definition autonomous_agent.h:49
String description
The description of the step.
Definition autonomous_agent.h:37
String status
The status of the step.
Definition autonomous_agent.h:41