#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(), std::make_shared(), std::make_shared() } ), const std::string& tool_choice = "auto", const std::set& 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 = nullptr, const std::shared_ptr& 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