#ifndef HUMANUS_TOOL_COLLECTION_H #define HUMANUS_TOOL_COLLECTION_H #include "base.h" namespace humanus { struct ToolCollection { std::vector> tools; std::map> tools_map; ToolCollection(std::vector> tools) : tools(tools) { for (auto tool : tools) { tools_map[tool->name] = tool; } } json to_params() const { json params = json::array(); for (auto tool : tools) { params.push_back(tool->to_param()); } return params; } ToolResult execute(const std::string& name, const json& args) const { auto tool_iter = tools_map.find(name); if (tool_iter == tools_map.end()) { return ToolError("Tool " + name + " is invalid"); } try { return tool_iter->second->execute(args); } catch (const std::exception& e) { return ToolError(e.what()); } } // // Execute all tools in the collection sequentially. // std::vector execute_all(const json& args) const { // No reference now // std::vector results; // for (auto tool : tools) { // try { // auto result = tool->execute(args); // results.push_back(result); // } catch (const std::exception& e) { // results.push_back(ToolError(e.what())); // } // } // return results; // } void add_tool(const std::shared_ptr& tool) { tools.push_back(tool); tools_map[tool->name] = tool; } void add_tools(const std::vector>& tools) { for (auto tool : tools) { add_tool(tool); } } }; } #endif // HUMANUS_TOOL_COLLECTION_H