Skip to content

Commit a6580a5

Browse files
authored
fix: add ensure_ascii=False to json.dumps for correct Unicode output (#639)
Set `ensure_ascii=False` in `json.dumps(...)` to allow proper Unicode character output (e.g., Japanese). Without this, non-ASCII characters are escaped (e.g., 日本語 → \u65e5\u672c\u8a9e), which makes logs or exports harder to read.
1 parent c1cb7ce commit a6580a5

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/agents/extensions/models/litellm_model.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ async def get_response(
9898
logger.debug("Received model response")
9999
else:
100100
logger.debug(
101-
f"LLM resp:\n{json.dumps(response.choices[0].message.model_dump(), indent=2)}\n"
101+
f"""LLM resp:\n{
102+
json.dumps(
103+
response.choices[0].message.model_dump(), indent=2, ensure_ascii=False
104+
)
105+
}\n"""
102106
)
103107

104108
if hasattr(response, "usage"):
@@ -269,8 +273,8 @@ async def _fetch_response(
269273
else:
270274
logger.debug(
271275
f"Calling Litellm model: {self.model}\n"
272-
f"{json.dumps(converted_messages, indent=2)}\n"
273-
f"Tools:\n{json.dumps(converted_tools, indent=2)}\n"
276+
f"{json.dumps(converted_messages, indent=2, ensure_ascii=False)}\n"
277+
f"Tools:\n{json.dumps(converted_tools, indent=2, ensure_ascii=False)}\n"
274278
f"Stream: {stream}\n"
275279
f"Tool choice: {tool_choice}\n"
276280
f"Response format: {response_format}\n"

src/agents/models/openai_chatcompletions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async def get_response(
8787
if message is not None:
8888
logger.debug(
8989
"LLM resp:\n%s\n",
90-
json.dumps(message.model_dump(), indent=2),
90+
json.dumps(message.model_dump(), indent=2, ensure_ascii=False),
9191
)
9292
else:
9393
finish_reason = first_choice.finish_reason if first_choice else "-"
@@ -256,8 +256,8 @@ async def _fetch_response(
256256
logger.debug("Calling LLM")
257257
else:
258258
logger.debug(
259-
f"{json.dumps(converted_messages, indent=2)}\n"
260-
f"Tools:\n{json.dumps(converted_tools, indent=2)}\n"
259+
f"{json.dumps(converted_messages, indent=2, ensure_ascii=False)}\n"
260+
f"Tools:\n{json.dumps(converted_tools, indent=2, ensure_ascii=False)}\n"
261261
f"Stream: {stream}\n"
262262
f"Tool choice: {tool_choice}\n"
263263
f"Response format: {response_format}\n"

src/agents/models/openai_responses.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ async def get_response(
9696
else:
9797
logger.debug(
9898
"LLM resp:\n"
99-
f"{json.dumps([x.model_dump() for x in response.output], indent=2)}\n"
99+
f"""{
100+
json.dumps(
101+
[x.model_dump() for x in response.output],
102+
indent=2,
103+
ensure_ascii=False,
104+
)
105+
}\n"""
100106
)
101107

102108
usage = (
@@ -249,8 +255,8 @@ async def _fetch_response(
249255
else:
250256
logger.debug(
251257
f"Calling LLM {self.model} with input:\n"
252-
f"{json.dumps(list_input, indent=2)}\n"
253-
f"Tools:\n{json.dumps(converted_tools.tools, indent=2)}\n"
258+
f"{json.dumps(list_input, indent=2, ensure_ascii=False)}\n"
259+
f"Tools:\n{json.dumps(converted_tools.tools, indent=2, ensure_ascii=False)}\n"
254260
f"Stream: {stream}\n"
255261
f"Tool choice: {tool_choice}\n"
256262
f"Response format: {response_format}\n"

0 commit comments

Comments
 (0)