{"record":{"id":"1f259cef837df9ee","repo":"microsoft/autogen","slug":"graph-has-no-nodes","errorCode":null,"errorMessage":"Graph has no nodes.","messagePattern":"Graph has no nodes\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_graph/_digraph_group_chat.py","lineNumber":210,"sourceCode":"        has_cycle = False\n        for node in self.nodes:\n            if node not in visited:\n                if dfs(node):\n                    has_cycle = True\n\n        return has_cycle\n\n    def get_has_cycles(self) -> bool:\n        \"\"\"Indicates if the graph has at least one cycle (with valid exit conditions).\"\"\"\n        if self._has_cycles is None:\n            self._has_cycles = self.has_cycles_with_exit()\n\n        return self._has_cycles\n\n    def graph_validate(self) -> None:\n        \"\"\"Validate graph structure and execution rules.\"\"\"\n        if not self.nodes:\n            raise ValueError(\"Graph has no nodes.\")\n\n        if not self.get_start_nodes():\n            raise ValueError(\"Graph must have at least one start node\")\n\n        if not self.get_leaf_nodes():\n            raise ValueError(\"Graph must have at least one leaf node\")\n\n        # Outgoing edge condition validation (per node)\n        for node in self.nodes.values():\n            # Check that if a node has an outgoing conditional edge, then all outgoing edges are conditional\n            has_condition = any(\n                edge.condition is not None or edge.condition_function is not None for edge in node.edges\n            )\n            has_unconditioned = any(edge.condition is None and edge.condition_function is None for edge in node.edges)\n            if has_condition and has_unconditioned:\n                raise ValueError(f\"Node '{node.name}' has a mix of conditional and unconditional edges.\")\n\n        # Validate activation conditions across all edges in the graph","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_graph/_digraph_group_chat.py#L192-L228","documentation":"Raised by DiGraph.graph_validate when the graph contains no nodes at all. Every GraphFlow needs at least one node to execute; an empty graph (only a DiGraphBuilder with set_start_node on nothing, or no add_edge calls) is a construction bug and is rejected immediately at team creation time.","triggerScenarios":"Building a DiGraphBuilder and forgetting any add_edge calls (nodes are only created via edges); dynamically generating a graph from config where the node list came out empty; calling GraphFlow with an empty builder.","commonSituations":"Config-driven graph construction where a filter accidentally removes all nodes; refactoring graph-building code and dropping the edge additions; early scaffolding code that wires the team before the graph is populated.","solutions":["Ensure at least one builder.add_edge(source_agent, target_agent) call creates a node before GraphFlow(...).","If the graph is generated dynamically, assert non-empty node set before constructing the flow.","Check that set_start_node refers to a node actually created via add_edge."],"exampleFix":"// before\nbuilder = DiGraphBuilder()\nflow = GraphFlow(builder)  # no edges/nodes\n\n// after\nbuilder = DiGraphBuilder()\nbuilder.add_edge(starter, finisher)\nflow = GraphFlow(builder)","handlingStrategy":"validation","validationCode":"if not builder.nodes:\n    raise ValueError(\"Graph is empty: add at least one add_edge(...) before GraphFlow\")\nflow = GraphFlow(participants, graph_builder=builder)","typeGuard":"def graph_has_nodes(builder: DiGraphBuilder) -> bool:\n    return len(builder.nodes) > 0","tryCatchPattern":"try:\n    flow = GraphFlow(participants, graph_builder=builder)\nexcept ValueError as e:\n    if \"Graph has no nodes\" in str(e):\n        # builder was never populated; add edges first\n        ...","preventionTips":["Wire the builder completely (add_edge calls) before constructing GraphFlow.","For config-driven graphs, fail early when the parsed node list is empty.","Include a graph-validation step in CI for generated workflows."],"tags":["graph","validation","configuration"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}