def pick_two_obj_then_place(self, objecttype, receptacletype):
    def pick_two_obj_then_place():
        if hasattr(self, "old_object_name") and self.holding is not None:
            # If the agent is holding something, put it down first
            self.put(self.holding, self.location)
            return

        # Find the object to be placed in the receptacle
        entity = self.find_object(objecttype)
        if entity is None:
            # If the object is not found, explore the environment
            self.explore()
            return

        # Place the first object in the receptacle
        receptacle = self.find_receptacle(receptacletype)
        if receptacle is None:
            # If the receptacle is not found, explore the environment
            self.explore()
            return
        self.take(entity.name, receptacle.name)
        setattr(self, "old_object_name", entity.name)

        # Find another object to be placed in the receptacle
        other_objects = self.find_objects(objecttype)
        for obj in other_objects:
            if obj.name != entity.name:
                # Place the second object in the receptacle
                self.put(obj.name, receptacle.name)
                return

    pick_two_obj_then_place()