Skip to content

GraphFlow fails to find next speaker when conditional edge is added (No available speakers found) #6551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SogoKato opened this issue May 16, 2025 · 3 comments

Comments

@SogoKato
Copy link

What happened?

Describe the bug
In a GraphFlow that includes a loop with exit and conditional branching, adding an edge to join into the terminal node causes a RuntimeError: No available speakers found.

To Reproduce
You can reproduce this with the following code. If you omit the linebuilder.add_edge(agent_c, agent_e), it works normally.

import asyncio

from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import MaxMessageTermination
from autogen_agentchat.teams import DiGraphBuilder, GraphFlow
from autogen_agentchat.ui import Console
from autogen_core.tools import FunctionTool
from autogen_ext.models.openai import OpenAIChatCompletionClient


async def main():
    # Initialize agents with OpenAI model clients.
    model_client = OpenAIChatCompletionClient(model="gpt-4.1-nano")
    agent_a = AssistantAgent(
        "A",
        model_client=model_client,
        system_message="Search the web.",
        tools=[web_search_function_tool],
    )
    agent_b = AssistantAgent(
        "B",
        model_client=model_client,
        system_message="Determine whether the previous agent obtained the optimal result for the user’s question. "
        "If the optimal result is found, respond with 'APPROVE'. "
        "If another search should be conducted, respond with 'SEARCH_AGAIN'. "
        "If multiple searches yield no relevant results, respond with 'NOT_FOUND'.",
    )
    agent_c = AssistantAgent(
        "C",
        model_client=model_client,
        system_message="Use the search results to answer your question",
    )
    agent_d = AssistantAgent(
        "D", model_client=model_client, system_message="You are a helpful assistant."
    )
    agent_e = AssistantAgent(
        "E", model_client=model_client, system_message="Translate input to Japanese."
    )

    # Create a directed graph with conditional branching and loop
    builder = DiGraphBuilder()
    builder.add_node(agent_a).add_node(agent_b).add_node(agent_c).add_node(
        agent_d
    ).add_node(agent_e)
    builder.add_edge(agent_a, agent_b)
    builder.add_edge(agent_b, agent_a, condition="SEARCH_AGAIN")
    builder.add_edge(agent_b, agent_c, condition="APPROVE")
    builder.add_edge(agent_b, agent_d, condition="NOT_FOUND")
    builder.add_edge(
        agent_c, agent_e
    )  # if this line added, `RuntimeError: No available speakers found.` will be raised.
    builder.add_edge(agent_d, agent_e)
    builder.set_entry_point(agent_a)
    graph = builder.build()

    # Create a GraphFlow team with the directed graph.
    team = GraphFlow(
        participants=builder.get_participants(),
        graph=graph,
        termination_condition=MaxMessageTermination(10),
    )

    # Run the team and print the events.
    # await Console(team.run_stream(task="What is AutoGen?"))
    await Console(team.run_stream(task="What is LangGraph?"))


async def web_search_func(query: str) -> str:
    """Find information on the web"""
    if "autogen" in query.lower():
        return (
            "AutoGen is a programming framework for building multi-agent applications."
        )
    return "No results."


web_search_function_tool = FunctionTool(
    web_search_func, description="Find information on the web"
)


if __name__ == "__main__":
    asyncio.run(main())

Expected behavior

After starting at A → B, the flow should then either:

  1. Loop B → A → B as long as the exit condition isn’t met,
  2. Transition B → C → E, or
  3. Transition B → D → E.

Screenshots

