2025-03-16 17:17:01 +08:00
|
|
|
#ifndef HUMANUS_FLOW_BASE_H
|
|
|
|
#define HUMANUS_FLOW_BASE_H
|
|
|
|
|
2025-03-19 18:44:54 +08:00
|
|
|
#include "tool/base.h"
|
|
|
|
#include "agent/base.h"
|
2025-03-16 17:17:01 +08:00
|
|
|
|
|
|
|
namespace humanus {
|
|
|
|
|
|
|
|
enum FlowType {
|
2025-03-16 22:56:03 +08:00
|
|
|
PLANNING = 0
|
2025-03-16 17:17:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const std::map<FlowType, std::string> FLOW_TYPE_MAP = {
|
2025-03-16 22:56:03 +08:00
|
|
|
{PLANNING, "planning"}
|
2025-03-16 17:17:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Base class for execution flows supporting multiple agents
|
|
|
|
struct BaseFlow {
|
|
|
|
std::map<std::string, std::shared_ptr<BaseAgent>> agents;
|
|
|
|
std::string primary_agent_key;
|
|
|
|
|
2025-04-13 00:02:18 +08:00
|
|
|
BaseFlow(const std::map<std::string, std::shared_ptr<BaseAgent>>& agents = {}, const std::string& primary_agent_key = "")
|
|
|
|
: agents(agents), primary_agent_key(primary_agent_key) {
|
2025-03-16 17:17:01 +08:00
|
|
|
// If primary agent not specified, use first agent
|
|
|
|
if (primary_agent_key.empty() && !agents.empty()) {
|
2025-03-16 22:56:03 +08:00
|
|
|
this->primary_agent_key = agents.begin()->first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-13 00:02:18 +08:00
|
|
|
BaseFlow(const std::shared_ptr<BaseAgent>& agent, const std::string& primary_agent_key = "")
|
|
|
|
: primary_agent_key(primary_agent_key) {
|
2025-03-16 22:56:03 +08:00
|
|
|
agents["default"] = agent;
|
|
|
|
// If primary agent not specified, use first agent
|
|
|
|
if (primary_agent_key.empty()) {
|
|
|
|
this->primary_agent_key = "default";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-13 00:02:18 +08:00
|
|
|
BaseFlow(const std::vector<std::shared_ptr<BaseAgent>>& agents_list, const std::string& primary_agent_key = "")
|
|
|
|
: primary_agent_key(primary_agent_key) {
|
2025-03-16 22:56:03 +08:00
|
|
|
for (size_t i = 0; i < agents_list.size(); i++) {
|
|
|
|
agents["agent_" + std::to_string(i)] = agents_list[i];
|
|
|
|
}
|
|
|
|
// If primary agent not specified, use first agent
|
|
|
|
if (primary_agent_key.empty() && !agents.empty()) {
|
|
|
|
this->primary_agent_key = agents.begin()->first;
|
2025-03-16 17:17:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-03-17 14:07:41 +08:00
|
|
|
virtual ~BaseFlow() = default;
|
|
|
|
|
2025-03-16 17:17:01 +08:00
|
|
|
// Get the primary agent for the flow
|
|
|
|
std::shared_ptr<BaseAgent> primary_agent() const {
|
|
|
|
return agents.at(primary_agent_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get a specific agent by key
|
|
|
|
std::shared_ptr<BaseAgent> get_agent(const std::string& key) const {
|
|
|
|
return agents.at(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a new agent to the flow
|
|
|
|
void add_agent(const std::string& key, const std::shared_ptr<BaseAgent>& agent) {
|
|
|
|
agents[key] = agent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Execute the flow with the given input
|
2025-03-16 22:56:03 +08:00
|
|
|
virtual std::string execute(const std::string& input_text) = 0;
|
2025-03-16 17:17:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HUMANUS_FLOW_BASE_H
|