{"record":{"id":"16fc4bb4b7873c4d","repo":"microsoft/autogen","slug":"agent-save-state-is-not-yet-implemented","errorCode":null,"errorMessage":"Agent save_state is not yet implemented.","messagePattern":"Agent save_state is not yet implemented\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/runtimes/grpc/_worker_runtime.py","lineNumber":502,"sourceCode":"                )\n\n            telemetry_metadata = get_telemetry_grpc_metadata()\n            task = asyncio.create_task(self._send_message(runtime_message, \"publish\", topic_id, telemetry_metadata))\n            self._background_tasks.add(task)\n            task.add_done_callback(self._raise_on_exception)\n            task.add_done_callback(self._background_tasks.discard)\n\n    async def save_state(self) -> Mapping[str, Any]:\n        raise NotImplementedError(\"Saving state is not yet implemented.\")\n\n    async def load_state(self, state: Mapping[str, Any]) -> None:\n        raise NotImplementedError(\"Loading state is not yet implemented.\")\n\n    async def agent_metadata(self, agent: AgentId) -> AgentMetadata:\n        raise NotImplementedError(\"Agent metadata is not yet implemented.\")\n\n    async def agent_save_state(self, agent: AgentId) -> Mapping[str, Any]:\n        raise NotImplementedError(\"Agent save_state is not yet implemented.\")\n\n    async def agent_load_state(self, agent: AgentId, state: Mapping[str, Any]) -> None:\n        raise NotImplementedError(\"Agent load_state is not yet implemented.\")\n\n    async def _get_new_request_id(self) -> str:\n        async with self._pending_requests_lock:\n            self._next_request_id += 1\n            return str(self._next_request_id)\n\n    async def _process_request(self, request: agent_worker_pb2.RpcRequest) -> None:\n        assert self._host_connection is not None\n        recipient = AgentId(request.target.type, request.target.key)\n        sender: AgentId | None = None\n        if request.HasField(\"source\"):\n            sender = AgentId(request.source.type, request.source.key)\n            logging.info(f\"Processing request from {sender} to {recipient}\")\n        else:\n            logging.info(f\"Processing request from unknown source to {recipient}\")","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/runtimes/grpc/_worker_runtime.py#L484-L520","documentation":"GrpcWorkerAgentRuntime.agent_save_state() always raises NotImplementedError: saving an individual agent's state via the runtime is not supported in the distributed gRPC model, where agents live in (possibly remote) worker processes the runtime cannot introspect.","triggerScenarios":"Calling `await runtime.agent_save_state(agent_id)` on GrpcWorkerAgentRuntime, e.g. from generic persistence layers built on the AgentRuntime interface.","commonSituations":"Migrating stateful multi-agent apps from the local runtime; framework code that snapshots each agent via the runtime API.","solutions":["Persist agent state inside the agent itself (its handlers or a dedicated save message) rather than via the runtime","Condition persistence logic on runtime type and skip for gRPC workers","Use the local runtime where per-agent state APIs are required"],"exampleFix":"# before\nstate = await runtime.agent_save_state(agent_id)  # NotImplementedError\n\n# after\nstate = await runtime.send_message(SaveStateRequest(), agent_id)  # agent handles it","handlingStrategy":"type-guard","validationCode":"from autogen_ext.runtimes.grpc import GrpcWorkerAgentRuntime\n\nif isinstance(runtime, GrpcWorkerAgentRuntime):\n    state = await runtime.send_message(SaveStateRequest(), agent_id)  # agent handles it\nelse:\n    state = await runtime.agent_save_state(agent_id)","typeGuard":"def runtime_has_per_agent_state(runtime: object) -> bool:\n    return not isinstance(runtime, GrpcWorkerAgentRuntime)","tryCatchPattern":"try:\n    state = await runtime.agent_save_state(agent_id)\nexcept NotImplementedError:\n    state = await runtime.send_message(SaveStateRequest(), agent_id)","preventionTips":["Implement a SaveState message handler in stateful agents","Centralize persistence in app code rather than runtime APIs","Detect runtime type before per-agent state operations"],"tags":["python","autogen","grpc","not-implemented","state-management"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}