Agent Zero AI framework
Fix Responses API output and minify user turns
linkliti3db4c4954ea2
diff --git a/helpers/history.py b/helpers/history.pyindex a52263812..c980e8f13 100644--- a/helpers/history.py+++ b/helpers/history.py@@ -808,7 +808,7 @@ def _messages_from_record(record: Record) -> list[Message]:def _json_dumps(obj):- return json.dumps(obj, ensure_ascii=False)+ return json.dumps(obj, ensure_ascii=False, separators=(",", ":"))def _json_loads(obj):diff --git a/helpers/history.py.dox.md b/helpers/history.py.dox.mdindex 59593e253..ac1c2b03f 100644--- a/helpers/history.py.dox.md+++ b/helpers/history.py.dox.md@@ -81,6 +81,7 @@- `clear_responses_provider_state(agent)` removes the active provider continuation IDs after local history rewrites while preserving stored response ID lists for later cleanup.- `Message.from_dict()` normalizes legacy AI Responses metadata through `LLMResult.metadata()` so loaded chats shed transient payloads while unrelated metadata and non-AI tool-result inputs remain intact.- `output_langchain()` removes leading assistant messages after grouping so provider histories always begin with a user turn; the WebUI greeting remains persisted and displayed but is not sent as an orphaned assistant message.+- `_json_dumps()` emits compact JSON (`","`, `":"` separators) for serialized history and generated non-string user-turn content.- Observed side-effect areas: filesystem writes, filesystem deletion, model calls, plugin state, settings/state persistence, secret handling.- Imported dependency areas include: `abc`, `asyncio`, `collections`, `collections.abc`, `enum`, `helpers`, `json`, `langchain_core.messages`, `math`, `plugins._model_config.helpers.model_config`, `typing`, `uuid`.diff --git a/helpers/llm_result.py b/helpers/llm_result.pyindex a39234eab..166c88c2b 100644--- a/helpers/llm_result.py+++ b/helpers/llm_result.py@@ -194,9 +194,10 @@ class LLMResult: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,)def to_dict(self) -> dict[str, Any]:diff --git a/tests/test_responses_architecture.py b/tests/test_responses_architecture.pyindex f344e9ebf..d7843aa4a 100644--- a/tests/test_responses_architecture.py+++ b/tests/test_responses_architecture.py@@ -44,6 +44,22 @@ class _AsyncEventStream:self.closed = True+def test_responses_function_call_text_preserves_non_ascii_tool_args():+ result = LLMResult.from_response(+ {+ "output": [+ {+ "type": "function_call",+ "name": "response",+ "arguments": '{"text":"привет"}',+ }+ ]+ }+ )++ assert result.function_calls_text() == '{"tool_name": "response", "tool_args": {"text": "привет"}}'++def test_llm_result_persists_only_durable_responses_metadata():result = LLMResult.from_response({@@ -105,7 +121,9 @@ def test_history_migrates_legacy_ai_metadata_and_preserves_tool_inputs():"done",metadata={"responses": {"input_items": [tool_item]}},)- restored = history.deserialize_history(hist.serialize(), DummyAgent())+ serialized = hist.serialize()+ assert '"input_items":[{"type":"function_call_output"' in serialized+ restored = history.deserialize_history(serialized, DummyAgent())restored_message = restored.all_messages()[0]assert restored_message.sequence == message.sequence