A programming framework for agentic AI
Add API doc for save_state and load_state for SingleThreadedAgentRuntime (#5984)
Eric Zhu855bcd711c9a
diff --git a/python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py b/python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.pyindex 0b11ca292..9610e7f54 100644--- a/python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py+++ b/python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py@@ -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 stateasync 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: