Agent Zero AI framework
Let Responses text reach the core response dispatcher
Alessandro9bc33fe76180
diff --git a/plugins/_context_doctor/AGENTS.md b/plugins/_context_doctor/AGENTS.mdindex f36a0dd56..1c5d41471 100644--- a/plugins/_context_doctor/AGENTS.md+++ b/plugins/_context_doctor/AGENTS.md@@ -17,7 +17,7 @@- Leave canonical `LLMResult.function_calls` and their accompanying text untouched in either transport. The agent dispatches those calls through the normal tool-policy gate; text repair must not suppress them or reinterpret a textual follow-up as another call.- Repaired and fallback JSON is always minified.-- Nonempty non-tool output becomes `{"thoughts":[raw]}`; XML-like output becomes `{}` only when suppression is enabled.+- Usable Responses output text stays untouched for the core response-tool dispatcher. Recognizable tool intent still enters repair; Chat Completions non-tool output becomes `{"thoughts":[raw]}` and XML-like output becomes `{}` when suppression is enabled.- Blank-line-separated thoughts expand into separate entries after repair when the split strategy is enabled (default on). This rewrites model-authored thoughts for every repaired turn by design, not only the raw-text fallback branch.- `_select_value` returns only repaired tool calls or model-authored partial responses; `transform_response` wraps otherwise-raw output as thoughts afterward. `looks_like_tool_call` rejects that synthesized wrapper, so it reaches the fallback branch. Repaired output is usable only with a non-empty thoughts list, headline/tool name string, or tool-args dict.- A raw-text fallback conversion must emit a `fw.msg_thoughts_fallback.md` history warning and a separate `fw.msg_thoughts_fallback_response.md` user notice, refresh the generating log and response item with the transformed thoughts JSON, and set `skip_default_processing` so the retry advances the unusable-response counter.diff --git a/plugins/_context_doctor/extensions/python/message_loop_result/_10_context_doctor.py b/plugins/_context_doctor/extensions/python/message_loop_result/_10_context_doctor.pyindex 6c1f989da..5b7467ff9 100644--- a/plugins/_context_doctor/extensions/python/message_loop_result/_10_context_doctor.py+++ b/plugins/_context_doctor/extensions/python/message_loop_result/_10_context_doctor.py@@ -5,6 +5,7 @@ from __future__ import annotationsimport jsonfrom typing import Any, override+from helpers import extract_toolsfrom helpers.extension import Extensionfrom helpers.plugins import get_plugin_configfrom helpers.print_style import PrintStyle@@ -37,10 +38,17 @@ class ContextDoctor(Extension):suppress_xml=config.get("suppress_xml", True),split_thoughts=config.get("split_thoughts", True),)+ is_tool_call = looks_like_tool_call(response, transformed)+ if (+ getattr(llm_result, "mode", None) == "responses"+ and not is_tool_call+ and not extract_tools.is_misformatted_tool_request(response)+ ):+ return # Core dispatches Responses output text through the response tool.llm_result.response = transformed# Treat as raw-text fallback when no usable tool call was extracted- if not looks_like_tool_call(response, transformed):+ if not is_tool_call:# Manually add ai response and warningslog_item = self.agent.loop_data.params_temporary.get("log_item_generating")self.agent.hist_add_ai_response(diff --git a/plugins/_context_doctor/tests/test_context_doctor.py b/plugins/_context_doctor/tests/test_context_doctor.pyindex 8626ecf0b..d01ae0b08 100644--- a/plugins/_context_doctor/tests/test_context_doctor.py+++ b/plugins/_context_doctor/tests/test_context_doctor.py@@ -214,12 +214,37 @@ async def test_extension_leaves_native_calls_and_accompanying_text_intact(monkeyassert agent._execute_tool_request.call_args.kwargs["tool_name"] == "code_execution_tool"-def test_extension_replaces_result_refreshes_log_and_response_item(monkeypatch):[email protected]("text", ["Done.", "First paragraph.\n\nSecond paragraph.", "<p>Done.</p>"])+async def test_responses_text_reaches_core_response_dispatch(monkeypatch, text):+ monkeypatch.setattr(+ "plugins._context_doctor.extensions.python.message_loop_result._10_context_doctor.get_plugin_config",+ lambda *args, **kwargs: {},+ )+ result = LLMResult.from_response({"id": "resp_text", "output_text": text})+ before = result.to_dict()+ agent = SimpleNamespace(+ _log_response_builtin_items=AsyncMock(),+ _execute_tool_request=AsyncMock(return_value="finished"),+ )+ data = {"llm_result": result}+ ContextDoctor(agent).execute(data)+ assert result.to_dict() == before+ assert not data.get("skip_default_processing")+ assert await Agent.process_llm_result_tools(agent, result) == "finished"+ agent._execute_tool_request.assert_awaited_once_with(+ tool_name="response", tool_args={"text": text}, message=text,+ )++[email protected]("mode", ["responses", "chat_completions"])+def test_extension_replaces_result_refreshes_log_and_response_item(monkeypatch, mode):monkeypatch.setattr("plugins._context_doctor.extensions.python.message_loop_result._10_context_doctor.get_plugin_config",lambda *args, **kwargs: {"suppress_xml": True, "update_log": False},)llm_result = SimpleNamespace(+ mode=mode,response='{"tool_name":"response","tool_args":{"text":"ok",},}')log_item = SimpleNamespace(@@ -306,7 +331,7 @@ def test_extension_handles_raw_text_fallback_with_warning_and_skip(monkeypatch):hist_add_ai_response=lambda message, **kwargs: ai_responses.append(message) or SimpleNamespace(id="ai"),hist_add_warning=lambda message: warnings.append(message) or SimpleNamespace(id="warning"),)- llm_result = SimpleNamespace(response="Hello there…")+ llm_result = LLMResult.from_chat(response="Hello there…")result_data = {"llm_result": llm_result}ContextDoctor(agent).execute(result_data)