Agents 0.0.2
Edge AI Agents SDK
Loading...
Searching...
No Matches
agent.h
1
10#pragma once
11
12#include <agents-cpp/agent_context.h>
13#include <agents-cpp/coroutine_utils.h>
14#include <agents-cpp/types.h>
15#include <functional>
16#include <memory>
17
18namespace agents {
19
26class Agent {
27public:
57
61 struct Options {
66
71
76
80 std::function<bool(const String&, const JsonObject&)> human_in_the_loop;
81 };
82
87 Agent(std::shared_ptr<AgentContext> context);
88
92 virtual ~Agent() = default;
93
97 virtual void init() = 0;
98
104 virtual Task<JsonObject> run(const String& task) = 0;
105
111 void runAsync(const String& task, std::function<void(const JsonObject&)> callback);
112
116 virtual void stop();
117
122 std::shared_ptr<AgentContext> getContext() const;
123
129
134 void setOptions(const Options& options);
135
140 const Options& getOptions() const;
141
146 void setStatusCallback(std::function<void(const String&)> callback);
147
152 virtual void provideFeedback(const String& feedback);
153
161 const String& message,
162 const JsonObject& context
163 ) {
164 // Placeholder implementation, to be overridden
165 co_return "";
166 }
167
169protected:
173 std::shared_ptr<AgentContext> context_;
174
178 State state_ = State::READY;
179
183 Options options_;
184
189 std::function<void(const String&)> status_callback_;
190
195 void setState(State state);
196
201 void logStatus(const String& status);
203};
204
205} // namespace agents
Agent(std::shared_ptr< AgentContext > context)
Constructor.
void runAsync(const String &task, std::function< void(const JsonObject &)> callback)
Run the agent with a callback.
virtual Task< String > waitForFeedback(const String &message, const JsonObject &context)
Wait for feedback using coroutines.
Definition agent.h:160
void setStatusCallback(std::function< void(const String &)> callback)
Set a callback for status updates.
const Options & getOptions() const
Get execution options.
virtual void init()=0
Initialize the agent.
virtual void provideFeedback(const String &feedback)
Provide human feedback.
virtual Task< JsonObject > run(const String &task)=0
Run the agent with a task using coroutines.
State getState() const
Get the agent's current state.
std::shared_ptr< AgentContext > getContext() const
Get the agent's context.
virtual void stop()
Stop the agent.
Agent(std::shared_ptr< AgentContext > context)
Constructor.
State
Agent execution state.
Definition agent.h:31
@ STOPPED
Execution stopped by user.
Definition agent.h:55
@ WAITING
Waiting for human input.
Definition agent.h:43
@ READY
Ready to start execution.
Definition agent.h:35
@ RUNNING
Currently executing.
Definition agent.h:39
@ COMPLETED
Execution completed successfully.
Definition agent.h:47
@ FAILED
Execution failed.
Definition agent.h:51
virtual ~Agent()=default
Destructor.
void setOptions(const Options &options)
Set execution options.
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
Agent execution options.
Definition agent.h:61
Agent execution options.
Definition agent.h:61
int max_consecutive_errors
The maximum number of consecutive errors.
Definition agent.h:70
bool human_feedback_enabled
Whether human feedback is enabled.
Definition agent.h:75
int max_iterations
The maximum number of iterations.
Definition agent.h:65
std::function< bool(const String &, const JsonObject &)> human_in_the_loop
The human in the loop function.
Definition agent.h:80