{"record":{"id":"0c935eb8d61a2bfd","repo":"microsoft/semantic-kernel","slug":"cannot-create-a-new-thread-since-the-current-thre","errorCode":null,"errorMessage":"Cannot create a new thread, since the current thread has been deleted.","messagePattern":"Cannot create a new thread, since the current thread has been deleted\\.","errorType":"exception","errorClass":"AgentThreadOperationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/openai_responses_agent.py","lineNumber":198,"sourceCode":"        \"\"\"Set the response ID.\"\"\"\n        self._response_id = value\n\n    @property\n    def store_enabled(self) -> bool:\n        \"\"\"Check if the store is enabled.\"\"\"\n        return self._enable_store\n\n    @override\n    @property\n    def id(self) -> str | None:\n        \"\"\"Get the thread ID.\"\"\"\n        return self.response_id\n\n    @override\n    async def _create(self) -> str:\n        \"\"\"Starts the thread and returns its ID.\"\"\"\n        if self._is_deleted:\n            raise AgentThreadOperationException(\n                \"Cannot create a new thread, since the current thread has been deleted.\"\n            )\n        self._enable_store = True\n\n        # The ID isn't available until after a message is sent\n        return \"\"\n\n    @override\n    async def _delete(self) -> None:\n        \"\"\"Ends the current thread.\"\"\"\n        if self._is_deleted:\n            return\n        if self.response_id is None:\n            raise AgentThreadOperationException(\"Cannot delete the thread, since it has not been created.\")\n        self._chat_history.clear()\n        self._is_deleted = True\n\n    @override","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/openai_responses_agent.py#L180-L216","documentation":"Raised as AgentThreadOperationException by ResponseAgentThread._create() when the thread has already been deleted (_is_deleted True). The Responses thread is created lazily (its id arrives only after the first message); once deleted, the internal state forbids re-creating on the same object, so you must instantiate a new ResponseAgentThread.","triggerScenarios":"Calling thread.create() after thread.delete() on the same ResponseAgentThread; a chat loop that deletes then retries on the same thread object; cleanup-then-reuse patterns.","commonSituations":"Conversation reset logic that deletes and recreates the thread in place; long-lived session objects reused across conversations; error-handling paths that delete on failure then retry.","solutions":["Create a new ResponseAgentThread(client=...) for a fresh conversation instead of recreating a deleted one.","Do not call create() after delete(); branch your logic to instantiate a fresh thread.","Guard with a check or replace the deleted reference entirely."],"exampleFix":"# before\nawait thread.delete()\nawait thread.create()\n\n# after\nawait thread.delete()\nthread = ResponseAgentThread(client=client)\nawait thread.create()","handlingStrategy":"validation","validationCode":"if getattr(thread, '_is_deleted', False):\n    thread = ResponseAgentThread(client=client)\nawait thread.create()","typeGuard":"def response_thread_is_alive(thread) -> bool:\n    return not getattr(thread, '_is_deleted', False)","tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentThreadOperationException\ntry:\n    await thread.create()\nexcept AgentThreadOperationException as e:\n    if 'deleted' in str(e):\n        thread = ResponseAgentThread(client=client)\n        await thread.create()","preventionTips":["Replace the thread object on reset, do not recreate in place.","Track lifecycle in your own state.","Never create() after delete() on the same instance."],"tags":["thread-lifecycle","agents","openai-responses","state"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}