mirror of
https://github.com/microsoft/autogen.git
synced 2025-12-29 07:59:50 +00:00
Add API doc for save_state and load_state for SingleThreadedAgentRuntime (#5984)
Resolves #4108
This commit is contained in:
parent
8f42e5a27f
commit
855bcd711c
@ -376,12 +376,35 @@ class SingleThreadedAgentRuntime(AgentRuntime):
|
||||
)
|
||||
|
||||
async def save_state(self) -> Mapping[str, Any]:
|
||||
"""Save the state of all instantiated agents.
|
||||
|
||||
This method calls the :meth:`~autogen_core.BaseAgent.save_state` method on each agent and returns a dictionary
|
||||
mapping agent IDs to their state.
|
||||
|
||||
.. note::
|
||||
This method does not currently save the subscription state. We will add this in the future.
|
||||
|
||||
Returns:
|
||||
A dictionary mapping agent IDs to their state.
|
||||
|
||||
"""
|
||||
state: Dict[str, Dict[str, Any]] = {}
|
||||
for agent_id in self._instantiated_agents:
|
||||
state[str(agent_id)] = dict(await (await self._get_agent(agent_id)).save_state())
|
||||
return state
|
||||
|
||||
async def load_state(self, state: Mapping[str, Any]) -> None:
|
||||
"""Load the state of all instantiated agents.
|
||||
|
||||
This method calls the :meth:`~autogen_core.BaseAgent.load_state` method on each agent with the state
|
||||
provided in the dictionary. The keys of the dictionary are the agent IDs, and the values are the state
|
||||
dictionaries returned by the :meth:`~autogen_core.BaseAgent.save_state` method.
|
||||
|
||||
.. note::
|
||||
|
||||
This method does not currently load the subscription state. We will add this in the future.
|
||||
|
||||
"""
|
||||
for agent_id_str in state:
|
||||
agent_id = AgentId.from_str(agent_id_str)
|
||||
if agent_id.type in self._known_agent_names:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user