Agents 0.0.2
Edge AI Agents SDK
Loading...
Searching...
No Matches
actor_agent.h
1
10#pragma once
11
12#include <agents-cpp/agent.h>
13#include <agents-cpp/agent_context.h>
14#include <agents-cpp/coroutine_utils.h>
15#include <map>
16#include <memory>
17#include <mutex>
18#include <optional>
19#include <queue>
20#include <thread>
21#include <vector>
22
23namespace agents {
24
31class ActorAgent : public Agent {
32public:
37 ActorAgent(std::shared_ptr<AgentContext> context);
38
42 virtual ~ActorAgent();
43
47 void init() override;
48
54 Task<JsonObject> run(const String& task) override;
55
59 void stop() override;
60
65 void provideFeedback(const String& feedback) override;
66
71 void setSystemPrompt(const String& system_prompt);
72
78
85 Task<String> waitForFeedback(const String& message, const JsonObject& context) override;
86
88protected:
92 String system_prompt_;
93
97 std::vector<Message> conversation_;
98
102 int run_interval_ms_ = 100;
103
107 std::promise<String> feedback_promise_;
108
112 std::mutex queue_mutex_;
113
117 std::condition_variable queue_cv_;
118
122 std::queue<String> inbound_tasks_;
123
127 std::atomic<bool> stop_flag_{false};
128
132 std::thread worker_thread_;
133
140 virtual void onToolUsed(const String& tool_name, const JsonObject& params, const ToolResult& result);
141
146 virtual void onResponse(const String& response);
147
152 virtual void onError(const String& error);
153
157 void startWorker();
158
162 void stopWorker();
163
168 virtual String createAgentPrompt() const;
169
176 Task<ToolResult> executeTool(const String& tool_name, const JsonObject& params);
177
183 Task<String> processMessage(const String& message);
185};
186
187} // namespace agents
ActorAgent(std::shared_ptr< AgentContext > context)
Constructor with agent context.
ActorAgent(std::shared_ptr< AgentContext > context)
Constructor with agent context.
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.
Task< String > waitForFeedback(const String &message, const JsonObject &context) override
Wait for feedback using coroutines.
void setSystemPrompt(const String &system_prompt)
Set the system prompt for the agent.
virtual ~ActorAgent()
Destructor.
void init() override
Initialize the agent.
String getSystemPrompt() const
Get the current system prompt.
Agent(std::shared_ptr< AgentContext > context)
Constructor.
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
Result of a tool execution.
Definition tool.h:22