academy.exchange.factory¶
ExchangeFactory
¶
Bases: ABC
, Generic[ExchangeTransportT]
Exchange client factory.
An exchange factory is used to mint new exchange clients for users and
agents, encapsulating the complexities of instantiating the underlying
communication classes (the
ExchangeTransport
).
Warning
Factory implementations must be efficiently pickleable because factory instances are shared between user and agent processes so that all entities can create clients to the same exchange.
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_id
is 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.