{"record":{"id":"aaaeea0a378cc2af","repo":"microsoft/semantic-kernel","slug":"no-chat-history-available","errorCode":null,"errorMessage":"No chat history available.","messagePattern":"No chat history available\\.","errorType":"exception","errorClass":"AgentChatException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/channels/bedrock_agent_channel.py","lineNumber":63,"sourceCode":"    async def invoke(self, agent: \"Agent\", **kwargs: Any) -> AsyncIterable[tuple[bool, ChatMessageContent]]:\n        \"\"\"Perform a discrete incremental interaction between a single Agent and AgentChat.\n\n        Args:\n            agent: The agent to interact with.\n            kwargs: Additional keyword arguments.\n\n        Returns:\n            An async iterable of ChatMessageContent with a boolean indicating if the\n            message should be visible external to the agent.\n        \"\"\"\n        from semantic_kernel.agents.bedrock.bedrock_agent import BedrockAgent\n\n        if not isinstance(agent, BedrockAgent):\n            raise AgentChatException(f\"Agent is not of the expected type {type(BedrockAgent)}.\")\n        if not self.messages:\n            # This is not supposed to happen, as the channel won't get invoked\n            # before it has received messages. This is just extra safety.\n            raise AgentChatException(\"No chat history available.\")\n\n        # Preprocess chat history\n        await self._ensure_history_alternates()\n        await self._ensure_last_message_is_user()\n\n        async for response in agent.invoke(\n            messages=self.messages[-1].content,\n            thread=self.thread,\n            sessionState=await self._parse_chat_history_to_session_state(),\n        ):\n            # All messages from Bedrock agents are user facing, i.e., function calls are not returned as messages\n            self.messages.append(response.message)\n            yield True, response.message\n\n    @override\n    async def invoke_stream(\n        self,\n        agent: \"Agent\",","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/channels/bedrock_agent_channel.py#L45-L81","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nchat = AgentGroupChat(agent=bedrock_agent)\nawait chat.invoke()  # raises: no chat history\n// after\nchat = AgentGroupChat(agent=bedrock_agent)\nawait chat.add_chat_message(ChatMessageContent(role=AuthorRole.USER, content='hi'))\nawait chat.invoke()","handlingStrategy":"validation","validationCode":"if not history:\n    raise RuntimeError('Add a user message before invoking the chat')\nawait chat.add_chat_message(ChatMessageContent(role=AuthorRole.USER, content='hi'))\nawait chat.invoke()","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentChatException\ntry:\n    await chat.invoke()\nexcept AgentChatException as e:\n    if 'No chat history' in str(e):\n        await chat.add_chat_message(user_msg); await chat.invoke()\n    else: raise","preventionTips":["Always add at least one user message before invoking","Treat empty-history invoke as an orchestration ordering bug"],"tags":["bedrock","channel","chat-history","orchestration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}