microsoft/semantic-kernel · error · AgentThreadOperationException
Cannot reduce chat history, since the thread is not…
Error message
Cannot reduce chat history, since the thread is not currently active.
What it means
Raised by the chat-completion AgentThread.reduce (an AgentThreadOperationException) when self._id is None, i.e. the thread has not been created/activated yet. History reduction only applies to an active thread whose chat history is the live one.
Solutions
- Ensure the thread is active (await thread.create() or add a message first) before calling reduce.
- Guard reduce with a check that the thread is active, or call get_response/invoke first so the thread is created.
- Confirm the AgentThread is configured with a ChatHistoryReducer if you expect reduction to do work.
- Reorder logic so reduction runs after the first interaction, not before creation.
Example fix
// before reduced = await thread.reduce() # raises: thread not active // after await thread.create() # or send a message first reduced = await thread.reduce()
Defensive patterns
Strategy: validation
Validate before calling
if thread._id is None:
await thread.create()
reduced = await thread.reduce() Type guard
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
- Create/activate the thread before reduction
- Confirm a ChatHistoryReducer is configured if reduction is expected
When it happens
Trigger: Calling thread.reduce() before the thread has been created (create() never awaited, or _id is still None); calling reduce on a freshly constructed thread that lazy-creates on first message but has seen no activity.
Common situations: Attempting summarization/reduction during setup before any message forces creation; a thread configured with a reducer but never started; reduce called in a branch where creation was skipped.
Related errors
- Cannot retrieve chat history, since the thread has been…
- Cannot reduce chat history, since the thread is not…
- MaxTokens is not valid, the value must be greater than zero
- A complete then action is required for orchestration steps.
- A function name can contain only ASCII letters, digits…
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/bb6f4d8a201f4db5.
Report an issue: GitHub.
Appendix: source
Thrown at python/semantic_kernel/agents/chat_completion/chat_completion_agent.py:110
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()
@register_agent_type("chat_completion_agent")
class ChatCompletionAgent(DeclarativeSpecMixin, Agent):
"""A Chat Completion Agent based on ChatCompletionClientBase."""
function_choice_behavior: FunctionChoiceBehavior | None = Field(
default_factory=lambda: FunctionChoiceBehavior.Auto()
)
channel_type: ClassVar[type[AgentChannel] | None] = ChatHistoryChannel
service: ChatCompletionClientBase | None = Field(default=None, exclude=True)
def __init__(
self,
*,View on GitHub (pinned to c028a0c7dc)