mirror of
https://github.com/microsoft/autogen.git
synced 2025-12-29 16:09:07 +00:00
parent
796e349cc3
commit
4358dfd5c3
@ -159,7 +159,7 @@ class DiGraph(BaseModel):
|
||||
cycle_edges: List[DiGraphEdge] = []
|
||||
for n in cycle_nodes:
|
||||
cycle_edges.extend(self.nodes[n].edges)
|
||||
if not any(edge.condition is not None for edge in cycle_edges):
|
||||
if all(edge.condition is None and edge.condition_function is None for edge in cycle_edges):
|
||||
raise ValueError(
|
||||
f"Cycle detected without exit condition: {' -> '.join(cycle_nodes + cycle_nodes[:1])}"
|
||||
)
|
||||
|
||||
@ -219,6 +219,18 @@ def test_cycle_detection_with_exit_condition() -> None:
|
||||
)
|
||||
assert graph.has_cycles_with_exit()
|
||||
|
||||
# Use a lambda condition
|
||||
graph_with_lambda = DiGraph(
|
||||
nodes={
|
||||
"A": DiGraphNode(name="A", edges=[DiGraphEdge(target="B")]),
|
||||
"B": DiGraphNode(name="B", edges=[DiGraphEdge(target="C")]),
|
||||
"C": DiGraphNode(
|
||||
name="C", edges=[DiGraphEdge(target="A", condition=lambda msg: "test" in msg.to_model_text())]
|
||||
), # Cycle with lambda
|
||||
}
|
||||
)
|
||||
assert graph_with_lambda.has_cycles_with_exit()
|
||||
|
||||
|
||||
def test_cycle_detection_without_exit_condition() -> None:
|
||||
"""Test that cycle without exit condition raises an error."""
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user