academy.exchange.client¶
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
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
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
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
close
async
¶
Close the user client.
This terminates the user's mailbox, closes the underlying exchange transport.
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.