academy.message¶
ActionRequest
pydantic-model
¶
Bases: BaseModel
Agent action request message.
Warning
The positional and keywords arguments for the invoked action are pickled and base64-encoded when serialized to JSON. This can have non-trivial time and space overheads for large arguments.
Config:
default
:DEFAULT_MUTABLE_CONFIG
Fields:
-
action
(str
) -
pargs
(SkipValidation[tuple[Any, ...]]
) -
kargs
(SkipValidation[dict[str, Any]]
) -
kind
(Literal['action-request']
)
pargs
pydantic-field
¶
pargs: SkipValidation[tuple[Any, ...]]
Positional arguments to the action method.
kargs
pydantic-field
¶
kargs: SkipValidation[dict[str, Any]]
Keyword arguments to the action method.
get_args
¶
Get the positional arguments.
Lazily deserializes and returns the positional arguments. Caches the result to avoid redundant decoding.
Returns:
Source code in academy/message.py
get_kwargs
¶
Get the keyword arguments.
Lazily deserializes and returns the keyword arguments. Caches the result to avoid redundant decoding.
Returns:
Source code in academy/message.py
PingRequest
pydantic-model
¶
ShutdownRequest
pydantic-model
¶
ActionResponse
pydantic-model
¶
Bases: BaseModel
Agent action response message.
Warning
The result is pickled and base64-encoded when serialized to JSON. This can have non-trivial time and space overheads for large results.
Config:
default
:DEFAULT_MUTABLE_CONFIG
Fields:
get_result
¶
get_result() -> Any
Get the result.
Lazily deserializes and returns the result of the action. Caches the result to avoid redundant decoding.
Returns:
-
Any
–The deserialized result of the action.
Source code in academy/message.py
ErrorResponse
pydantic-model
¶
Bases: BaseModel
Error response message.
Contains the exception raised by a failed request.
Config:
default
:DEFAULT_MUTABLE_CONFIG
Fields:
-
exception
(SkipValidation[Exception]
) -
kind
(Literal['error-response']
)
get_exception
¶
get_exception() -> Exception
Get the exception.
Lazily deserializes and returns the exception object. Caches the result to avoid redundant decoding.
Returns:
-
Exception
–The deserialized exception.
Source code in academy/message.py
SuccessResponse
pydantic-model
¶
Header
pydantic-model
¶
Bases: BaseModel
Message metadata header.
Contains information about the sender, receiver, and message context.
Config:
default
:DEFAULT_FROZEN_CONFIG
Fields:
-
src
(EntityId
) -
dest
(EntityId
) -
tag
(UUID
) -
label
(Optional[UUID]
) -
kind
(Literal['request', 'response']
)
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
.
create_response_header
¶
Create a response header based on the current request header.
Swaps the source and destination, retains the tag and label, and sets the kind to 'response'.
Returns:
-
Self
–A new header instance with reversed roles.
Raises:
-
ValueError
–If the current header is already a response.
Source code in academy/message.py
Message
pydantic-model
¶
Bases: BaseModel
, Generic[BodyT]
A complete message with header and body.
Wraps a header and a typed request/response body. Supports lazy deserialization of message bodies, metadata access, and convenient construction.
Note
The body value is ignored when testing equality or hashing an instance
because the body value could be in either a serialized or
deserialized state until
get_body()
is called.
Config:
default
:DEFAULT_MUTABLE_CONFIG
Fields:
-
header
(Header
) -
body
(SkipValidation[BodyT]
)
create
classmethod
¶
create(
src: EntityId,
dest: EntityId,
body: BodyT,
*,
label: UUID | None = None
) -> Message[BodyT]
Create a new message with the specified header and body.
Parameters:
-
src
(EntityId
) –Source entity ID.
-
dest
(EntityId
) –Destination entity ID.
-
body
(BodyT
) –Message body.
-
label
(UUID | None
, default:None
) –Optional label for disambiguation.
Returns:
-
Message[BodyT]
–A new message instance.
Source code in academy/message.py
create_response
¶
create_response(body: ResponseT) -> Message[ResponseT]
Create a response message from this request message.
Parameters:
-
body
(ResponseT
) –Response message body.
Returns:
-
Message[ResponseT]
–A new response message instance.
Raises:
-
ValueError
–If this message is already a response.
Source code in academy/message.py
get_body
¶
Return the message body, deserializing if needed.
Lazily deserializes and returns the body object. Caches the body to avoid redundant decoding.
Returns:
-
BodyT
–The deserialized body.
Source code in academy/message.py
model_deserialize
classmethod
¶
Deserialize a message from bytes using pickle.
Warning
This uses pickle and is therefore susceptible to all the typical pickle warnings about code injection.
Parameters:
-
data
(bytes
) –The serialized message as bytes.
Returns:
-
Message[BodyT]
–The deserialized message instance.
Raises:
-
TypeError
–If the deserialized object is not a Message.