{"record":{"id":"92f889c241a0cb94","repo":"microsoft/autogen","slug":"node-node-name-has-a-mix-of-conditional-and-un","errorCode":null,"errorMessage":"Node '{node.name}' has a mix of conditional and unconditional edges.","messagePattern":"Node '(.+?)' has a mix of conditional and unconditional edges\\.","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":226,"sourceCode":"        \"\"\"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\n        self._validate_activation_conditions()\n\n        self._has_cycles = self.has_cycles_with_exit()\n\n    def _validate_activation_conditions(self) -> None:\n        \"\"\"Validate that all edges pointing to the same target node have consistent activation_condition values.\n\n        Raises:\n            ValueError: If edges pointing to the same target have different activation_condition values\n        \"\"\"\n        target_activation_conditions: Dict[str, Dict[str, str]] = {}  # target_node -> {activation_group -> condition}\n\n        for node in self.nodes.values():\n            for edge in node.edges:\n                target = edge.target  # The target node this edge points to\n                activation_group = edge.activation_group","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_graph/_digraph_group_chat.py#L208-L244","documentation":"Raised by DiGraph.graph_validate per node when a single node has both conditional edges (with condition= or condition_function=) and unconditional edges. Mixing the two on one node makes branching ambiguous (the unconditional edge always fires, so the conditions can never steer), so validation requires a node's outgoing edges to be either all conditional or all unconditional.","triggerScenarios":"builder.add_edge(a, b) followed by builder.add_edge(a, c, condition=\"x\") — node a mixes both kinds; adding a 'default' fallback edge next to conditional edges; incremental edits that add one conditional edge to a previously unconditional fan-out.","commonSituations":"Trying to express 'if X go to c, otherwise always go to b' — which this API does not support directly; refactoring a router node; copying edge definitions from different examples into one node.","solutions":["Make every outgoing edge of that node conditional, encoding the default branch as condition=\"...\" / condition_function=... returning True when no other branch matches.","Or keep all edges of the node unconditional (single-path) and move the branching to a downstream node.","Name the node from the error message to locate the offending edges quickly."],"exampleFix":"// before\nbuilder.add_edge(router, fast_path)\nbuilder.add_edge(router, slow_path, condition=\"complex task\")  # mixed\n\n// after\nbuilder.add_edge(router, fast_path, condition=\"simple task\")\nbuilder.add_edge(router, slow_path, condition=\"complex task\")","handlingStrategy":"validation","validationCode":"for name, node in builder.nodes.items():\n    conditional = [e for e in node.edges if e.condition is not None or e.condition_function is not None]\n    unconditional = [e for e in node.edges if e.condition is None and e.condition_function is None]\n    if conditional and unconditional:\n        raise ValueError(f\"Node '{name}' mixes conditional and unconditional outgoing edges\")","typeGuard":"def node_edges_are_uniform(node) -> bool:\n    flags = [(e.condition is not None or e.condition_function is not None) for e in node.edges]\n    return all(flags) or not any(flags)","tryCatchPattern":"try:\n    flow = GraphFlow(participants, graph_builder=builder)\nexcept ValueError as e:\n    if \"mix of conditional and unconditional edges\" in str(e):\n        # make all outgoing edges of the named node conditional (encode default as a condition)\n        ...","preventionTips":["Treat every router node as fully conditional; encode the default branch as an explicit condition.","Review a node's outgoing edges as a group when editing a graph.","Add a structural lint pass over builder.nodes in tests."],"tags":["graph","validation","edges","conditions"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}