microsoft/semantic-kernel · error · AgentThreadOperationException
Cannot create a new thread, since the current thread has bee
Error message
Cannot create a new thread, since the current thread has been deleted.
What it means
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.
Source
Thrown at python/semantic_kernel/agents/open_ai/openai_responses_agent.py:198
"""Set the response ID."""
self._response_id = value
@property
def store_enabled(self) -> bool:
"""Check if the store is enabled."""
return self._enable_store
@override
@property
def id(self) -> str | None:
"""Get the thread ID."""
return self.response_id
@override
async def _create(self) -> str:
"""Starts the thread and returns its ID."""
if self._is_deleted:
raise AgentThreadOperationException(
"Cannot create a new thread, since the current thread has been deleted."
)
self._enable_store = True
# The ID isn't available until after a message is sent
return ""
@override
async def _delete(self) -> None:
"""Ends the current thread."""
if self._is_deleted:
return
if self.response_id is None:
raise AgentThreadOperationException("Cannot delete the thread, since it has not been created.")
self._chat_history.clear()
self._is_deleted = True
@overrideView on GitHub (pinned to c028a0c7dc)
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.
Example fix
# before await thread.delete() await thread.create() # after await thread.delete() thread = ResponseAgentThread(client=client) await thread.create()
Defensive patterns
Strategy: validation
Validate before calling
if getattr(thread, '_is_deleted', False):
thread = ResponseAgentThread(client=client)
await thread.create() Type guard
def response_thread_is_alive(thread) -> bool:
return not getattr(thread, '_is_deleted', False) Try / catch
from semantic_kernel.exceptions.agent_exceptions import AgentThreadOperationException
try:
await thread.create()
except AgentThreadOperationException as e:
if 'deleted' in str(e):
thread = ResponseAgentThread(client=client)
await thread.create() Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot delete the thread, since it has not been created.
- The thread has been deleted.
- Missing or malformed 'vector_store_ids' in: {spec}
- Tool spec must include a 'type' field.
- Unsupported tool type: {spec.type}
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/0c935eb8d61a2bfd.
Report an issue: GitHub.