fix compilation error on Windows

main
hkr04 2025-03-18 16:40:16 +08:00
parent be606c1020
commit c8a9056e4a
9 changed files with 47 additions and 10 deletions

View File

@ -1,6 +1,30 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(humanus.cpp VERSION 0.1.0) project(humanus.cpp VERSION 0.1.0)
set(CMAKE_WARN_UNUSED_CLI YES)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
option(BUILD_SHARED_LIBS "build shared libraries" ${BUILD_SHARED_LIBS_DEFAULT})
if (WIN32)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()
if (MSVC)
add_compile_options("$<$<COMPILE_LANGUAGE:C>:/utf-8>")
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/utf-8>")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:/bigobj>")
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/bigobj>")
add_compile_options(/wd4244 /wd4267)
endif()
# Set C++ standard
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)

View File

@ -4,6 +4,11 @@
#include "../llm.h" #include "../llm.h"
#include "../schema.h" #include "../schema.h"
#include "../logger.h" #include "../logger.h"
#include <memory>
#include <stdexcept>
#include <string>
#include <vector>
#include <utility>
namespace humanus { namespace humanus {
@ -103,7 +108,7 @@ struct BaseAgent : std::enable_shared_from_this<BaseAgent> {
step_result = step(); step_result = step();
} catch (const std::exception& e) { } catch (const std::exception& e) {
logger->error("Error executing step " + std::to_string(current_step) + ": " + std::string(e.what())); logger->error("Error executing step " + std::to_string(current_step) + ": " + std::string(e.what()));
state = AgentState::ERROR; state = AgentState::ERR;
break; break;
} }
@ -116,7 +121,7 @@ struct BaseAgent : std::enable_shared_from_this<BaseAgent> {
if (current_step >= max_steps) { if (current_step >= max_steps) {
results.push_back("Terminated: Reached max steps (" + std::to_string(max_steps) + ")"); results.push_back("Terminated: Reached max steps (" + std::to_string(max_steps) + ")");
} }
if (state == AgentState::ERROR) { if (state == AgentState::ERR) {
results.push_back("Terminated: Agent state is " + agent_state_map[state]); results.push_back("Terminated: Agent state is " + agent_state_map[state]);
} else { } else {
state = AgentState::IDLE; // FINISHED -> IDLE state = AgentState::IDLE; // FINISHED -> IDLE
@ -182,6 +187,6 @@ struct BaseAgent : std::enable_shared_from_this<BaseAgent> {
} }
}; };
} } // namespace humanus
#endif // HUMANUS_AGENT_BASE_H #endif // HUMANUS_AGENT_BASE_H

View File

@ -142,7 +142,7 @@ std::string ToolCallAgent::execute_tool(ToolCall tool_call) {
_handle_special_tool(name, result); _handle_special_tool(name, result);
return observation; return observation;
} catch (const json::exception& e) { } catch (const json::exception& /* e */) {
std::string error_msg = "Error parsing arguments for " + name + ": Invalid JSON format"; std::string error_msg = "Error parsing arguments for " + name + ": Invalid JSON format";
logger->error( logger->error(
"📝 Oops! The arguments for '" + name + "' don't make sense - invalid JSON" "📝 Oops! The arguments for '" + name + "' don't make sense - invalid JSON"

View File

@ -18,8 +18,9 @@ static std::filesystem::path get_project_root() {
return std::filesystem::path(__FILE__).parent_path(); return std::filesystem::path(__FILE__).parent_path();
} }
inline const std::filesystem::path PROJECT_ROOT = get_project_root(); // Windows环境下使用静态变量
inline const std::filesystem::path WORKSPACE_ROOT = PROJECT_ROOT / "workspace"; static const std::filesystem::path PROJECT_ROOT = get_project_root();
static const std::filesystem::path WORKSPACE_ROOT = PROJECT_ROOT / "workspace";
struct LLMSettings { struct LLMSettings {
std::string model; std::string model;

View File

@ -58,7 +58,7 @@ std::string PlanningFlow::execute(const std::string& input) {
result += step_result + "\n"; result += step_result + "\n";
// Check if agent wants to terminate // Check if agent wants to terminate
if (executor->state == AgentState::FINISHED || executor->state == AgentState::ERROR) { if (executor->state == AgentState::FINISHED || executor->state == AgentState::ERR) {
break; break;
} }
} }

View File

@ -1,6 +1,8 @@
#include "logger.h" #include "logger.h"
#include "config.h"
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <filesystem>
namespace humanus { namespace humanus {

2
mcp

@ -1 +1 @@
Subproject commit 7f9862f91ca82118f31834570ee409381574eba0 Subproject commit 5e9ff48b070a11ba20529feb22c68d0e9ef46f3d

View File

@ -6,7 +6,7 @@ std::map<AgentState, std::string> agent_state_map = {
{AgentState::IDLE, "IDLE"}, {AgentState::IDLE, "IDLE"},
{AgentState::RUNNING, "RUNNING"}, {AgentState::RUNNING, "RUNNING"},
{AgentState::FINISHED, "FINISHED"}, {AgentState::FINISHED, "FINISHED"},
{AgentState::ERROR, "ERROR"} {AgentState::ERR, "ERROR"}
}; };
} // namespace humanus } // namespace humanus

View File

@ -2,6 +2,10 @@
#define HUMANUS_SCHEMA_H #define HUMANUS_SCHEMA_H
#include "mcp_message.h" #include "mcp_message.h"
#include <string>
#include <vector>
#include <map>
#include <algorithm>
namespace humanus { namespace humanus {
@ -12,9 +16,10 @@ enum class AgentState {
IDLE = 0, IDLE = 0,
RUNNING = 1, RUNNING = 1,
FINISHED = 2, FINISHED = 2,
ERROR = 3 ERR = 3 // Don't use ERROR
}; };
// 定义全局map
extern std::map<AgentState, std::string> agent_state_map; extern std::map<AgentState, std::string> agent_state_map;
struct Function { struct Function {