academy.exchange.local¶
LocalAgentRegistration
dataclass
¶
LocalExchangeTransport
¶
LocalExchangeTransport(
mailbox_id: EntityId, state: _LocalExchangeState
)
Bases: ExchangeTransportMixin, NoPickleMixin
Local exchange client bound to a specific mailbox.
Source code in academy/exchange/local.py
new
classmethod
¶
new(
mailbox_id: EntityId | None = None,
*,
name: str | None = None,
state: _LocalExchangeState
) -> Self
Instantiate a new transport.
Parameters:
-
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 redistered entity if
mailbox_idisNone. -
state(_LocalExchangeState) –Shared state among exchange clients.
Returns:
-
Self–An instantiated transport bound to a specific mailbox.
Source code in academy/exchange/local.py
LocalExchangeFactory
¶
Bases: ExchangeFactory[LocalExchangeTransport], NoPickleMixin
Local exchange client factory.
A thread exchange can be used to pass messages between agents running in separate threads of a single process.
Source code in academy/exchange/local.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.