#ifndef HUMANUS_AGENT_TOOLCALL_H #define HUMANUS_AGENT_TOOLCALL_H #include "react.h" #include "prompt.h" #include "tool/tool_collection.h" #include "tool/terminate.h" namespace humanus { // Base agent class for handling tool/function calls with enhanced abstraction struct ToolCallAgent : ReActAgent { std::vector tool_calls; ToolCollection available_tools; std::string tool_choice; std::set special_tool_names; ToolCallAgent( const ToolCollection& available_tools = ToolCollection( { std::make_shared() } ), const std::string& tool_choice = "auto", const std::set& special_tool_names = {"terminate"}, const std::string& name = "toolcall", const std::string& description = "an agent that can execute tool calls.", const std::string& system_prompt = prompt::toolcall::SYSTEM_PROMPT, const std::string& next_step_prompt = prompt::toolcall::NEXT_STEP_PROMPT, const std::shared_ptr& llm = nullptr, const std::shared_ptr& memory = nullptr, AgentState state = AgentState::IDLE, int max_steps = 30, int current_step = 0, int duplicate_threshold = 2 ) : ReActAgent( name, description, system_prompt, next_step_prompt, llm, memory, state, max_steps, current_step, duplicate_threshold ), available_tools(available_tools), tool_choice(tool_choice), special_tool_names(special_tool_names) {} // Process current state and decide next actions using tools bool think() override; // Execute tool calls and handle their results std::string act() override; // Execute a single tool call with robust error handling std::string execute_tool(ToolCall tool_call); // Handle special tool execution and state changes void _handle_special_tool(const std::string& name, const ToolResult& result, const json& kwargs = {}); // Determine if tool execution should finish the agent static bool _should_finish_execution(const std::string& name, const ToolResult& result, const json& kwargs = {}); bool _is_special_tool(const std::string& name); }; } #endif // HUMANUS_AGENT_TOOLCALL_H