microsoft/semantic-kernel · error · AgentChatException
No chat history available.
Error message
No chat history available.
What it means
Raised by BedrockAgentChannel.invoke as a defensive AgentChatException when self.messages is empty. The channel preprocesses history (alternate roles, ensure last is user) and forwards the last message, so an empty history is treated as an internal invariant violation that should not normally occur.
Source
Thrown at python/semantic_kernel/agents/channels/bedrock_agent_channel.py:63
async def invoke(self, agent: "Agent", **kwargs: Any) -> AsyncIterable[tuple[bool, ChatMessageContent]]:
"""Perform a discrete incremental interaction between a single Agent and AgentChat.
Args:
agent: The agent to interact with.
kwargs: Additional keyword arguments.
Returns:
An async iterable of ChatMessageContent with a boolean indicating if the
message should be visible external to the agent.
"""
from semantic_kernel.agents.bedrock.bedrock_agent import BedrockAgent
if not isinstance(agent, BedrockAgent):
raise AgentChatException(f"Agent is not of the expected type {type(BedrockAgent)}.")
if not self.messages:
# This is not supposed to happen, as the channel won't get invoked
# before it has received messages. This is just extra safety.
raise AgentChatException("No chat history available.")
# Preprocess chat history
await self._ensure_history_alternates()
await self._ensure_last_message_is_user()
async for response in agent.invoke(
messages=self.messages[-1].content,
thread=self.thread,
sessionState=await self._parse_chat_history_to_session_state(),
):
# All messages from Bedrock agents are user facing, i.e., function calls are not returned as messages
self.messages.append(response.message)
yield True, response.message
@override
async def invoke_stream(
self,
agent: "Agent",View on GitHub (pinned to c028a0c7dc)
Solutions
- Add at least one user message to the chat (chat.add_chat_message(...)) before invoking.
- If orchestrating channels manually, ensure self.messages is populated before calling invoke.
- Treat this error as a bug in your orchestration flow rather than a runtime data condition, and fix the call ordering.
- Add an upstream guard so invoke is never reached with empty history.
Example fix
// before chat = AgentGroupChat(agent=bedrock_agent) await chat.invoke() # raises: no chat history // after chat = AgentGroupChat(agent=bedrock_agent) await chat.add_chat_message(ChatMessageContent(role=AuthorRole.USER, content='hi')) await chat.invoke()
Defensive patterns
Strategy: validation
Validate before calling
if not history:
raise RuntimeError('Add a user message before invoking the chat')
await chat.add_chat_message(ChatMessageContent(role=AuthorRole.USER, content='hi'))
await chat.invoke() Try / catch
from semantic_kernel.exceptions.agent_exceptions import AgentChatException
try:
await chat.invoke()
except AgentChatException as e:
if 'No chat history' in str(e):
await chat.add_chat_message(user_msg); await chat.invoke()
else: raise Prevention
- Always add at least one user message before invoking
- Treat empty-history invoke as an orchestration ordering bug
When it happens
Trigger: The channel's invoke is called before any message has been added to self.messages; a race or logic error in the chat orchestration that invokes a channel with no history.
Common situations: Invoking an AgentGroupChat before calling add_chat_message; a custom orchestration that calls channel.invoke directly on a fresh channel; message-list mutation that empties history between add and invoke.
Related errors
- Agent is not of the expected type {type(BedrockAgent)}.
- Only text and image content are supported in a user message.
- Image content is not supported in an assistant message.
- Unsupported content type in an assistant message: {type(item
- Image content is not supported in a tool message.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/aaaeea0a378cc2af.
Report an issue: GitHub.