microsoft/semantic-kernel · error · AgentChatException
Failed to delete thread: {e}
Error message
Failed to delete thread: {e} What it means
Raised by AzureAIChannel.reset when client.agents.threads.delete raises any exception during a channel reset. The original exception is interpolated into the message (not chained via 'from'), limiting introspection. Surfaced as AgentChatException.
Source
Thrown at python/semantic_kernel/agents/azure_ai/azure_ai_channel.py:121
yield message
@override
async def get_history(self) -> AsyncIterable["ChatMessageContent"]:
"""Get the conversation history.
Yields:
ChatMessageContent: The conversation history.
"""
async for message in AgentThreadActions.get_messages(self.client, thread_id=self.thread_id):
yield message
@override
async def reset(self) -> None:
"""Reset the agent's thread."""
try:
await self.client.agents.threads.delete(thread_id=self.thread_id)
except Exception as e:
raise AgentChatException(f"Failed to delete thread: {e}")
View on GitHub (pinned to c028a0c7dc)
Solutions
- Make reset tolerant of 'not found'/404 by catching AgentChatException and inspecting the embedded message/cause.
- Avoid calling reset() multiple times on the same channel without coordination.
- Retry transient network/5xx errors with backoff during reset.
Example fix
try:
await channel.reset()
except AgentChatException as e:
if 'not found' not in str(e).lower() and not _is_transient(e):
raise Defensive patterns
Strategy: try-catch
Try / catch
from semantic_kernel.exceptions.agent_exceptions import AgentChatException
try:
await channel.reset()
except AgentChatException as e:
msg = str(e).lower()
if 'not found' in msg:
return # thread already gone -> treat reset as success
if _is_transient_text(msg):
await asyncio.sleep(backoff); await channel.reset()
else:
raise Prevention
- Treat 'not found' during reset as benign/idempotent.
- Avoid concurrent resets of the same channel/thread.
- Log the embedded message to triage auth vs not-found vs transient.
When it happens
Trigger: Resetting a channel whose thread was already deleted server-side; auth/network failure during reset; the thread_id belongs to a different project; concurrent reset/delete by another client.
Common situations: Group-chat teardown calling reset() on a channel whose thread was already cleaned up; a thread deleted out-of-band; expired credential at teardown time; transient 5xx during shutdown.
Related errors
- The thread could not be deleted due to an error response fro
- Agent is not of the expected type {type(AzureAIAgent)}.
- The message could not be added to the thread due to an error
- The thread could not be created due to an error response fro
- The thread cannot be deleted because it has not been created
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/6fabbfaacf5f2913.
Report an issue: GitHub.