% rye run python main.py
---------- TextMessage (user) ----------
What is LangGraph?
---------- ToolCallRequestEvent (A) ----------
[FunctionCall(id='call_bUdgTvWyZ0eE0gCxp2J99ycJ', arguments='{"query":"What is LangGraph?"}', name='web_search_func')]
---------- ToolCallExecutionEvent (A) ----------
[FunctionExecutionResult(content='No results.', name='web_search_func', call_id='call_bUdgTvWyZ0eE0gCxp2J99ycJ', is_error=False)]
---------- ToolCallSummaryMessage (A) ----------
No results.
---------- TextMessage (B) ----------
SEARCH_AGAIN
---------- ToolCallRequestEvent (A) ----------
[FunctionCall(id='call_x5uTwkIbS7iL4Wckpb5S16vn', arguments='{"query": "What is LangGraph?"}', name='web_search_func')]
---------- ToolCallExecutionEvent (A) ----------
[FunctionExecutionResult(content='No results.', name='web_search_func', call_id='call_x5uTwkIbS7iL4Wckpb5S16vn', is_error=False)]
---------- ToolCallSummaryMessage (A) ----------
No results.
---------- TextMessage (B) ----------
NOT_FOUND
---------- TextMessage (D) ----------
It appears that there is no available information on "LangGraph" at this time. If you have more context or specific details about what LangGraph refers to, please share them, and I'll do my best to assist you further.
Error processing publish message for GraphManager_17f14989-847d-4561-994e-9c30d7068b5b/17f14989-847d-4561-994e-9c30d7068b5b
Traceback (most recent call last):
  File "/Users/sogo/tmp/ag/.venv/lib/python3.12/site-packages/autogen_core/_single_threaded_agent_runtime.py", line 604, in _on_message
    return await agent.on_message(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sogo/tmp/ag/.venv/lib/python3.12/site-packages/autogen_core/_base_agent.py", line 119, in on_message
    return await self.on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sogo/tmp/ag/.venv/lib/python3.12/site-packages/autogen_agentchat/teams/_group_chat/_sequential_routed_agent.py", line 67, in on_message_impl
    return await super().on_message_impl(message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sogo/tmp/ag/.venv/lib/python3.12/site-packages/autogen_core/_routed_agent.py", line 485, in on_message_impl
    return await h(self, message, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sogo/tmp/ag/.venv/lib/python3.12/site-packages/autogen_core/_routed_agent.py", line 268, in wrapper
    return_value = await func(self, message, ctx)  # type: ignore
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sogo/tmp/ag/.venv/lib/python3.12/site-packages/autogen_agentchat/teams/_group_chat/_base_group_chat_manager.py", line 165, in handle_agent_response
    speaker_name = await speaker_name_future
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sogo/tmp/ag/.venv/lib/python3.12/site-packages/autogen_agentchat/teams/_group_chat/_graph/_digraph_group_chat.py", line 357, in select_speaker
    raise RuntimeError("No available speakers found.")
RuntimeError: No available speakers found.
Traceback (most recent call last):
  File "/Users/sogo/tmp/ag/main.py", line 81, in <module>
    asyncio.run(main())
  File "/Users/sogo/.rye/py/cpython@3.12.2/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/sogo/.rye/py/cpython@3.12.2/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sogo/.rye/py/cpython@3.12.2/lib/python3.12/asyncio/base_events.py", line 685, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/sogo/tmp/ag/main.py", line 63, in main
    await Console(team.run_stream(task="What is LangGraph?"))
  File "/Users/sogo/tmp/ag/.venv/lib/python3.12/site-packages/autogen_agentchat/ui/_console.py", line 117, in Console
    async for message in stream:
  File "/Users/sogo/tmp/ag/.venv/lib/python3.12/site-packages/autogen_agentchat/teams/_group_chat/_base_group_chat.py", line 518, in run_stream
    raise RuntimeError(str(message.error))
RuntimeError: RuntimeError: No available speakers found.
Traceback:
Traceback (most recent call last):

  File "/Users/sogo/tmp/ag/.venv/lib/python3.12/site-packages/autogen_agentchat/teams/_group_chat/_base_group_chat_manager.py", line 165, in handle_agent_response
    speaker_name = await speaker_name_future
                   ^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/Users/sogo/tmp/ag/.venv/lib/python3.12/site-packages/autogen_agentchat/teams/_group_chat/_graph/_digraph_group_chat.py", line 357, in select_speaker
    raise RuntimeError("No available speakers found.")

RuntimeError: No available speakers found.

Additional context
Add any other context about the problem here.

Which packages was the bug in?

Python AgentChat (autogen-agentchat>=0.4.0)

AutoGen library version.

Python 0.5.7

Other library version.

No response

Model used

gpt-4.1-nano

Model provider

OpenAI

Other model provider

No response

Python version

3.12

.NET version

None

Operating system

MacOS

@salvprest
Copy link

salvprest commented May 17, 2025

I have a similar problem,
i have the flow
A -> B -> C -> D
conditional:
D -> C "OR" D -> E
then
E -> C "OR" E -> F

this give me the same error at the step B -> C of the linear flow (it don't see the C speaker)
if I Remove the conditional part of the flow, then the error disappear

Operating system:
Ubuntu 24.04
Python version:
3.12
Model:
gpt-4o

@ekzhu
Copy link
Collaborator

ekzhu commented May 17, 2025

Thanks for the issue. This will be addressed through #6542

If a node's edges are all conditional, and none of the conditions are met, no next node can be found.

@SogoKato
Copy link
Author

Thank you for the response!

In the example above, agent D only has a single, unconditional edge to agent E, yet GraphFlow still fails to find that next node. This suggests that even non-conditional outgoing edges are ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants