50 lines
1.2 KiB
C++
50 lines
1.2 KiB
C++
#include "include/flow/base_flow.h"
|
|
#include <stdexcept>
|
|
|
|
namespace openmanus {
|
|
|
|
BaseFlow::BaseFlow(std::shared_ptr<AgentBase> agent) {
|
|
if (agent) {
|
|
primary_agent_key_ = "default";
|
|
agents_[primary_agent_key_] = agent;
|
|
}
|
|
}
|
|
|
|
BaseFlow::BaseFlow(const std::vector<std::shared_ptr<AgentBase>>& agents) {
|
|
if (!agents.empty()) {
|
|
primary_agent_key_ = "agent0";
|
|
for (size_t i = 0; i < agents.size(); ++i) {
|
|
if (agents[i]) {
|
|
std::string key = "agent" + std::to_string(i);
|
|
agents_[key] = agents[i];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
std::shared_ptr<AgentBase> BaseFlow::getPrimaryAgent() const {
|
|
auto it = agents_.find(primary_agent_key_);
|
|
if (it != agents_.end()) {
|
|
return it->second;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
std::shared_ptr<AgentBase> BaseFlow::getAgent(const std::string& key) const {
|
|
auto it = agents_.find(key);
|
|
if (it != agents_.end()) {
|
|
return it->second;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
void BaseFlow::addAgent(const std::string& key, std::shared_ptr<AgentBase> agent) {
|
|
if (agent) {
|
|
agents_[key] = agent;
|
|
if (agents_.size() == 1) {
|
|
primary_agent_key_ = key;
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace openmanus
|