Skip to content

Commit 9a09ed0

Browse files
fix: don't trace conditional edges and no todos in input state (#33842)
while experimenting w/ todo middleware | Before | After | |--------|-------| | ![Screenshot 2025-11-05 at 1 56 21 PM](https://github.com/user-attachments/assets/63195ae4-8122-4662-8246-0fbc16cb1e22) | ![Screenshot 2025-11-05 at 1 56 03 PM](https://github.com/user-attachments/assets/255e2fa8-e52d-4d1a-949a-33df52ee6668) | | Tracing conditional edges (verbose) | Not tracing conditional edges (cleaner) | | ![Screenshot 2025-11-05 at 1 57 56 PM](https://github.com/user-attachments/assets/449ccfe9-4c21-4c87-8e0e-6e89d7a97611) | ![Screenshot 2025-11-05 at 1 56 58 PM](https://github.com/user-attachments/assets/c5c28d0e-2153-4572-af29-b2528761fec6) | | Todos in input state (cluttered) | No todos in input state (cleaner) |
1 parent 5f27b54 commit 9a09ed0

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

libs/langchain_v1/langchain/agents/factory.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,11 +1268,14 @@ async def amodel_node(state: AgentState, runtime: Runtime[ContextT]) -> dict[str
12681268

12691269
graph.add_conditional_edges(
12701270
"tools",
1271-
_make_tools_to_model_edge(
1272-
tool_node=tool_node,
1273-
model_destination=loop_entry_node,
1274-
structured_output_tools=structured_output_tools,
1275-
end_destination=exit_node,
1271+
RunnableCallable(
1272+
_make_tools_to_model_edge(
1273+
tool_node=tool_node,
1274+
model_destination=loop_entry_node,
1275+
structured_output_tools=structured_output_tools,
1276+
end_destination=exit_node,
1277+
),
1278+
trace=False,
12761279
),
12771280
tools_to_model_destinations,
12781281
)
@@ -1289,19 +1292,25 @@ async def amodel_node(state: AgentState, runtime: Runtime[ContextT]) -> dict[str
12891292

12901293
graph.add_conditional_edges(
12911294
loop_exit_node,
1292-
_make_model_to_tools_edge(
1293-
model_destination=loop_entry_node,
1294-
structured_output_tools=structured_output_tools,
1295-
end_destination=exit_node,
1295+
RunnableCallable(
1296+
_make_model_to_tools_edge(
1297+
model_destination=loop_entry_node,
1298+
structured_output_tools=structured_output_tools,
1299+
end_destination=exit_node,
1300+
),
1301+
trace=False,
12961302
),
12971303
model_to_tools_destinations,
12981304
)
12991305
elif len(structured_output_tools) > 0:
13001306
graph.add_conditional_edges(
13011307
loop_exit_node,
1302-
_make_model_to_model_edge(
1303-
model_destination=loop_entry_node,
1304-
end_destination=exit_node,
1308+
RunnableCallable(
1309+
_make_model_to_model_edge(
1310+
model_destination=loop_entry_node,
1311+
end_destination=exit_node,
1312+
),
1313+
trace=False,
13051314
),
13061315
[loop_entry_node, exit_node],
13071316
)
@@ -1602,7 +1611,7 @@ def jump_edge(state: dict[str, Any]) -> str:
16021611
if "model" in can_jump_to and name != model_destination:
16031612
destinations.append(model_destination)
16041613

1605-
graph.add_conditional_edges(name, jump_edge, destinations)
1614+
graph.add_conditional_edges(name, RunnableCallable(jump_edge, trace=False), destinations)
16061615

16071616
else:
16081617
graph.add_edge(name, default_destination)

libs/langchain_v1/langchain/agents/middleware/todo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
ModelCallResult,
2020
ModelRequest,
2121
ModelResponse,
22+
OmitFromInput,
2223
)
2324
from langchain.tools import InjectedToolCallId
2425

@@ -36,7 +37,7 @@ class Todo(TypedDict):
3637
class PlanningState(AgentState):
3738
"""State schema for the todo middleware."""
3839

39-
todos: NotRequired[list[Todo]]
40+
todos: Annotated[NotRequired[list[Todo]], OmitFromInput]
4041
"""List of todo items for tracking task progress."""
4142

4243

0 commit comments

Comments
 (0)