academy.exchange¶
AgentExchangeClient
¶
AgentExchangeClient(
agent_id: AgentId[AgentT],
transport: ExchangeTransportT,
request_handler: RequestHandler[RequestT_co],
)
Bases: ExchangeClient[ExchangeTransportT]
, Generic[AgentT, ExchangeTransportT]
Agent exchange client.
Warning
Agent exchange clients should only be created via
ExchangeFactory.create_agent_client()
!
Parameters:
-
agent_id
(AgentId[AgentT]
) –Agent ID.
-
transport
(ExchangeTransportT
) –Exchange transport bound to
agent_id
. -
request_handler
(RequestHandler[RequestT_co]
) –Request handler of the agent that will be called for each message received to this agent's mailbox. start_listener: Start a message listener thread.
Source code in academy/exchange/client.py
discover
async
¶
Discover peer agents with a given agent.
Parameters:
-
agent
(type[Agent]
) –Agent type of interest.
-
allow_subclasses
(bool
, default:True
) –Return agents implementing subclasses of the agent.
Returns:
Source code in academy/exchange/client.py
factory
¶
factory() -> ExchangeFactory[ExchangeTransportT]
register_handle
¶
Register an existing handle to receive messages.
Parameters:
register_agent
async
¶
register_agent(
agent: type[AgentT], *, name: str | None = None
) -> AgentRegistration[AgentT]
Register a new agent and associated mailbox with the exchange.
Parameters:
-
agent
(type[AgentT]
) –Agent type of the agent.
-
name
(str | None
, default:None
) –Optional display name for the agent.
Returns:
-
AgentRegistration[AgentT]
–Agent registration info.
Source code in academy/exchange/client.py
send
async
¶
Send a message to a mailbox.
Parameters:
Raises:
-
BadEntityIdError
–If a mailbox for
message.dest
does not exist. -
MailboxTerminatedError
–If the mailbox was closed.
Source code in academy/exchange/client.py
status
async
¶
status(uid: EntityId) -> MailboxStatus
Check the status of a mailbox in the exchange.
Parameters:
-
uid
(EntityId
) –Entity identifier of the mailbox to check.
terminate
async
¶
terminate(uid: EntityId) -> None
Terminate a mailbox in the exchange.
Terminating a mailbox means that the corresponding entity will no longer be able to receive messages.
Note
This method is a no-op if the mailbox does not exist.
Parameters:
-
uid
(EntityId
) –Entity identifier of the mailbox to close.
Source code in academy/exchange/client.py
close
async
¶
Close the user client.
This closes the underlying exchange transport and all handles created by this client. The agent's mailbox will not be terminated so the agent can be started again later.
Source code in academy/exchange/client.py
ExchangeClient
¶
ExchangeClient(transport: ExchangeTransportT)
Bases: ABC
, Generic[ExchangeTransportT]
Base exchange client.
Warning
Exchange clients should only be created via
ExchangeFactory.create_agent_client()
or
ExchangeFactory.create_user_client()
!
Parameters:
-
transport
(ExchangeTransportT
) –Exchange transport bound to a mailbox.
Source code in academy/exchange/client.py
close
abstractmethod
async
¶
discover
async
¶
Discover peer agents with a given agent.
Parameters:
-
agent
(type[Agent]
) –Agent type of interest.
-
allow_subclasses
(bool
, default:True
) –Return agents implementing subclasses of the agent.
Returns:
Source code in academy/exchange/client.py
factory
¶
factory() -> ExchangeFactory[ExchangeTransportT]
register_handle
¶
Register an existing handle to receive messages.
Parameters:
register_agent
async
¶
register_agent(
agent: type[AgentT], *, name: str | None = None
) -> AgentRegistration[AgentT]
Register a new agent and associated mailbox with the exchange.
Parameters:
-
agent
(type[AgentT]
) –Agent type of the agent.
-
name
(str | None
, default:None
) –Optional display name for the agent.
Returns:
-
AgentRegistration[AgentT]
–Agent registration info.
Source code in academy/exchange/client.py
send
async
¶
Send a message to a mailbox.
Parameters:
Raises:
-
BadEntityIdError
–If a mailbox for
message.dest
does not exist. -
MailboxTerminatedError
–If the mailbox was closed.
Source code in academy/exchange/client.py
status
async
¶
status(uid: EntityId) -> MailboxStatus
Check the status of a mailbox in the exchange.
Parameters:
-
uid
(EntityId
) –Entity identifier of the mailbox to check.
terminate
async
¶
terminate(uid: EntityId) -> None
Terminate a mailbox in the exchange.
Terminating a mailbox means that the corresponding entity will no longer be able to receive messages.
Note
This method is a no-op if the mailbox does not exist.
Parameters:
-
uid
(EntityId
) –Entity identifier of the mailbox to close.
Source code in academy/exchange/client.py
UserExchangeClient
¶
UserExchangeClient(
user_id: UserId,
transport: ExchangeTransportT,
*,
start_listener: bool = True
)
Bases: ExchangeClient[ExchangeTransportT]
User exchange client.
Warning
User exchange clients should only be created via
ExchangeFactory.create_user_client()
!
Parameters:
-
user_id
(UserId
) –User ID.
-
transport
(ExchangeTransportT
) –Exchange transport bound to
user_id
. -
start_listener
(bool
, default:True
) –Start a message listener thread.
Source code in academy/exchange/client.py
discover
async
¶
Discover peer agents with a given agent.
Parameters:
-
agent
(type[Agent]
) –Agent type of interest.
-
allow_subclasses
(bool
, default:True
) –Return agents implementing subclasses of the agent.
Returns:
Source code in academy/exchange/client.py
factory
¶
factory() -> ExchangeFactory[ExchangeTransportT]
register_handle
¶
Register an existing handle to receive messages.
Parameters:
register_agent
async
¶
register_agent(
agent: type[AgentT], *, name: str | None = None
) -> AgentRegistration[AgentT]
Register a new agent and associated mailbox with the exchange.
Parameters:
-
agent
(type[AgentT]
) –Agent type of the agent.
-
name
(str | None
, default:None
) –Optional display name for the agent.
Returns:
-
AgentRegistration[AgentT]
–Agent registration info.
Source code in academy/exchange/client.py
send
async
¶
Send a message to a mailbox.
Parameters:
Raises:
-
BadEntityIdError
–If a mailbox for
message.dest
does not exist. -
MailboxTerminatedError
–If the mailbox was closed.
Source code in academy/exchange/client.py
status
async
¶
status(uid: EntityId) -> MailboxStatus
Check the status of a mailbox in the exchange.
Parameters:
-
uid
(EntityId
) –Entity identifier of the mailbox to check.
terminate
async
¶
terminate(uid: EntityId) -> None
Terminate a mailbox in the exchange.
Terminating a mailbox means that the corresponding entity will no longer be able to receive messages.
Note
This method is a no-op if the mailbox does not exist.
Parameters:
-
uid
(EntityId
) –Entity identifier of the mailbox to close.
Source code in academy/exchange/client.py
close
async
¶
Close the user client.
This terminates the user's mailbox, closes the underlying exchange transport.
Source code in academy/exchange/client.py
HttpExchangeFactory
¶
HttpExchangeFactory(
url: str,
auth_method: Literal["globus"] | None = None,
additional_headers: dict[str, str] | None = None,
ssl_verify: bool | None = None,
)
Bases: ExchangeFactory[HttpExchangeTransport]
Http exchange client factory.
Parameters:
-
url
(str
) –Address of HTTP exchange
-
auth_method
(Literal['globus'] | None
, default:None
) –Method to get authorization headers
-
additional_headers
(dict[str, str] | None
, default:None
) –Any other information necessary to communicate with the exchange. Used for passing the Globus bearer token
-
ssl_verify
(bool | None
, default:None
) –Same as requests.Session.verify. If the server's TLS certificate should be validated. Should be true if using HTTPS Only set to false for testing or local development.
Source code in academy/exchange/cloud/client.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_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.
Source code in academy/exchange/factory.py
HttpExchangeTransport
¶
HttpExchangeTransport(
mailbox_id: EntityId,
session: ClientSession,
connection_info: _HttpConnectionInfo,
)
Bases: ExchangeTransportMixin
, NoPickleMixin
Http exchange client.
Parameters:
-
mailbox_id
(EntityId
) –Identifier of the mailbox on the exchange. If there is not an id provided, the exchange will create a new client mailbox.
-
session
(ClientSession
) –Http session.
-
connection_info
(_HttpConnectionInfo
) –Exchange connection info.
Source code in academy/exchange/cloud/client.py
new
async
classmethod
¶
new(
*,
connection_info: _HttpConnectionInfo,
mailbox_id: EntityId | None = None,
name: str | None = None
) -> Self
Instantiate a new transport.
Parameters:
-
connection_info
(_HttpConnectionInfo
) –Exchange connection information.
-
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_id
isNone
.
Returns:
-
Self
–An instantiated transport bound to a specific mailbox.
Source code in academy/exchange/cloud/client.py
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.
Source code in academy/exchange/factory.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
None
a 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_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.
Source code in academy/exchange/factory.py
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_id
isNone
. -
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
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_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.
Source code in academy/exchange/factory.py
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_id
isNone
. -
state
(_LocalExchangeState
) –Shared state among exchange clients.
Returns:
-
Self
–An instantiated transport bound to a specific mailbox.
Source code in academy/exchange/local.py
ProxyStoreExchangeFactory
¶
ProxyStoreExchangeFactory(
base: ExchangeFactory[ExchangeTransportT],
store: Store[Any] | None,
should_proxy: Callable[[Any], bool],
*,
resolve_async: bool = False
)
Bases: ExchangeFactory[ProxyStoreExchangeTransport[ExchangeTransportT]]
ProxStore exchange client factory.
A ProxyStore exchange is used to wrap an underlying exchange so large objects may be passed by reference.
Parameters:
-
base
(ExchangeFactory[ExchangeTransportT]
) –Base exchange factory.
-
store
(Store[Any] | None
) –Store to use for proxying data.
-
should_proxy
(Callable[[Any], bool]
) –A callable that returns
True
if an object should be proxied. This is applied to every positional and keyword argument and result value. -
resolve_async
(bool
, default:False
) –Resolve proxies asynchronously when received.
Source code in academy/exchange/proxystore.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_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.
Source code in academy/exchange/factory.py
ProxyStoreExchangeTransport
¶
ProxyStoreExchangeTransport(
transport: ExchangeTransportT,
store: Store[Any],
should_proxy: Callable[[Any], bool],
*,
resolve_async: bool = False
)
Bases: ExchangeTransportMixin
, NoPickleMixin
, Generic[ExchangeTransportT]
ProxyStore exchange client bound to a specific mailbox.
Source code in academy/exchange/proxystore.py
RedisExchangeFactory
¶
Bases: ExchangeFactory[RedisExchangeTransport]
Redis exchange client factory.
Parameters:
-
hostname
(str
) –Redis server hostname.
-
port
(int
) –Redis server port.
-
redis_kwargs
(Any
, default:{}
) –Extra keyword arguments to pass to
redis.Redis()
.
Source code in academy/exchange/redis.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_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.
Source code in academy/exchange/factory.py
RedisExchangeTransport
¶
RedisExchangeTransport(
mailbox_id: EntityId,
redis_client: Redis,
*,
redis_info: _RedisConnectionInfo
)
Bases: ExchangeTransportMixin
, NoPickleMixin
Redis exchange transport bound to a specific mailbox.
Source code in academy/exchange/redis.py
new
async
classmethod
¶
new(
*,
mailbox_id: EntityId | None = None,
name: str | None = None,
redis_info: _RedisConnectionInfo
) -> 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_id
isNone
. -
redis_info
(_RedisConnectionInfo
) –Redis connection information.
Returns:
-
Self
–An instantiated transport bound to a specific mailbox.
Raises:
-
ConnectionError
–If the Redis server is not reachable.
Source code in academy/exchange/redis.py
ExchangeTransport
¶
Bases: Protocol[AgentRegistrationT_co]
Low-level exchange communicator.
A message exchange hosts mailboxes for each entity (i.e., agent or user) in a multi-agent system. This transport protocol defines mechanisms for entity management (e.g., registration, discovery, status, termination) and for sending/receiving messages from a mailbox. As such, each transport instance is "bound" to a specific mailbox in the exchange.
Warning
A specific exchange transport should not be replicated because multiple client instances receiving from the same mailbox produces undefined agent.
close
async
¶
Close the exchange client.
Note
This does not alter the state of the mailbox this client is bound to. I.e., the mailbox will not be terminated.
discover
async
¶
Discover peer agents with a given agent.
Warning
Implementations of this method are often O(n) and scan the types of all agents registered to the exchange.
Parameters:
-
agent
(type[Agent]
) –Agent type of interest.
-
allow_subclasses
(bool
, default:True
) –Return agents implementing subclasses of the agent.
Returns:
Raises:
-
ExchangeError
–Error returned by the exchange.
Source code in academy/exchange/transport.py
factory
¶
factory() -> ExchangeFactory[Self]
recv
async
¶
Receive the next message sent to the mailbox.
This blocks until the next message is received, there is a timeout, or the mailbox is terminated.
Parameters:
-
timeout
(float | None
, default:None
) –Optional timeout in seconds to wait for the next message. If
None
, the default, block forever until the next message or the mailbox is closed.
Raises:
-
MailboxTerminatedError
–If the mailbox was closed.
-
ExchangeError
–Error returned by the exchange.
-
TimeoutError
–If a
timeout
was specified and exceeded.
Source code in academy/exchange/transport.py
register_agent
async
¶
Register a new agent and associated mailbox with the exchange.
Parameters:
-
agent
(type[AgentT]
) –Agent type of the agent.
-
name
(str | None
, default:None
) –Optional display name for the agent.
Returns:
-
AgentRegistrationT_co
–Agent registration info.
Raises:
-
ExchangeError
–Error returned by the exchange.
Source code in academy/exchange/transport.py
send
async
¶
Send a message to a mailbox.
Parameters:
Raises:
-
BadEntityIdError
–If a mailbox for
message.dest
does not exist. -
MailboxTerminatedError
–If the mailbox was closed.
-
ExchangeError
–Error returned by the exchange.
Source code in academy/exchange/transport.py
status
async
¶
status(uid: EntityId) -> MailboxStatus
Check the status of a mailbox in the exchange.
Parameters:
-
uid
(EntityId
) –Entity identifier of the mailbox to check.
Raises:
-
ExchangeError
–Error returned by the exchange.
Source code in academy/exchange/transport.py
terminate
async
¶
terminate(uid: EntityId) -> None
Terminate a mailbox in the exchange.
Once an entity's mailbox is terminated:
- All request messages in the mailbox will be replied to with a
MailboxTerminatedError
. - All calls to
recv()
will raise aMailboxTerminatedError
. - All attempts to
send()
to this mailbox by other entities will raise aMailboxTerminatedError
.
Note
This method is a no-op if the mailbox does not exist.
Parameters:
-
uid
(EntityId
) –Entity identifier of the mailbox to close.
Raises:
-
ExchangeError
–Error returned by the exchange.