mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-31 12:19:58 +02:00
Merge pull request #1894 from langchain-ai/dqbd/xray-bool
fix(graph): xray=True should be distinct from xray=1
This commit is contained in:
@@ -561,7 +561,11 @@ class CompiledGraph(Pregel):
|
||||
subgraph = (
|
||||
subgraphs[key].get_graph(
|
||||
config=config,
|
||||
xray=xray - 1 if isinstance(xray, int) and xray > 0 else xray,
|
||||
xray=xray - 1
|
||||
if isinstance(xray, int)
|
||||
and not isinstance(xray, bool)
|
||||
and xray > 0
|
||||
else xray,
|
||||
)
|
||||
if key in subgraphs
|
||||
else node.get_graph(config=config)
|
||||
|
||||
@@ -5148,6 +5148,42 @@
|
||||
|
||||
'''
|
||||
# ---
|
||||
# name: test_xray_bool
|
||||
'''
|
||||
%%{init: {'flowchart': {'curve': 'linear'}}}%%
|
||||
graph TD;
|
||||
__start__([<p>__start__</p>]):::first
|
||||
gp_one(gp_one)
|
||||
gp_two___start__(<p>__start__</p>)
|
||||
gp_two_p_one(p_one)
|
||||
gp_two_p_two___start__(<p>__start__</p>)
|
||||
gp_two_p_two_c_one(c_one)
|
||||
gp_two_p_two_c_two(c_two)
|
||||
gp_two_p_two___end__(<p>__end__</p>)
|
||||
gp_two___end__(<p>__end__</p>)
|
||||
__end__([<p>__end__</p>]):::last
|
||||
__start__ --> gp_one;
|
||||
gp_two___end__ --> gp_one;
|
||||
gp_one -. 0 .-> gp_two___start__;
|
||||
gp_one -. 1 .-> __end__;
|
||||
subgraph gp_two
|
||||
gp_two___start__ --> gp_two_p_one;
|
||||
gp_two_p_two___end__ --> gp_two_p_one;
|
||||
gp_two_p_one -. 0 .-> gp_two_p_two___start__;
|
||||
gp_two_p_one -. 1 .-> gp_two___end__;
|
||||
subgraph p_two
|
||||
gp_two_p_two___start__ --> gp_two_p_two_c_one;
|
||||
gp_two_p_two_c_two --> gp_two_p_two_c_one;
|
||||
gp_two_p_two_c_one -. 0 .-> gp_two_p_two_c_two;
|
||||
gp_two_p_two_c_one -. 1 .-> gp_two_p_two___end__;
|
||||
end
|
||||
end
|
||||
classDef default fill:#f2f0ff,line-height:1.2
|
||||
classDef first fill-opacity:0
|
||||
classDef last fill:#bfb6fc
|
||||
|
||||
'''
|
||||
# ---
|
||||
# name: test_xray_issue
|
||||
'''
|
||||
%%{init: {'flowchart': {'curve': 'linear'}}}%%
|
||||
|
||||
@@ -11358,6 +11358,51 @@ def test_xray_issue(snapshot: SnapshotAssertion) -> None:
|
||||
assert app.get_graph(xray=True).draw_mermaid() == snapshot
|
||||
|
||||
|
||||
def test_xray_bool(snapshot: SnapshotAssertion) -> None:
|
||||
class State(TypedDict):
|
||||
messages: Annotated[list, add_messages]
|
||||
|
||||
def node(name):
|
||||
def _node(state: State):
|
||||
return {"messages": [("human", f"entered {name} node")]}
|
||||
|
||||
return _node
|
||||
|
||||
grand_parent = StateGraph(State)
|
||||
|
||||
child = StateGraph(State)
|
||||
|
||||
child.add_node("c_one", node("c_one"))
|
||||
child.add_node("c_two", node("c_two"))
|
||||
|
||||
child.add_edge("__start__", "c_one")
|
||||
child.add_edge("c_two", "c_one")
|
||||
|
||||
child.add_conditional_edges(
|
||||
"c_one", lambda x: str(randrange(0, 2)), {"0": "c_two", "1": "__end__"}
|
||||
)
|
||||
|
||||
parent = StateGraph(State)
|
||||
parent.add_node("p_one", node("p_one"))
|
||||
parent.add_node("p_two", child.compile())
|
||||
parent.add_edge("__start__", "p_one")
|
||||
parent.add_edge("p_two", "p_one")
|
||||
parent.add_conditional_edges(
|
||||
"p_one", lambda x: str(randrange(0, 2)), {"0": "p_two", "1": "__end__"}
|
||||
)
|
||||
|
||||
grand_parent.add_node("gp_one", node("gp_one"))
|
||||
grand_parent.add_node("gp_two", parent.compile())
|
||||
grand_parent.add_edge("__start__", "gp_one")
|
||||
grand_parent.add_edge("gp_two", "gp_one")
|
||||
grand_parent.add_conditional_edges(
|
||||
"gp_one", lambda x: str(randrange(0, 2)), {"0": "gp_two", "1": "__end__"}
|
||||
)
|
||||
|
||||
app = grand_parent.compile()
|
||||
assert app.get_graph(xray=True).draw_mermaid() == snapshot
|
||||
|
||||
|
||||
def test_subgraph_retries():
|
||||
class State(TypedDict):
|
||||
count: int
|
||||
|
||||
Reference in New Issue
Block a user