agentscope.module

The module in agentscope.

class StateModule[源代码]

基类:object

The state module class in agentscope to support nested state serialization and deserialization.

__init__()[源代码]

Initialize the state module.

返回类型:

None

state_dict()[源代码]

Get the state dictionary of the module, including the nested state modules and registered attributes.

返回:

A dictionary that keys are attribute names and values are the state of the attribute.

返回类型:

dict

load_state_dict(state_dict, strict=True)[源代码]

Load the state dictionary into the module.

参数:
  • state_dict (dict) -- The state dictionary to load.

  • strict (bool, defaults to True) -- If True, raises an error if any key in the module is not found in the state_dict. If False, skips missing keys.

返回类型:

None

register_state(attr_name, custom_to_json=None, custom_from_json=None)[源代码]

Register an attribute to be tracked as a state variable.

参数:
  • attr_name (str) -- The name of the attribute to register.

  • custom_to_json (Callable[[Any], JSONSerializableObject] | None, optional) -- A custom function to convert the attribute to a JSON-serializable format. If not provided, json.dumps will be used.

  • custom_from_json (Callable[[JSONSerializableObject], Any] | None , defaults to None) -- A custom function to convert the JSON dictionary back to the original attribute format.

返回类型:

None