academy.exchange.cloud.backend¶
MailboxBackend
¶
Bases: Protocol
Backend protocol for storing mailboxes on server.
check_mailbox
async
¶
check_mailbox(client: str, uid: EntityId) -> MailboxStatus
Check if a mailbox exists, or is terminated.
Parameters:
Returns:
-
MailboxStatus
–The mailbox status.
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
Source code in academy/exchange/cloud/backend.py
create_mailbox
async
¶
Create a mailbox is not exists.
This method should be idempotent.
Parameters:
-
client
(str
) –Client making the request.
-
uid
(EntityId
) –Mailbox id to check.
-
agent
(tuple[str, ...] | None
, default:None
) –The agent_mro for behavior discovery.
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
Source code in academy/exchange/cloud/backend.py
terminate
async
¶
Close a mailbox.
For security, the manager should keep a gravestone so the same id cannot be re-registered.
Parameters:
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
Source code in academy/exchange/cloud/backend.py
discover
async
¶
Find mailboxes of matching agent class.
Parameters:
-
client
(str
) –Client making the request.
-
agent
(str
) –Agent class to search for.
-
allow_subclasses
(bool
) –Include agents that inherit from the target.
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
Source code in academy/exchange/cloud/backend.py
get
async
¶
Get messages from a mailbox.
Parameters:
-
client
(str
) –Client making the request.
-
uid
(EntityId
) –Mailbox id to get messages.
-
timeout
(float | None
, default:None
) –Time in seconds to wait for message. If None, wait indefinitely.
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
-
BadEntityIdError
–The mailbox requested does not exist.
-
MailboxTerminatedError
–The mailbox is closed.
-
TimeoutError
–There was not message received during the timeout.
Source code in academy/exchange/cloud/backend.py
put
async
¶
Put a message in a mailbox.
Parameters:
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
-
BadEntityIdError
–The mailbox requested does not exist.
-
MailboxTerminatedError
–The mailbox is closed.
-
MessageTooLargeError
–The message is larger than the message size limit for this exchange.
Source code in academy/exchange/cloud/backend.py
PythonBackend
¶
PythonBackend(message_size_limit_kb: int = 1024)
Mailbox backend using in-memory python data structures.
Parameters:
-
message_size_limit_kb
(int
, default:1024
) –Maximum message size to allow.
Source code in academy/exchange/cloud/backend.py
check_mailbox
async
¶
check_mailbox(client: str, uid: EntityId) -> MailboxStatus
Check if a mailbox exists, or is terminated.
Parameters:
Returns:
-
MailboxStatus
–The mailbox status.
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
Source code in academy/exchange/cloud/backend.py
create_mailbox
async
¶
Create a mailbox is not exists.
This method should be idempotent.
Parameters:
-
client
(str
) –Client making the request.
-
uid
(EntityId
) –Mailbox id to check.
-
agent
(tuple[str, ...] | None
, default:None
) –The agent_mro for behavior discovery.
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
Source code in academy/exchange/cloud/backend.py
terminate
async
¶
Close a mailbox.
For security, the manager should keep a gravestone so the same id cannot be re-registered.
Parameters:
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
Source code in academy/exchange/cloud/backend.py
discover
async
¶
Find mailboxes of matching agent class.
Parameters:
-
client
(str
) –Client making the request.
-
agent
(str
) –Agent class to search for.
-
allow_subclasses
(bool
) –Include agents that inherit from the target.
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
Source code in academy/exchange/cloud/backend.py
get
async
¶
Get messages from a mailbox.
Parameters:
-
client
(str
) –Client making the request.
-
uid
(EntityId
) –Mailbox id to get messages.
-
timeout
(float | None
, default:None
) –Time in seconds to wait for message. If None, wait indefinitely.
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
-
BadEntityIdError
–The mailbox requested does not exist.
-
MailboxTerminatedError
–The mailbox is closed.
-
TimeoutError
–There was not message received during the timeout.
Source code in academy/exchange/cloud/backend.py
put
async
¶
Put a message in a mailbox.
Parameters:
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
-
BadEntityIdError
–The mailbox requested does not exist.
-
MailboxTerminatedError
–The mailbox is closed.
-
MessageTooLargeError
–The message is larger than the message size limit for this exchange.
Source code in academy/exchange/cloud/backend.py
RedisBackend
¶
RedisBackend(
hostname: str = "localhost",
port: int = 6379,
*,
message_size_limit_kb: int = 1024,
kwargs: dict[str, Any] | None = None,
mailbox_expiration_s: int | None = None,
gravestone_expiration_s: int | None = None
)
Redis backend of mailboxes.
Parameters:
-
hostname
(str
, default:'localhost'
) –Host address of redis.
-
port
(int
, default:6379
) –Redis port.
-
message_size_limit_kb
(int
, default:1024
) –Maximum message size to allow.
-
kwargs
(dict[str, Any] | None
, default:None
) –Addition arguments to pass to redis session.
Source code in academy/exchange/cloud/backend.py
check_mailbox
async
¶
check_mailbox(client: str, uid: EntityId) -> MailboxStatus
Check if a mailbox exists, or is terminated.
Parameters:
Returns:
-
MailboxStatus
–The mailbox status.
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
Source code in academy/exchange/cloud/backend.py
create_mailbox
async
¶
Create a mailbox is not exists.
This method should be idempotent.
Parameters:
-
client
(str
) –Client making the request.
-
uid
(EntityId
) –Mailbox id to check.
-
agent
(tuple[str, ...] | None
, default:None
) –The agent_mro for behavior discovery.
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
Source code in academy/exchange/cloud/backend.py
terminate
async
¶
Close a mailbox.
For security, the manager should keep a gravestone so the same id cannot be re-registered.
Parameters:
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
Source code in academy/exchange/cloud/backend.py
discover
async
¶
Find mailboxes of matching agent class.
Parameters:
-
client
(str
) –Client making the request.
-
agent
(str
) –Agent class to search for.
-
allow_subclasses
(bool
) –Include agents that inherit from the target.
Source code in academy/exchange/cloud/backend.py
get
async
¶
Get messages from a mailbox.
Parameters:
-
client
(str
) –Client making the request.
-
uid
(EntityId
) –Mailbox id to get messages.
-
timeout
(float | None
, default:None
) –Time in seconds to wait for message. If None, wait indefinitely.
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
-
BadEntityIdError
–The mailbox requested does not exist.
-
MailboxTerminatedError
–The mailbox is closed.
-
TimeoutError
–There was not message received during the timeout.
Source code in academy/exchange/cloud/backend.py
put
async
¶
Put a message in a mailbox.
Parameters:
Raises:
-
ForbiddenError
–If the client does not have the right permissions.
-
BadEntityIdError
–The mailbox requested does not exist.
-
MailboxTerminatedError
–The mailbox is closed.
-
MessageTooLargeError
–The message is larger than the message size limit for this exchange.