Chat Completions mode: plain-text final answer is never logged — model answers, turn completes, UI silently shows nothing
Summary
In Chat Completions mode, when a model returns its final answer as plain prose (no JSON tool call), the answer is fully generated, the turn completes cleanly, the history is updated, memory extensions still run — but no type="response" log entry is ever created, so the WebUI never displays the answer. The chat silently returns to idle, indistinguishable from a hang. No warning, no exception, no diagnostic trail.
This was observed with a custom preset pointing a glm-5.3 Chat Completions endpoint at a coding-assistant API (z.ai coding plan) that answers conversational requests in plain text instead of emitting the {"tool_name":"response",...} JSON protocol. Any provider/model that answers in prose for simple conversational prompts will trigger this.
Related prior work (not duplicates):
- #1812 (closed) fixed the
return messageshortcut inprocess_llm_result_tools()— that code path no longer exists in v2.10; plain text now always reachesprocess_tools(). But the logging half was never covered for chat mode. - #1729 (open) proposes a
monologue_endfallback for the same family of symptom. This issue provides a root-cause trace and a narrower fix at thehist_add_ai_responsehook that reuses the generating log item (so the response bubbles into the existing stream position).
Reproduction
- Run Agent Zero v2.10 with any Chat Completions mode preset whose model answers a trivial prompt in plain prose (e.g. a coding-assistant endpoint, or any model that ignores the JSON tool protocol for conversational questions).
- Open a new chat, send:
say READY. - Observe:
- the LLM call completes (debug trace:
turn_end response="READY"), process_tools()runs and returns the message,message_loop_endfires, memorize extensions run in thefinally,- the chat goes idle — no response bubble, no warning.
- the LLM call completes (debug trace:
Instrumented trace from a live v2.10 instance (extension hooks on call_chat_model_turn, process_tools, message_loop_end):
turn_end: response_len=5, response_head="READY"
process_tools: message="READY" (plain prose, not a tool request)
process_tools_end: result="READY" (returned cleanly)
message_loop_end: last_response_len=5
→ no response log entry anywhere ✗Root cause
Three logging paths exist for a final answer, and plain prose in Chat Completions mode falls through all of them:
extensions/python/response_stream/_20_live_response.py— only createslog_item_responsewhen it sees aresponsetool request in the stream (vianormalize_tool_request(parsed)). Plain prose is never a tool request, so no entry is created during streaming.tools/response.py(before_execution) — response logging is intentionally disabled:and# don't log here anymore, we have the live_response extension now passafter_executiononly updatesloop_data.params_temporary["log_item_response"]if it already exists — it never creates one.extensions/python/_functions/agent/Agent/hist_add_ai_response/end/_10_log_plain_responses.py— this is exactly the backstop for plain-text answers, but it early-returns unless the call was Responses-API mode:llm_result = call_kwargs.get("llm_result") if getattr(llm_result, "mode", "") != "responses": return
Meanwhile the framework does anticipate plain-text finals — but only for Responses mode: agent.py process_llm_result_tools() treats plain text as a response tool call when llm_result.mode == "responses" (agent.py:1124-1135), and the _10_log_plain_responses backstop covers its logging. Chat Completions mode never got the equivalent pair, so a valid, fully-generated answer disappears silently.
The model is not at fault and neither is the stream: chunk deltas arrive, the monologue completes, hist_add_ai_response runs — only the log entry is missing.
Proposed fix
Minimal, conservative fix: a chat-mode sibling of _10_log_plain_responses at the same hook point (hist_add_ai_response/end), which converts the existing log_item_generating into a finished response entry when the message is plain prose and no response entry exists yet:
# extensions/python/_functions/agent/Agent/hist_add_ai_response/end/_20_log_plain_chat_responses.py
class LogPlainChatResponses(Extension):
def execute(self, data=None, **kwargs): # SYNC — hook point runs via call_extensions_sync
call_kwargs = data.get("kwargs") or {}
llm_result = call_kwargs.get("llm_result")
if getattr(llm_result, "mode", "") == "responses":
return # core _10 already handles Responses mode
message = call_kwargs.get("message") or (data.get("args")[1] if ...)
if not isinstance(message, str) or not message:
return
if extract_tools.extract_tool_request(message) is not None:
return # proper tool call — normal path
if extract_tools.is_misformatted_tool_request(message):
return # repair/warning path stays intact
params = self.agent.loop_data.params_temporary
if "log_item_response" in params or "log_item_generating" not in params:
return
params["log_item_response"] = params["log_item_generating"]
params["log_item_generating"].update(
type="response", heading="", content=message,
finished=True, update_progress="none",
)(Full tested file below.) Notes:
execute()must stay sync —hist_add_ai_responseis a syncdef(agent.py:758) and its/endpoint runscall_extensions_sync, which raisesValueError: Extension ... returned awaitable in sync modefor async extensions. That failure mode itself silently kills every turn after the LLM answered — worth documenting in the extension developer docs.- Never raises (whole body wrapped), so the backstop cannot become a new kill switch.
- Reusing
log_item_generatingkeeps the response attached to the same stream position/branch id the UI already tracks.
Alternative (more conservative, no new core file): extend the gate in the existing core _10_log_plain_responses.py from mode != "responses" to also run for chat mode. Functionally identical; keeps everything in one file.
"""Log plain-text responses in Chat Completions mode."""
import sys, traceback
from typing import Any
from helpers import extract_tools
from helpers.extension import Extension
class LogPlainChatResponses(Extension):
def execute(self, data: dict[str, Any] | None = None, **kwargs):
try:
if not self.agent or not isinstance(data, dict):
return
call_kwargs = data.get("kwargs")
if not isinstance(call_kwargs, dict):
call_kwargs = {}
llm_result = call_kwargs.get("llm_result")
if getattr(llm_result, "mode", "") == "responses":
return # core _10 handles Responses API mode
message = call_kwargs.get("message")
call_args = data.get("args")
if message is None and isinstance(call_args, tuple) and len(call_args) > 1:
message = call_args[1]
if not isinstance(message, str) or not message:
return
if (
extract_tools.extract_tool_request(message) is not None
or extract_tools.is_misformatted_tool_request(message)
):
return
params = getattr(getattr(self.agent, "loop_data", None), "params_temporary", None)
if not isinstance(params, dict) or "log_item_response" in params:
return
log_item = params.get("log_item_generating")
if log_item is None:
return
params["log_item_response"] = log_item
log_item.update(
type="response", heading="", content=message,
finished=True, update_progress="none",
)
except Exception:
try:
traceback.print_exc(file=sys.stderr)
except Exception:
passBefore / after
| Scenario | Before | After |
|---|---|---|
| Chat Completions model returns plain-prose final answer | No response entry; UI silently idle | Response logged & displayed |
Chat Completions model returns proper response tool JSON |
Logged by LiveResponse in-stream |
Unchanged (backstop skips: log_item_response exists) |
| Responses-API plain text | Logged by core _10_log_plain_responses |
Unchanged (mode gate) |
| Misformatted tool request (fenced/concatenated JSON) | Warning + repair path | Unchanged (is_misformatted_tool_request guard) |
| Empty response (reasoning only) | Retry path | Unchanged (empty-message guard) |
Environment
- Agent Zero v2.10 (git tag), Docker deployment
- Custom preset: Chat Completions mode,
api_base=https://api.z.ai/api/coding/paas/v4, model glm-5.3 (coding-assistant persona → plain-prose answers) - Same model via a gateway that emits the JSON protocol works fine — the failure is purely the chat-mode logging gap, not the model
- Fix verified live on three chats (incl. two long-running production chats) after applying the user-space extension above; trace captured with temporary
call_chat_model_turn/process_tools/message_loop_endhooks
Happy to turn this into a PR against development if the approach looks right — the tested extension is ready to drop into extensions/python/_functions/agent/Agent/hist_add_ai_response/end/ with a regression test alongside tests/test_plain_response_logging.py.
Source: agent0ai/agent-zero