def avg_agree(ps, gar, aggr_grad, num_iter, num_wait_ps, f):
    """Execute the average agreement protocol as in the paper
    Basically, exchange and aggregate gradients for log2(t) time
    Args
       ps              the local server object
       gar             GAR used for aggregation
       aggr_grad       the initial aggregated gradient
       num_iter        the number of iterations to be done; should be log2(t)
       num_wait_ps     the number of servers that should be waited for
       f               the number of byzantine servers
    """
    for _ in range(num_iter):
        ps.latest_aggr_grad = aggr_grad
        aggr_grads = ps.get_aggr_grads(num_wait_ps)
        aggr_grad = gar(gradients=aggr_grads, f=f)
    return aggr_grad