@@ -235,7 +235,7 @@ async def _handle_stream_events(self, input: RunAgentInput) -> AsyncGenerator[st
235235 CustomEvent (
236236 type = EventType .CUSTOM ,
237237 name = LangGraphEventTypes .OnInterrupt .value ,
238- value = json . dumps (interrupt .value , default = json_safe_stringify ) if not isinstance ( interrupt . value , str ) else interrupt . value ,
238+ value = dump_json_safe (interrupt .value ) ,
239239 raw_event = interrupt ,
240240 )
241241 )
@@ -311,7 +311,7 @@ async def prepare_stream(self, input: RunAgentInput, agent_state: State, config:
311311 CustomEvent (
312312 type = EventType .CUSTOM ,
313313 name = LangGraphEventTypes .OnInterrupt .value ,
314- value = json . dumps (interrupt .value ) if not isinstance ( interrupt . value , str ) else interrupt . value ,
314+ value = dump_json_safe (interrupt .value ),
315315 raw_event = interrupt ,
316316 )
317317 )
@@ -741,7 +741,7 @@ async def _handle_single_event(self, event: Any, state: State) -> AsyncGenerator
741741 ToolCallArgsEvent (
742742 type = EventType .TOOL_CALL_ARGS ,
743743 tool_call_id = tool_call_output .tool_call_id ,
744- delta = json . dumps (event ["data" ]["input" ]),
744+ delta = dump_json_safe (event ["data" ]["input" ]),
745745 raw_event = event
746746 )
747747 )
@@ -758,7 +758,7 @@ async def _handle_single_event(self, event: Any, state: State) -> AsyncGenerator
758758 type = EventType .TOOL_CALL_RESULT ,
759759 tool_call_id = tool_call_output .tool_call_id ,
760760 message_id = str (uuid .uuid4 ()),
761- content = tool_call_output .content ,
761+ content = dump_json_safe ( tool_call_output .content ) ,
762762 role = "tool"
763763 )
764764 )
@@ -917,3 +917,7 @@ def get_stream_kwargs(
917917 kwargs .update (fork )
918918
919919 return kwargs
920+
921+
922+ def dump_json_safe (value ):
923+ return json .dumps (value , default = json_safe_stringify ) if not isinstance (value , str ) else value
0 commit comments