academy.exchange.hybrid¶
HybridAgentRegistration
dataclass
¶
HybridExchangeTransport
¶
HybridExchangeTransport(
mailbox_id: EntityId,
redis_client: Redis,
*,
redis_info: _RedisConnectionInfo,
namespace: str,
host: str,
port: int,
interface: str | None = None
)
Bases: ExchangeTransportMixin, NoPickleMixin
Hybrid exchange transport bound to a specific mailbox.
Source code in academy/exchange/hybrid.py
new
async
classmethod
¶
new(
*,
namespace: str,
redis_info: _RedisConnectionInfo,
interface: str | None = None,
mailbox_id: EntityId | None = None,
name: str | None = None,
port: int | None = None
) -> Self
Instantiate a new transport.
Parameters:
-
namespace(str) –Redis key namespace.
-
redis_info(_RedisConnectionInfo) –Redis connection information.
-
interface(str | None, default:None) –Network interface use for peer-to-peer communication. If
None, the hostname of the local host is used. -
mailbox_id(EntityId | None, default:None) –Bind the transport to the specific mailbox. If
None, a new user entity will be registered and the transport will be bound to that mailbox. -
name(str | None, default:None) –Display name of the registered entity if
mailbox_idisNone. -
port(int | None, default:None) –Port to listen for peer connection on.
Returns:
-
Self–An instantiated transport bound to a specific mailbox.
Raises:
-
ConnectionError–If the Redis server is not reachable.
Source code in academy/exchange/hybrid.py
HybridExchangeFactory
¶
HybridExchangeFactory(
redis_host: str,
redis_port: int,
*,
redis_kwargs: dict[str, Any] | None = None,
interface: str | None = None,
namespace: str | None = "default",
ports: Iterable[int] | None = None
)
Bases: ExchangeFactory[HybridExchangeTransport]
Hybrid exchange client factory.
The hybrid exchange uses peer-to-peer communication via TCP and a central Redis server for mailbox state and queueing messages for offline entities.
Parameters:
-
redis_host(str) –Redis server hostname.
-
redis_port(int) –Redis server port.
-
redis_kwargs(dict[str, Any] | None, default:None) –Extra keyword arguments to pass to
redis.Redis(). -
interface(str | None, default:None) –Network interface use for peer-to-peer communication. If
None, the hostname of the local host is used. -
namespace(str | None, default:'default') –Redis key namespace. If
Nonea random key prefix is generated. -
ports(Iterable[int] | None, default:None) –An iterable of ports to give each client a unique port from a user defined set. A StopIteration exception will be raised in
create_*_client()methods if the number of clients in the process is greater than the length of the iterable.
Source code in academy/exchange/hybrid.py
create_agent_client
async
¶
create_agent_client(
registration: AgentRegistration[AgentT],
request_handler: RequestHandler[RequestT_co],
) -> AgentExchangeClient[AgentT, ExchangeTransportT]
Create a new agent exchange client.
An agent must be registered with the exchange before an exchange client can be created. For example:
factory = ExchangeFactory(...)
user_client = factory.create_user_client()
registration = user_client.register_agent(...)
agent_client = factory.create_agent_client(registration, ...)
Parameters:
-
registration(AgentRegistration[AgentT]) –Registration information returned by the exchange.
-
request_handler(RequestHandler[RequestT_co]) –Agent request message handler.
Returns:
-
AgentExchangeClient[AgentT, ExchangeTransportT]–Agent exchange client.
Raises:
-
BadEntityIdError–If an agent with
registration.agent_idis not already registered with the exchange.
Source code in academy/exchange/factory.py
create_user_client
async
¶
create_user_client(
*, name: str | None = None, start_listener: bool = True
) -> UserExchangeClient[ExchangeTransportT]
Create a new user in the exchange and associated client.
Parameters:
-
name(str | None, default:None) –Display name of the client on the exchange.
-
start_listener(bool, default:True) –Start a message listener thread.
Returns:
-
UserExchangeClient[ExchangeTransportT]–User exchange client.
Source code in academy/exchange/factory.py
base32_to_uuid
¶
Parse a base32 string as a UUID.
uuid_to_base32
¶
Encode a UUID as a trimmed base32 string.