agentscope.session¶
The session module in agentscope.
- class SessionBase[source]¶
Bases:
object
The base class for session in agentscope.
- abstract async save_session_state(session_id, **state_modules_mapping)[source]¶
Save the session state
- Parameters:
session_id (str) – The session id.
**state_modules_mapping (dict[str, StateModule]) – A dictionary mapping of state module names to their instances.
- Return type:
None
- abstract async load_session_state(session_id, allow_not_exist=True, **state_modules_mapping)[source]¶
Load the session state
- Parameters:
session_id (str)
allow_not_exist (bool)
state_modules_mapping (StateModule)
- Return type:
None
- class JSONSession[source]¶
Bases:
SessionBase
The JSON session class.
- __init__(session_id=None, save_dir='./')[source]¶
Initialize the JSON session class.
- Parameters:
session_id (str) – The session id, deprecated and move to the save_session_state and load_session_state methods to support different session ids.
save_dir (str, defaults to `”./”) – The directory to save the session state.
- Return type:
None
- async save_session_state(session_id, **state_modules_mapping)[source]¶
Load the state dictionary from a JSON file.
- Parameters:
session_id (str) – The session id.
**state_modules_mapping (dict[str, StateModule]) – A dictionary mapping of state module names to their instances.
- Return type:
None
- async load_session_state(session_id, allow_not_exist=True, **state_modules_mapping)[source]¶
Get the state dictionary to be saved to a JSON file.
- Parameters:
session_id (str) – The session id.
allow_not_exist (bool, defaults to True) – Whether to allow the session to not exist. If False, raises an error if the session does not exist.
state_modules_mapping (list[StateModule]) – The list of state modules to be loaded.
- Return type:
None