academy.message¶
Message
module-attribute
¶
Message = Union[RequestMessage, ResponseMessage]
Message union type for type annotations.
Tip
This is a parameterized generic type meaning that this type cannot
be used for [isinstance
][builtins.isinstance
] checks:
typing.get_args()
:
BaseMessage
pydantic-model
¶
Bases: BaseModel
Base message type for messages between entities (agents or clients).
Note
The hash()
of this type is a combination of the
message type and message ID.
Config:
arbitrary_types_allowed
:True
extra
:forbid
frozen
:False
use_enum_values
:True
validate_default
:True
Fields:
label
pydantic-field
¶
Optional label used to disambiguate response messages when multiple objects (i.e., handles) share the same mailbox. This is a different usage from the tag
.
model_from_json
classmethod
¶
Reconstruct a specific message from a JSON dump.
Example
Source code in academy/message.py
model_deserialize
classmethod
¶
Deserialize a message.
Warning
This uses pickle and is therefore suceptible to all the typical pickle warnings about code injection.
Source code in academy/message.py
ActionRequest
pydantic-model
¶
Bases: BaseMessage
Agent action request message.
When this message is dumped to a JSON string, the pargs
and kargs
are pickled and then base64 encoded to a string. This can have non-trivial
time and space overheads for large arguments.
Fields:
-
tag
(UUID
) -
src
(EntityId
) -
dest
(EntityId
) -
label
(Optional[UUID]
) -
action
(str
) -
pargs
(tuple[Any, ...]
) -
kargs
(dict[str, Any]
) -
kind
(Literal['action-request']
)
Validators:
label
pydantic-field
¶
Optional label used to disambiguate response messages when multiple objects (i.e., handles) share the same mailbox. This is a different usage from the tag
.
error
¶
error(exception: Exception) -> ActionResponse
Construct an error response to action request.
Parameters:
-
exception
(Exception
) –Error of the action.
Source code in academy/message.py
response
¶
response(result: Any) -> ActionResponse
Construct a success response to action request.
Parameters:
-
result
(Any
) –Result of the action.
Source code in academy/message.py
model_from_json
classmethod
¶
Reconstruct a specific message from a JSON dump.
Example
Source code in academy/message.py
model_deserialize
classmethod
¶
Deserialize a message.
Warning
This uses pickle and is therefore suceptible to all the typical pickle warnings about code injection.
Source code in academy/message.py
ActionResponse
pydantic-model
¶
Bases: BaseMessage
Agent action response message.
Fields:
-
tag
(UUID
) -
src
(EntityId
) -
dest
(EntityId
) -
label
(Optional[UUID]
) -
action
(str
) -
result
(Any
) -
exception
(Optional[Exception]
) -
kind
(Literal['action-response']
)
Validators:
exception
pydantic-field
¶
Exception of the action, if unsuccessful.
label
pydantic-field
¶
Optional label used to disambiguate response messages when multiple objects (i.e., handles) share the same mailbox. This is a different usage from the tag
.
model_from_json
classmethod
¶
Reconstruct a specific message from a JSON dump.
Example
Source code in academy/message.py
model_deserialize
classmethod
¶
Deserialize a message.
Warning
This uses pickle and is therefore suceptible to all the typical pickle warnings about code injection.
Source code in academy/message.py
PingRequest
pydantic-model
¶
Bases: BaseMessage
Ping request message.
Fields:
label
pydantic-field
¶
Optional label used to disambiguate response messages when multiple objects (i.e., handles) share the same mailbox. This is a different usage from the tag
.
response
¶
response() -> PingResponse
error
¶
error(exception: Exception) -> PingResponse
Construct an error response to ping request.
Parameters:
-
exception
(Exception
) –Error of the action.
Source code in academy/message.py
model_from_json
classmethod
¶
Reconstruct a specific message from a JSON dump.
Example
Source code in academy/message.py
model_deserialize
classmethod
¶
Deserialize a message.
Warning
This uses pickle and is therefore suceptible to all the typical pickle warnings about code injection.
Source code in academy/message.py
PingResponse
pydantic-model
¶
Bases: BaseMessage
Ping response message.
Fields:
-
tag
(UUID
) -
src
(EntityId
) -
dest
(EntityId
) -
label
(Optional[UUID]
) -
exception
(Optional[Exception]
) -
kind
(Literal['ping-response']
)
Validators:
-
_decode_pickled_obj
→exception
exception
pydantic-field
¶
Exception of the ping, if unsuccessful.
label
pydantic-field
¶
Optional label used to disambiguate response messages when multiple objects (i.e., handles) share the same mailbox. This is a different usage from the tag
.
model_from_json
classmethod
¶
Reconstruct a specific message from a JSON dump.
Example
Source code in academy/message.py
model_deserialize
classmethod
¶
Deserialize a message.
Warning
This uses pickle and is therefore suceptible to all the typical pickle warnings about code injection.
Source code in academy/message.py
ShutdownRequest
pydantic-model
¶
Bases: BaseMessage
Agent shutdown request message.
Fields:
Validators:
-
_validate_agent
→dest
label
pydantic-field
¶
Optional label used to disambiguate response messages when multiple objects (i.e., handles) share the same mailbox. This is a different usage from the tag
.
response
¶
response() -> ShutdownResponse
error
¶
error(exception: Exception) -> ShutdownResponse
Construct an error response to shutdown request.
Parameters:
-
exception
(Exception
) –Error of the action.
Source code in academy/message.py
model_from_json
classmethod
¶
Reconstruct a specific message from a JSON dump.
Example
Source code in academy/message.py
model_deserialize
classmethod
¶
Deserialize a message.
Warning
This uses pickle and is therefore suceptible to all the typical pickle warnings about code injection.
Source code in academy/message.py
ShutdownResponse
pydantic-model
¶
Bases: BaseMessage
Agent shutdown response message.
Fields:
-
tag
(UUID
) -
src
(EntityId
) -
dest
(EntityId
) -
label
(Optional[UUID]
) -
exception
(Optional[Exception]
) -
kind
(Literal['shutdown-response']
)
Validators:
-
_decode_pickled_obj
→exception
exception
pydantic-field
¶
Exception of the request, if unsuccessful.
label
pydantic-field
¶
Optional label used to disambiguate response messages when multiple objects (i.e., handles) share the same mailbox. This is a different usage from the tag
.
model_from_json
classmethod
¶
Reconstruct a specific message from a JSON dump.
Example
Source code in academy/message.py
model_deserialize
classmethod
¶
Deserialize a message.
Warning
This uses pickle and is therefore suceptible to all the typical pickle warnings about code injection.