Agent Zero AI framework
Own Responses-API state advancement in hist_add_ai_response
linkliti4634070e95a8
diff --git a/AGENTS.md b/AGENTS.mdindex 4b0545add..9a790fff9 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -15,6 +15,7 @@## Root Ownership- `agent.py` owns `Agent`, `AgentContext`, and loop data.+- `Agent.hist_add_ai_response` owns Responses-API state advancement: it calls `_remember_llm_result_state` internally and requires an `LLMResult` (empty for non-LLM turns like greetings or intervention progress). Callers must not invoke `_remember_llm_result_state` manually.- `initialize.py` owns framework initialization.- `models.py` owns model-provider configuration and LiteLLM integration.- `run_ui.py` is the WebUI entry point.diff --git a/agent.py b/agent.pyindex fa5308c88..e4f00ed6b 100644--- a/agent.py+++ b/agent.py@@ -532,7 +532,6 @@ class Agent:id=log_item.id if log_item else "",llm_result=llm_result,)- self._remember_llm_result_state(llm_result, assistant_message)tools_result = await self.process_llm_result_tools(llm_result)if tools_result: # final response of message loop availablereturn tools_result # break the execution if the task is done@@ -771,16 +770,18 @@ class Agent:@extension.extensibledef hist_add_ai_response(- self, message: str, id: str = "", llm_result: LLMResult | None = None+ self, message: str, llm_result: LLMResult, id: str = ""):self.loop_data.last_response = messagecontent = self.parse_prompt("fw.ai_response.md", message=message)- return self.hist_add_message(+ msg = self.hist_add_message(True,content=content,id=id,metadata=metadata_from_llm_result(llm_result),)+ self._remember_llm_result_state(llm_result, msg)+ return msg@extension.extensibledef hist_add_warning(self, message: history.MessageContent, id: str = ""):@@ -1098,7 +1099,7 @@ class Agent:self.hist_add_tool_result(last_tool.name, tool_progress)last_tool.set_progress(None)if progress.strip():- self.hist_add_ai_response(progress)+ self.hist_add_ai_response(progress, llm_result=LLMResult())# append the intervention messageself.hist_add_user_message(msg, intervention=True)raise InterventionException(msg)diff --git a/extensions/python/agent_init/AGENTS.md b/extensions/python/agent_init/AGENTS.mdindex c8c64d17b..7bf26fd03 100644--- a/extensions/python/agent_init/AGENTS.md+++ b/extensions/python/agent_init/AGENTS.md@@ -14,6 +14,7 @@- Preserve ordering between initial message creation and profile settings loading.- Keep a placeholder user turn (`fw.initial_user_message.md`) ahead of the AI greeting (`fw.initial_message.md`) so `output_langchain` never pops the greeting as a leading `AIMessage`; do not remove either prompt without replacing the turn-order guarantee.- Minify the initial AI message JSON before storage; preserve raw text as the displayed greeting when JSON parsing fails.+- `_10_initial_message.py` passes an empty `LLMResult()` to `hist_add_ai_response` so the Responses-API state seam runs uniformly; the empty result carries no `response_id`, so state advancement is a no-op for the greeting turn.## Work Guidancediff --git a/extensions/python/agent_init/_10_initial_message.py b/extensions/python/agent_init/_10_initial_message.pyindex a017db2dc..5d1a2bcec 100644--- a/extensions/python/agent_init/_10_initial_message.py+++ b/extensions/python/agent_init/_10_initial_message.py@@ -1,6 +1,7 @@import jsonfrom agent import LoopData, UserMessagefrom helpers.extension import Extension+from helpers.llm_result import LLMResultclass InitialMessage(Extension):@@ -40,7 +41,7 @@ class InitialMessage(Extension):self.agent.loop_data = LoopData(user_message=None)# Add the message to history as an AI response- msg = self.agent.hist_add_ai_response(initial_message)+ msg = self.agent.hist_add_ai_response(initial_message, llm_result=LLMResult())# Add to log (green bubble) for immediate UI displayself.agent.context.log.log(diff --git a/extensions/python/message_loop_result/AGENTS.md b/extensions/python/message_loop_result/AGENTS.mdindex f87835d35..f88bbef8e 100644--- a/extensions/python/message_loop_result/AGENTS.md+++ b/extensions/python/message_loop_result/AGENTS.md@@ -9,7 +9,7 @@- Extensions receive mutable `result_data` with `llm_result` and may set `skip_default_processing` after fully handling the turn.- `_20_empty_response.py` retries fully empty turns (no response and no reasoning): count them toward the unusable-response limit without adding a warning to model history, and use `fw.msg_empty_response.md` for agent-prefixed UI warning text only.- `_20_empty_response.py` retries reasoning-only turns: add an agent-facing `fw.msg_reasoning_only.md` history warning with a separate `fw.msg_reasoning_only_response.md` user notice, and count them through the stop-unusable-response-loop extension.-- `_30_repeat_response.py` retries response content that exactly matches `loop_data.last_response`, regardless of reasoning, using `fw.msg_repeat.md` for history and `fw.msg_repeat_response.md` for the agent-prefixed UI warning text.+- `_30_repeat_response.py` retries response content that exactly matches `loop_data.last_response`, regardless of reasoning, using `fw.msg_repeat.md` for history and `fw.msg_repeat_response.md` for the agent-prefixed UI warning text. State advancement is owned by `hist_add_ai_response`; do not call `_remember_llm_result_state` manually.## Local Contractsdiff --git a/extensions/python/message_loop_result/_30_repeat_response.py b/extensions/python/message_loop_result/_30_repeat_response.pyindex 45457ff82..4b4e09ba7 100644--- a/extensions/python/message_loop_result/_30_repeat_response.py+++ b/extensions/python/message_loop_result/_30_repeat_response.py@@ -27,7 +27,6 @@ class RepeatResponse(Extension):id=log_item.id if log_item else "",llm_result=llm_result,)- 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)self.agent.context.log.log(diff --git a/plugins/_context_doctor/AGENTS.md b/plugins/_context_doctor/AGENTS.mdindex b55a331b8..d2624c457 100644--- a/plugins/_context_doctor/AGENTS.md+++ b/plugins/_context_doctor/AGENTS.md@@ -19,6 +19,7 @@- Nonempty non-tool output becomes `{"thoughts":[raw]}`; XML-like output becomes `{}` only when suppression is enabled.- Blank-line-separated thoughts expand into separate entries after repair when the split strategy is enabled (default on).- 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.+- The fallback passes the repaired `llm_result` to `hist_add_ai_response`, which owns Responses-API state advancement (`_remember_llm_result_state`); do not call the state method directly. The fallback turn's `response_id` is recorded so the next turn's `previous_response_id` chain stays intact.- The fallback warning is counted by the core stop-unusable-response loop alongside `fw.msg_misformat.md`, `fw.msg_repeat.md`, `fw.msg_empty_response.md`, and `fw.msg_reasoning_only.md`.- Log kvps retain streamed `reasoning` and `thoughts`, then add transformed output; `update_log` controls only View Details content.- A repaired `response` tool call refreshes the response log item when streaming did not create it.