Skip to content

A programming framework for agentic AI

allow serialize_to_str to work with non ascii when dumping via json.dumps (#2714)

jtoy129887519d86
diff --git a/autogen/function_utils.py b/autogen/function_utils.py
index dd225fd47..6b9b6f5b1 100644
--- a/autogen/function_utils.py
+++ b/autogen/function_utils.py
@@ -353,4 +353,4 @@ def serialize_to_str(x: Any) -> str:
elif isinstance(x, BaseModel):
return model_dump_json(x)
else:
- return json.dumps(x)
+ return json.dumps(x, ensure_ascii=False)
diff --git a/test/test_function_utils.py b/test/test_function_utils.py
index adddbf32e..0475044b4 100644
--- a/test/test_function_utils.py
+++ b/test/test_function_utils.py
@@ -391,6 +391,10 @@ async def test_load_basemodels_if_needed_async() -> None:
assert actual[1] == "EUR"
+def test_serialize_to_str_with_nonascii() -> None:
+ assert serialize_to_str("中文") == "中文"
+
+
def test_serialize_to_json() -> None:
assert serialize_to_str("abc") == "abc"
assert serialize_to_str(123) == "123"