microsoft/semantic-kernel · error · AgentThreadOperationException
Cannot reduce chat history, since the thread is not currentl
Error message
Cannot reduce chat history, since the thread is not currently active.
What it means
Thrown by AutoGenConversableAgentThread.reduce when self._id is None, i.e. the thread was never created/activated (create() not yet called or never auto-invoked). reduce delegates to the underlying ChatHistoryReducer only on an active thread, so an inactive one is rejected up front.
Source
Thrown at python/semantic_kernel/agents/autogen/autogen_conversable_agent.py:98
self._chat_history.add_message(new_message)
async def get_messages(self) -> AsyncIterable[ChatMessageContent]:
"""Retrieve the current chat history.
Returns:
An async iterable of ChatMessageContent.
"""
if self._is_deleted:
raise AgentThreadOperationException("Cannot retrieve chat history, since the thread has been deleted.")
if self._id is None:
await self.create()
for message in self._chat_history.messages:
yield message
async def reduce(self) -> ChatHistory | None:
"""Reduce the chat history to a smaller size."""
if self._id is None:
raise AgentThreadOperationException("Cannot reduce chat history, since the thread is not currently active.")
if not isinstance(self._chat_history, ChatHistoryReducer):
return None
return await self._chat_history.reduce()
@experimental
class AutoGenConversableAgent(Agent):
"""A Semantic Kernel wrapper around an AutoGen 0.2 `ConversableAgent`.
This allows one to use it as a Semantic Kernel `Agent`. Note: this agent abstraction
does not currently allow for the use of AgentGroupChat within Semantic Kernel.
"""
conversable_agent: ConversableAgent
def __init__(self, conversable_agent: ConversableAgent, **kwargs: Any) -> None:
"""Initialize the AutoGenConversableAgent.
View on GitHub (pinned to c028a0c7dc)
Solutions
- Ensure the thread is active first: `await thread.create()` (or run an invoke that triggers creation) before reduce.
- Construct the thread with an explicit thread_id so _id is set.
- Guard reduce behind an `if thread.id is not None` check.
Example fix
# before thread = AutoGenConversableAgentThread() await thread.reduce() # after thread = AutoGenConversableAgentThread() await thread.create() await thread.reduce()
Defensive patterns
Strategy: validation
Validate before calling
if thread.id is None:
await thread.create()
result = await thread.reduce() Type guard
async def thread_is_active(thread) -> bool:
return getattr(thread, '_id', None) is not None Try / catch
from semantic_kernel.exceptions.agent_exceptions import AgentThreadOperationException
try:
reduced = await thread.reduce()
except AgentThreadOperationException as e:
if 'not currently active' in str(e):
await thread.create()
reduced = await thread.reduce()
else:
raise Prevention
- Activate the thread (create() or an invoke) before calling reduce.
- Construct threads with a thread_id when you need immediate activity.
When it happens
Trigger: Constructing `AutoGenConversableAgentThread()` and immediately calling `await thread.reduce()` without first invoking the agent (which lazily calls create()) or calling thread.create().
Common situations: Calling reduce in setup before any message exchange; thread instantiated with thread_id=None and never activated.
Related errors
- Cannot retrieve chat history, since the thread has been dele
- Thread has been deleted; call `create()` to recreate it.
- Cannot create thread because it has already been deleted.
- This thread has been deleted and cannot be used anymore.
- This thread has been deleted and cannot be recreated.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/88e80c56cf0c003f.
Report an issue: GitHub.