Skip to content

Commit 5c1b8a1

Browse files
committed
get latest langgraph fixes from main
1 parent 88b0b90 commit 5c1b8a1

File tree

4 files changed

+135
-30
lines changed

4 files changed

+135
-30
lines changed

integrations/langgraph/python/ag_ui_langgraph/utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import re
3+
from enum import Enum
34
from typing import List, Any, Dict, Union
45
from dataclasses import is_dataclass, asdict
56
from datetime import date, datetime
@@ -302,6 +303,9 @@ def json_safe_stringify(o):
302303
return o.isoformat()
303304
return str(o) # last resort
304305

306+
def is_json_primitive(value: Any) -> bool:
307+
return isinstance(value, (str, int, float, bool)) or value is None
308+
305309
def make_json_safe(value: Any) -> Any:
306310
"""
307311
Recursively convert a value into a JSON-serializable structure.
@@ -333,8 +337,18 @@ def make_json_safe(value: Any) -> Any:
333337
if isinstance(value, (list, tuple)):
334338
return [make_json_safe(sub_value) for sub_value in value]
335339

340+
if isinstance(value, Enum):
341+
enum_value = value.value
342+
if is_json_primitive(enum_value):
343+
return enum_value
344+
return {
345+
"__type__": type(value).__name__,
346+
"name": value.name,
347+
"value": make_json_safe(enum_value),
348+
}
349+
336350
# Already JSON safe
337-
if isinstance(value, (str, int, float, bool)) or value is None:
351+
if is_json_primitive(value):
338352
return value
339353

340354
# Arbitrary object: try __dict__ first, fallback to repr

0 commit comments

Comments
 (0)