54 lines
1.9 KiB
C++
54 lines
1.9 KiB
C++
#ifndef HUMANUS_AGENT_SWE_H
|
|
#define HUMANUS_AGENT_SWE_H
|
|
|
|
#include "toolcall.h"
|
|
#include "../tool/tool_collection.h"
|
|
#include "../tool/terminate.h"
|
|
#include "../prompt.h"
|
|
|
|
namespace humanus {
|
|
|
|
// An agent that implements the SWEAgent paradigm for executing code and natural conversations.
|
|
struct SweAgent : ToolCallAgent {
|
|
std::string working_dir;
|
|
std::shared_ptr<Bash> bash;
|
|
|
|
SweAgent(
|
|
const std::string& working_dir = ".",
|
|
const std::shared_ptr<Bash>& bash = std::make_shared<Bash>(),
|
|
const ToolCollection& available_tools = ToolCollection(
|
|
{
|
|
std::make_shared<Shell>(),
|
|
std::make_shared<FileSystem>(),
|
|
std::make_shared<Terminate>()
|
|
}
|
|
),
|
|
const std::string& tool_choice = "auto",
|
|
const std::set<std::string>& special_tool_names = {"terminate"},
|
|
const std::string& name = "swe",
|
|
const std::string& description = "an autonomous AI programmer that interacts directly with the computer to solve tasks.",
|
|
const std::string& system_prompt = prompt::swe::SYSTEM_PROMPT,
|
|
const std::string& next_step_prompt = prompt::swe::NEXT_STEP_TEMPLATE,
|
|
int max_steps = 100,
|
|
int current_step = 0,
|
|
int duplicate_threshold = 2
|
|
) : ToolCallAgent(available_tools, tool_choice, special_tool_names, name, description, system_prompt, next_step_prompt, max_steps, current_step, duplicate_threshold),
|
|
bash(bash),
|
|
working_dir(working_dir) {}
|
|
|
|
bool think() override {
|
|
// Update working directory
|
|
working_dir = bash->execute("pwd");
|
|
next_step_prompt = prompt::swe::NEXT_STEP_TEMPLATE;
|
|
next_step_prompt = next_step_prompt.replace(
|
|
next_step_prompt.find("{working_dir}"), std::string("{working_dir}").length(), working_dir
|
|
);
|
|
|
|
return ToolCallAgent::think();
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
#endif // HUMANUS_AGENT_SWE_H
|