humanus.cpp/agent/react.h

51 lines
1.2 KiB
C
Raw Normal View History

2025-03-16 17:17:01 +08:00
#ifndef HUMANUS_AGENT_REACT_H
#define HUMANUS_AGENT_REACT_H
#include "base.h"
namespace humanus {
struct ReActAgent : BaseAgent {
2025-03-16 22:56:03 +08:00
ReActAgent(
const std::string& name,
const std::string& description,
const std::string& system_prompt,
const std::string& next_step_prompt,
const std::shared_ptr<LLM>& llm = nullptr,
2025-03-23 14:35:54 +08:00
const std::shared_ptr<BaseMemory>& memory = nullptr,
2025-03-16 22:56:03 +08:00
int max_steps = 10,
int duplicate_threshold = 2
) : BaseAgent(
name,
description,
system_prompt,
next_step_prompt,
llm,
memory,
max_steps,
2025-03-16 22:56:03 +08:00
duplicate_threshold
) {}
2025-03-16 17:17:01 +08:00
// Process current state and decide next actions using tools
virtual bool think() = 0;
// Execute decided actions
virtual std::string act() = 0;
// Execute a single step: think and act.
virtual std::string step() {
bool should_act = think();
if (!should_act) {
return "Thinking complete - no action needed";
}
2025-04-08 23:26:53 +08:00
if (state == AgentState::RUNNING) {
return act();
}
return "Agent is not running";
2025-03-16 17:17:01 +08:00
}
};
}
#endif // HUMANUS_AGENT_REACT_H