70 lines
2.2 KiB
C++
70 lines
2.2 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 "tool/shell.h"
|
|
#include "tool/filesystem.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;
|
|
|
|
SweAgent(
|
|
const std::string& working_dir = ".",
|
|
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,
|
|
const std::shared_ptr<LLM>& llm = nullptr,
|
|
const std::shared_ptr<BaseMemory>& memory = nullptr,
|
|
AgentState state = AgentState::IDLE,
|
|
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,
|
|
llm,
|
|
memory,
|
|
state,
|
|
max_steps,
|
|
current_step,
|
|
duplicate_threshold
|
|
),
|
|
working_dir(working_dir) {}
|
|
|
|
bool think() override {
|
|
// Update working directory
|
|
working_dir = std::filesystem::current_path().string(); // TODO: Maybe use predefined working directory?
|
|
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
|