def average(v, state):
    """
    Parameters
    ----------
    v : number
       The next element of the input stream of the
       agent.
    state: (n, cumulative)
       The state of the agent where
       n : number
           The value of the next element in the agent's
           input stream.
       cumulative : number
           The sum of the values that the agent has
           received on its input stream.

    Returns
    -------
    (mean, state)
    mean : floating point number
       The average of the values received so far by
       the agent
    state : (n, cumulative)
       The new state of the agent.

    """
    n, cumulative = state
    n += 1
    cumulative += v
    mean = cumulative/float(n)
    state = (n, cumulative)
    return (mean, state)