{"record":{"id":"245d742e133db1d4","repo":"microsoft/semantic-kernel","slug":"no-agents-are-available","errorCode":null,"errorMessage":"No agents are available","messagePattern":"No agents are available","errorType":"exception","errorClass":"AgentChatException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/group_chat/agent_group_chat.py","lineNumber":141,"sourceCode":"            is_joining: Controls whether the agent joins the chat. Defaults to True.\n\n        Yields:\n            The chat message.\n        \"\"\"\n        if agent is not None:\n            if is_joining:\n                self.add_agent(agent)\n\n            async for message in super().invoke_agent(agent):\n                if message.role == AuthorRole.ASSISTANT:\n                    task = self.termination_strategy.should_terminate(agent, self.history.messages)\n                    self.is_complete = await task\n                yield message\n\n            return\n\n        if not self.agents:\n            raise AgentChatException(\"No agents are available\")\n\n        if self.is_complete:\n            if not self.termination_strategy.automatic_reset:\n                raise AgentChatException(\"Chat is already complete\")\n\n            self.is_complete = False\n\n        for _ in range(self.termination_strategy.maximum_iterations):\n            try:\n                selected_agent = await self.selection_strategy.next(self.agents, self.history.messages)\n            except Exception as ex:\n                logger.error(f\"Failed to select agent: {ex}\")\n                raise AgentChatException(\"Failed to select agent\") from ex\n\n            async for message in super().invoke_agent(selected_agent):\n                if message.role == AuthorRole.ASSISTANT:\n                    task = self.termination_strategy.should_terminate(selected_agent, self.history.messages)\n                    self.is_complete = await task","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/group_chat/agent_group_chat.py#L123-L159","documentation":"Raised by AgentGroupChat.invoke() when no agent argument is supplied and self.agents is empty. The group-chat invoke loop needs at least one agent to select and invoke via the selection strategy. With zero agents there is nothing to iterate. It is an AgentChatException.","triggerScenarios":"Constructing AgentGroupChat() with no agents (or an empty list) and then calling await chat.invoke() (no agent argument) expecting automatic multi-agent iteration.","commonSituations":"Agents added conditionally and the condition never met; agents list built dynamically and came back empty; forgetting to pass agents to the AgentGroupChat constructor or call add_agent before invoke.","solutions":["Pass agents to the AgentGroupChat constructor: AgentGroupChat(agents=[a1, a2]).","Call chat.add_agent(agent) before invoking.","Guard the invoke call: if not chat.agents: add agents first."],"exampleFix":"# before\nchat = AgentGroupChat()\nasync for msg in chat.invoke():  # raises\n    ...\n\n# after\nchat = AgentGroupChat(agents=[agent1, agent2])\nasync for msg in chat.invoke():\n    ...","handlingStrategy":"validation","validationCode":"if not chat.agents:\n    raise ValueError(\"Add at least one agent before invoking the group chat\")\nasync for msg in chat.invoke():\n    ...","typeGuard":"def has_agents(chat) -> bool:\n    return len(chat.agents) > 0","tryCatchPattern":null,"preventionTips":["Pass agents to the AgentGroupChat constructor or call add_agent before invoke.","Guard invoke calls with a check on chat.agents.","Validate dynamic agent lists are non-empty before constructing the group chat."],"tags":["validation","group-chat","no-agents"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}