Skip to content

Commit 90b6805

Browse files
authored
fix(langchain): revert conditional edge from tools to end (#33520) (#33539)
This is causing an issue with one of the middlewares
1 parent 87ad527 commit 90b6805

File tree

4 files changed

+8
-152
lines changed

4 files changed

+8
-152
lines changed

libs/langchain_v1/langchain/agents/factory.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,15 +1225,6 @@ async def amodel_node(state: AgentState, runtime: Runtime[ContextT]) -> dict[str
12251225
graph.add_edge(START, entry_node)
12261226
# add conditional edges only if tools exist
12271227
if tool_node is not None:
1228-
# Only include exit_node in destinations if any tool has return_direct=True
1229-
# or if there are structured output tools
1230-
tools_to_model_destinations = [loop_entry_node]
1231-
if (
1232-
any(tool.return_direct for tool in tool_node.tools_by_name.values())
1233-
or structured_output_tools
1234-
):
1235-
tools_to_model_destinations.append(exit_node)
1236-
12371228
graph.add_conditional_edges(
12381229
"tools",
12391230
_make_tools_to_model_edge(
@@ -1242,7 +1233,7 @@ async def amodel_node(state: AgentState, runtime: Runtime[ContextT]) -> dict[str
12421233
structured_output_tools=structured_output_tools,
12431234
end_destination=exit_node,
12441235
),
1245-
tools_to_model_destinations,
1236+
[loop_entry_node, exit_node],
12461237
)
12471238

12481239
# base destinations are tools and exit_node

libs/langchain_v1/tests/unit_tests/agents/__snapshots__/test_middleware_agent.ambr

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
__start__ --> NoopZero\2ebefore_agent;
2121
model -.-> NoopTwo\2eafter_agent;
2222
model -.-> tools;
23+
tools -.-> NoopTwo\2eafter_agent;
2324
tools -.-> model;
2425
NoopOne\2eafter_agent --> __end__;
2526
classDef default fill:#f2f0ff,line-height:1.2
@@ -342,6 +343,7 @@
342343
__start__ --> NoopSeven\2ebefore_model;
343344
model --> NoopEight\2eafter_model;
344345
tools -.-> NoopSeven\2ebefore_model;
346+
tools -.-> __end__;
345347
classDef default fill:#f2f0ff,line-height:1.2
346348
classDef first fill-opacity:0
347349
classDef last fill:#bfb6fc
@@ -374,6 +376,7 @@
374376
__start__ --> NoopSeven\2ebefore_model;
375377
model --> NoopEight\2eafter_model;
376378
tools -.-> NoopSeven\2ebefore_model;
379+
tools -.-> __end__;
377380
classDef default fill:#f2f0ff,line-height:1.2
378381
classDef first fill-opacity:0
379382
classDef last fill:#bfb6fc
@@ -406,6 +409,7 @@
406409
__start__ --> NoopSeven\2ebefore_model;
407410
model --> NoopEight\2eafter_model;
408411
tools -.-> NoopSeven\2ebefore_model;
412+
tools -.-> __end__;
409413
classDef default fill:#f2f0ff,line-height:1.2
410414
classDef first fill-opacity:0
411415
classDef last fill:#bfb6fc
@@ -438,6 +442,7 @@
438442
__start__ --> NoopSeven\2ebefore_model;
439443
model --> NoopEight\2eafter_model;
440444
tools -.-> NoopSeven\2ebefore_model;
445+
tools -.-> __end__;
441446
classDef default fill:#f2f0ff,line-height:1.2
442447
classDef first fill-opacity:0
443448
classDef last fill:#bfb6fc
@@ -470,6 +475,7 @@
470475
__start__ --> NoopSeven\2ebefore_model;
471476
model --> NoopEight\2eafter_model;
472477
tools -.-> NoopSeven\2ebefore_model;
478+
tools -.-> __end__;
473479
classDef default fill:#f2f0ff,line-height:1.2
474480
classDef first fill-opacity:0
475481
classDef last fill:#bfb6fc
@@ -491,6 +497,7 @@
491497
__start__ --> model;
492498
model -.-> __end__;
493499
model -.-> tools;
500+
tools -.-> __end__;
494501
tools -.-> model;
495502
classDef default fill:#f2f0ff,line-height:1.2
496503
classDef first fill-opacity:0

libs/langchain_v1/tests/unit_tests/agents/__snapshots__/test_return_direct_graph.ambr

Lines changed: 0 additions & 69 deletions
This file was deleted.

libs/langchain_v1/tests/unit_tests/agents/test_return_direct_graph.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)