def tor_agent(reactor, socks_endpoint, circuit=None, pool=None):
    """
    This is the low-level method used by
    :meth:`txtorcon.Tor.web_agent` and
    :meth:`txtorcon.Circuit.web_agent` -- probably you should call one
    of those instead.

    :returns: a Deferred that fires with an object that implements
        :class:`twisted.web.iweb.IAgent` and is thus suitable for passing
        to ``treq`` as the ``agent=`` kwarg. Of course can be used
        directly; see `using Twisted web cliet
        <http://twistedmatrix.com/documents/current/web/howto/client.html>`_.

    :param reactor: the reactor to use

    :param circuit: If supplied, a particular circuit to use

    :param socks_endpoint: Deferred that fires w/
        IStreamClientEndpoint (or IStreamClientEndpoint instance)
        which points at a SOCKS5 port of our Tor

    :param pool: passed on to the Agent (as ``pool=``)
    """

    if socks_endpoint is None:
        raise ValueError(
            "Must provide socks_endpoint as Deferred or IStreamClientEndpoint"
        )
    if circuit is not None:
        factory = _AgentEndpointFactoryForCircuit(reactor, socks_endpoint, circuit)
    else:
        factory = _AgentEndpointFactoryUsingTor(reactor, socks_endpoint)
    return Agent.usingEndpointFactory(reactor, factory, pool=pool)
This is the low-level method used by
    :meth:`txtorcon.Tor.web_agent` and
    :meth:`txtorcon.Circuit.web_agent` -- probably you should call one
    of those instead.

    :returns: a Deferred that fires with an object that implements
        :class:`twisted.web.iweb.IAgent` and is thus suitable for passing
        to ``treq`` as the ``agent=`` kwarg. Of course can be used
        directly; see `using Twisted web cliet
        <http://twistedmatrix.com/documents/current/web/howto/client.html>`_.

    :param reactor: the reactor to use

    :param circuit: If supplied, a particular circuit to use

    :param socks_endpoint: Deferred that fires w/
        IStreamClientEndpoint (or IStreamClientEndpoint instance)
        which points at a SOCKS5 port of our Tor

    :param pool: passed on to the Agent (as ``pool=``)