Skip to content

Agent Zero AI framework

Preserve Unicode in streamed Responses output

linklitieaeec455e2b6
diff --git a/extensions/python/message_loop_result/_20_loop_control.py b/extensions/python/message_loop_result/_20_loop_control.py
index b3f68fcc3..ff2c45bf2 100644
--- a/extensions/python/message_loop_result/_20_loop_control.py
+++ b/extensions/python/message_loop_result/_20_loop_control.py
@@ -37,7 +37,10 @@ class LoopControl(Extension):
self.agent._remember_llm_result_state(llm_result, assistant_message)
warning_message = self.agent.hist_add_warning(message=warning)
PrintStyle(font_color="orange", padding=True).print(warning)
+ log_content = warning
+ if response:
+ log_content = f"{self.agent.agent_name}: Repeated response detected. Retrying."
self.agent.context.log.log(
- type="warning", content=warning, id=warning_message.id
+ type="warning", content=log_content, id=warning_message.id
)
result_data["skip_default_processing"] = True
diff --git a/helpers/litellm_transport.py b/helpers/litellm_transport.py
index 6a1498b71..8634ff041 100644
--- a/helpers/litellm_transport.py
+++ b/helpers/litellm_transport.py
@@ -540,9 +540,10 @@ class ChatCompletionsTransport:
if not calls:
return ""
if len(calls) == 1:
- return json.dumps(calls[0])
+ return json.dumps(calls[0], ensure_ascii=False)
return json.dumps(
- {"tool_name": "parallel_tool_calls", "tool_args": {"calls": calls}}
+ {"tool_name": "parallel_tool_calls", "tool_args": {"calls": calls}},
+ ensure_ascii=False,
)
@classmethod
@@ -1118,7 +1119,7 @@ class ResponsesTransport:
call = cls.function_call_object(item)
if not call:
return ""
- return json.dumps(call)
+ return json.dumps(call, ensure_ascii=False)
@staticmethod
def function_call_object(item: Any) -> dict[str, Any]:
diff --git a/helpers/litellm_transport.py.dox.md b/helpers/litellm_transport.py.dox.md
index 1a8e20795..a3df0e73a 100644
--- a/helpers/litellm_transport.py.dox.md
+++ b/helpers/litellm_transport.py.dox.md
@@ -34,6 +34,7 @@
- Fall back to Chat Completions when LiteLLM's Responses mock streaming path tries to JSON-decode a real SSE stream before any output.
- Preserve Chat Completions tool calls from both non-streaming responses and streaming deltas as canonical `LLMResult` function-call items.
- Preserve Responses function calls collected from stream events when a terminal completed event omits them.
+- Serialize synthesized Responses function-call JSON with literal Unicode so streamed raw-response logs preserve tool arguments.
- Preserve provider-state metadata when Responses API calls succeed, and fall back to local replay when provider state is unsupported.
- Keep prompt-cache markers only for providers that accept them.
diff --git a/tests/test_message_loop_result.py b/tests/test_message_loop_result.py
index 23d056db9..9ce75487b 100644
--- a/tests/test_message_loop_result.py
+++ b/tests/test_message_loop_result.py
@@ -9,7 +9,11 @@ class FakeAgent:
last_response=last_response,
params_temporary={},
)
- self.context = SimpleNamespace(log=SimpleNamespace(log=lambda **kwargs: None))
+ self.logs = []
+ self.context = SimpleNamespace(
+ log=SimpleNamespace(log=lambda **entry: self.logs.append(entry))
+ )
+ self.agent_name = "A0"
self.response = response
self.reasoning = reasoning
self.warnings = []
@@ -54,6 +58,13 @@ def test_repeat_skips_default_processing():
assert _run(agent)["skip_default_processing"] is True
assert agent.warnings == ["repeat"]
+ assert agent.logs == [
+ {
+ "type": "warning",
+ "content": "A0: Repeated response detected. Retrying.",
+ "id": "warning",
+ }
+ ]
def test_result_with_reasoning_uses_default_processing():
diff --git a/tests/test_stream_tool_early_stop.py b/tests/test_stream_tool_early_stop.py
index 6c26570e4..35356d680 100644
--- a/tests/test_stream_tool_early_stop.py
+++ b/tests/test_stream_tool_early_stop.py
@@ -1715,3 +1715,30 @@ def test_responses_response_parser_groups_parallel_function_calls():
]
},
}
+
+
+def test_responses_stream_parser_preserves_non_ascii_function_call_arguments():
+ parser = litellm_transport.ResponsesEventParser()
+
+ parser.parse(
+ {
+ "type": "response.output_item.added",
+ "output_index": 0,
+ "item": {
+ "type": "function_call",
+ "id": "fc_1",
+ "name": "response",
+ "arguments": "",
+ },
+ }
+ )
+ parsed = parser.parse(
+ {
+ "type": "response.function_call_arguments.done",
+ "item_id": "fc_1",
+ "name": "response",
+ "arguments": '{"text":"привет"}',
+ }
+ )
+
+ assert parsed["response_delta"] == '{"tool_name": "response", "tool_args": {"text": "привет"}}'