| 152 | } |
| 153 | |
| 154 | ToolResult ToolExecutor::execute_async_tool( |
| 155 | const ToolCall& tool_call, |
| 156 | const Tool& tool, |
| 157 | const ToolExecutionContext& context) { |
| 158 | if (!tool.execute_async) { |
| 159 | return ToolResult(tool_call.id, tool_call.tool_name, tool_call.arguments, |
| 160 | std::string("Tool has no asynchronous execute function")); |
| 161 | } |
| 162 | |
| 163 | try { |
| 164 | auto future = tool.execute_async.value()(tool_call.arguments, context); |
| 165 | JsonValue result = future.get(); // Wait for completion |
| 166 | return ToolResult(tool_call.id, tool_call.tool_name, tool_call.arguments, |
| 167 | result); |
| 168 | } catch (const std::exception& e) { |
| 169 | return ToolResult( |
| 170 | tool_call.id, tool_call.tool_name, tool_call.arguments, |
| 171 | std::string("Async tool execution failed: " + std::string(e.what()))); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | bool ToolExecutor::validate_json_schema(const JsonValue& data, |
| 176 | const JsonValue& schema) { |