AttributeError: '_RestrictContext' object has no attribute 'object'
Some edits
Give operator a poll method so it requires an active object of type mesh (or a type that can have decimate modifier)
Add the modifier using the api method.
bl_info = {
    &quot;name&quot;: &quot;test&quot;,
    &quot;author&quot;: &quot;Aziz&quot;,
    &quot;version&quot;: (1, 0),
    &quot;blender&quot;: (2, 80, 0),
    &quot;location&quot;: &quot;...&quot;,
    &quot;description&quot;: &quot;...&quot;,
    &quot;warning&quot;: &quot;&quot;,
    &quot;doc_url&quot;: &quot;&quot;,
    &quot;category&quot;: &quot;Mesh&quot;,
}

import bpy

class ReducePolygons(bpy.types.Operator):
    
    bl_idname = &quot;reduce.polygons&quot;
    bl_label = &quot;Reduce Polygons&quot;
     
    @classmethod 
    def poll(cls, context):
        ob = context.active_object
        return ob and ob.type == 'MESH'
    
    def execute(self, context):
        ob = context.active_object
        dm = ob.modifiers.new(name=&quot;Foo&quot;, type='DECIMATE')
        
        dm.decimate_type = 'UNSUBDIV'
        dm.iterations = 1
        bpy.ops.object.modifier_apply(modifier=dm.name)
        return {'FINISHED'}
       

class LayoutDemoPanel(bpy.types.Panel):
    
    bl_label = &quot;test&quot;
    bl_idname = &quot;SCENE_PT_layout&quot;
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = &quot;scene&quot;
     

    
    def draw(self, context):
        layout = self.layout

        layout.label(text=&quot;Mesh Optimizations:&quot;)
        row = layout.row()
        row.scale_y = 2.0
        row.operator(&quot;reduce.polygons&quot;)
        

def register():
    bpy.utils.register_class(LayoutDemoPanel)
    bpy.utils.register_class(ReducePolygons)
    


def unregister():
    bpy.utils.unregister_class(LayoutDemoPanel)
    bpy.utils.unregister_class(ReducePolygons)
    


if __name__ == &quot;__main__&quot;:
    register()