33from collections import defaultdict
44from collections .abc import Iterable , Iterator , Mapping , Sequence
55from dataclasses import asdict
6- from datetime import datetime , timezone
76from pprint import pformat
87from typing import (
98 Any ,
1716from typing_extensions import TypedDict
1817
1918from langgraph .channels .base import BaseChannel
20- from langgraph .checkpoint .base import Checkpoint , CheckpointMetadata , PendingWrite
19+ from langgraph .checkpoint .base import CheckpointMetadata , PendingWrite
2120from langgraph .constants import (
2221 CONF ,
2322 CONFIG_KEY_CHECKPOINT_NS ,
@@ -92,30 +91,21 @@ class DebugOutputCheckpoint(DebugOutputBase):
9291TASK_NAMESPACE = UUID ("6ba7b831-9dad-11d1-80b4-00c04fd430c8" )
9392
9493
95- def map_debug_tasks (
96- step : int , tasks : Iterable [PregelExecutableTask ]
97- ) -> Iterator [DebugOutputTask ]:
94+ def map_debug_tasks (tasks : Iterable [PregelExecutableTask ]) -> Iterator [DebugOutputTask ]:
9895 """Produce "task" events for stream_mode=debug."""
99- ts = datetime .now (timezone .utc ).isoformat ()
10096 for task in tasks :
10197 if task .config is not None and TAG_HIDDEN in task .config .get ("tags" , []):
10298 continue
10399
104100 yield {
105- "type" : "task" ,
106- "timestamp" : ts ,
107- "step" : step ,
108- "payload" : {
109- "id" : task .id ,
110- "name" : task .name ,
111- "input" : task .input ,
112- "triggers" : task .triggers ,
113- },
101+ "id" : task .id ,
102+ "name" : task .name ,
103+ "input" : task .input ,
104+ "triggers" : task .triggers ,
114105 }
115106
116107
117108def map_debug_task_results (
118- step : int ,
119109 task_tup : tuple [PregelExecutableTask , Sequence [tuple [str , Any ]]],
120110 stream_keys : str | Sequence [str ],
121111) -> Iterator [DebugOutputTaskResult ]:
@@ -125,23 +115,16 @@ def map_debug_task_results(
125115 )
126116 task , writes = task_tup
127117 yield {
128- "type" : "task_result" ,
129- "timestamp" : datetime .now (timezone .utc ).isoformat (),
130- "step" : step ,
131- "payload" : {
132- "id" : task .id ,
133- "name" : task .name ,
134- "error" : next ((w [1 ] for w in writes if w [0 ] == ERROR ), None ),
135- "result" : [
136- w for w in writes if w [0 ] in stream_channels_list or w [0 ] == RETURN
137- ],
138- "interrupts" : [
139- asdict (v )
140- for w in writes
141- if w [0 ] == INTERRUPT
142- for v in (w [1 ] if isinstance (w [1 ], Sequence ) else [w [1 ]])
143- ],
144- },
118+ "id" : task .id ,
119+ "name" : task .name ,
120+ "error" : next ((w [1 ] for w in writes if w [0 ] == ERROR ), None ),
121+ "result" : [w for w in writes if w [0 ] in stream_channels_list or w [0 ] == RETURN ],
122+ "interrupts" : [
123+ asdict (v )
124+ for w in writes
125+ if w [0 ] == INTERRUPT
126+ for v in (w [1 ] if isinstance (w [1 ], Sequence ) else [w [1 ]])
127+ ],
145128 }
146129
147130
@@ -159,12 +142,10 @@ def rm_pregel_keys(config: RunnableConfig | None) -> RunnableConfig | None:
159142
160143
161144def map_debug_checkpoint (
162- step : int ,
163145 config : RunnableConfig ,
164146 channels : Mapping [str , BaseChannel ],
165147 stream_channels : str | Sequence [str ],
166148 metadata : CheckpointMetadata ,
167- checkpoint : Checkpoint ,
168149 tasks : Iterable [PregelExecutableTask ],
169150 pending_writes : list [PendingWrite ],
170151 parent_config : RunnableConfig | None ,
@@ -193,42 +174,35 @@ def map_debug_checkpoint(
193174 }
194175
195176 yield {
196- "type" : "checkpoint" ,
197- "timestamp" : checkpoint ["ts" ],
198- "step" : step ,
199- "payload" : {
200- "config" : rm_pregel_keys (patch_checkpoint_map (config , metadata )),
201- "parent_config" : rm_pregel_keys (
202- patch_checkpoint_map (parent_config , metadata )
203- ),
204- "values" : read_channels (channels , stream_channels ),
205- "metadata" : metadata ,
206- "next" : [t .name for t in tasks ],
207- "tasks" : [
208- {
209- "id" : t .id ,
210- "name" : t .name ,
211- "error" : t .error ,
212- "state" : t .state ,
213- }
214- if t .error
215- else {
216- "id" : t .id ,
217- "name" : t .name ,
218- "result" : t .result ,
219- "interrupts" : tuple (asdict (i ) for i in t .interrupts ),
220- "state" : t .state ,
221- }
222- if t .result
223- else {
224- "id" : t .id ,
225- "name" : t .name ,
226- "interrupts" : tuple (asdict (i ) for i in t .interrupts ),
227- "state" : t .state ,
228- }
229- for t in tasks_w_writes (tasks , pending_writes , task_states , output_keys )
230- ],
231- },
177+ "config" : rm_pregel_keys (patch_checkpoint_map (config , metadata )),
178+ "parent_config" : rm_pregel_keys (patch_checkpoint_map (parent_config , metadata )),
179+ "values" : read_channels (channels , stream_channels ),
180+ "metadata" : metadata ,
181+ "next" : [t .name for t in tasks ],
182+ "tasks" : [
183+ {
184+ "id" : t .id ,
185+ "name" : t .name ,
186+ "error" : t .error ,
187+ "state" : t .state ,
188+ }
189+ if t .error
190+ else {
191+ "id" : t .id ,
192+ "name" : t .name ,
193+ "result" : t .result ,
194+ "interrupts" : tuple (asdict (i ) for i in t .interrupts ),
195+ "state" : t .state ,
196+ }
197+ if t .result
198+ else {
199+ "id" : t .id ,
200+ "name" : t .name ,
201+ "interrupts" : tuple (asdict (i ) for i in t .interrupts ),
202+ "state" : t .state ,
203+ }
204+ for t in tasks_w_writes (tasks , pending_writes , task_states , output_keys )
205+ ],
232206 }
233207
234208
0 commit comments