microsoft/semantic-kernel · error · AgentChatException

No agents are available

Error message

No agents are available

What it means

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.

Source

Thrown at python/semantic_kernel/agents/group_chat/agent_group_chat.py:141

            is_joining: Controls whether the agent joins the chat. Defaults to True.

        Yields:
            The chat message.
        """
        if agent is not None:
            if is_joining:
                self.add_agent(agent)

            async for message in super().invoke_agent(agent):
                if message.role == AuthorRole.ASSISTANT:
                    task = self.termination_strategy.should_terminate(agent, self.history.messages)
                    self.is_complete = await task
                yield message

            return

        if not self.agents:
            raise AgentChatException("No agents are available")

        if self.is_complete:
            if not self.termination_strategy.automatic_reset:
                raise AgentChatException("Chat is already complete")

            self.is_complete = False

        for _ in range(self.termination_strategy.maximum_iterations):
            try:
                selected_agent = await self.selection_strategy.next(self.agents, self.history.messages)
            except Exception as ex:
                logger.error(f"Failed to select agent: {ex}")
                raise AgentChatException("Failed to select agent") from ex

            async for message in super().invoke_agent(selected_agent):
                if message.role == AuthorRole.ASSISTANT:
                    task = self.termination_strategy.should_terminate(selected_agent, self.history.messages)
                    self.is_complete = await task

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass agents to the AgentGroupChat constructor: AgentGroupChat(agents=[a1, a2]).
  2. Call chat.add_agent(agent) before invoking.
  3. Guard the invoke call: if not chat.agents: add agents first.

Example fix

# before
chat = AgentGroupChat()
async for msg in chat.invoke():  # raises
    ...

# after
chat = AgentGroupChat(agents=[agent1, agent2])
async for msg in chat.invoke():
    ...
Defensive patterns

Strategy: validation

Validate before calling

if not chat.agents:
    raise ValueError("Add at least one agent before invoking the group chat")
async for msg in chat.invoke():
    ...

Type guard

def has_agents(chat) -> bool:
    return len(chat.agents) > 0

Prevention

When it happens

Trigger: Constructing AgentGroupChat() with no agents (or an empty list) and then calling await chat.invoke() (no agent argument) expecting automatic multi-agent iteration.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/245d742e133db1d4. Report an issue: GitHub.