The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): a persisted /steer row survives the next prompt's alternation repair; typed for history
kshitijk4poor7dc796463d54
diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.pyindex 7fb69803829..7eaa892831b 100644--- a/agent/agent_runtime_helpers.py+++ b/agent/agent_runtime_helpers.py@@ -19,7 +19,7 @@ from hermes_cli.timeouts import get_provider_request_timeoutfrom agent.message_sanitization import (_FULL_ARGS_LOG_BOUND, coalesce_tool_call_id, tool_call_id_variants, tool_result_id_variants)-from agent.prompt_builder import format_steer_marker+from agent.prompt_builder import STEER_DISPLAY_KIND, steer_user_rowfrom agent.tool_dispatch_helpers import _trajectory_normalize_msg, make_tool_result_messagefrom agent.trajectory import convert_scratchpad_to_thinkfrom agent.credential_pool import (@@ -533,6 +533,9 @@ def _merge_consecutive_users(messages: List[Dict]) -> Tuple[List[Dict], int]:# A summary carrier followed by a new user row is a deliberate durable shape after# retry/rewind; never mutate the persisted carrier (sanitizers merge copies later).and split_user_originated_turn(prev)[0] is None+ # A /steer row that ended the previous run is already persisted; merging the next+ # prompt into it would rewrite it in place and re-break replay parity.+ and prev.get("display_kind") != STEER_DISPLAY_KIND# Only merge plain-text content; leave multimodal (list) content alone.and isinstance(prev.get("content", ""), str) and isinstance(msg.get("content", ""), str)):@@ -3180,10 +3183,7 @@ def apply_pending_steer_to_tool_results(agent, messages: list, num_tool_msgs: in# user message (which persists like any other user turn)._requeue_pending_steer(agent, steer_text)return- marker = format_steer_marker(steer_text)- # Append a standalone user message instead of rewriting the persisted- # tool row's content.- messages.append({"role": "user", "content": marker})+ messages.append(steer_user_row(steer_text))_ra().logger.info("Delivered /steer to agent after tool batch (%d chars) as new user message: %s", len(steer_text),steer_text[:120] + ("..." if len(steer_text) > 120 else ""),diff --git a/agent/conversation_compression.py b/agent/conversation_compression.pyindex 12359913edb..87d36ba4061 100644--- a/agent/conversation_compression.py+++ b/agent/conversation_compression.py@@ -1934,8 +1934,8 @@ def _steer_markers() -> Tuple[str, str]:def _message_contains_busy_steer(message: Any) -> bool:"""Return whether *message* carries a busy-steer marker.- Steer follow-ups live as markers inside ``role=tool`` results, so they carry user intent that- ``_is_real_user_message`` alone would miss."""+ Steer follow-ups are now their own ``role=user`` rows (caught by ``_is_real_user_message``); in+ transcripts persisted before that they ride inside ``role=tool`` results, so those still count."""text = _message_text(message)if not text:return Falsediff --git a/agent/prompt_builder.py b/agent/prompt_builder.pyindex a3fe15b316a..77db1c348a1 100644--- a/agent/prompt_builder.py+++ b/agent/prompt_builder.py@@ -13,7 +13,7 @@ import sysimport threadingfrom collections import OrderedDictfrom pathlib import Path-from typing import Optional+from typing import Any, Dict, Optionalfrom hermes_constants import (get_hermes_home, get_skills_dir, is_wsl, reset_hermes_home_override, set_hermes_home_override,@@ -512,10 +512,22 @@ STEER_MARKER_CLOSE = "[/OUT-OF-BAND USER MESSAGE]"def format_steer_marker(steer_text: str) -> str:- """Wrap a mid-turn steer for appending to a tool result (see note above)."""+ """Wrap a mid-turn steer in the self-describing marker (see note above)."""return f"\n\n{STEER_MARKER_OPEN}\n{steer_text}\n{STEER_MARKER_CLOSE}"+STEER_DISPLAY_KIND = "steer"+++def steer_user_row(steer_text: str) -> Dict[str, Any]:+ """The standalone ``role:user`` row a mid-turn /steer is delivered as (after the newest tool+ result). Its own row — never smeared onto the already-persisted tool row, which append-only+ persistence would leave divergent from the live request — and typed so the alternation repair+ never merges the next real prompt into it and history renderers can label it."""+ return {"role": "user", "content": format_steer_marker(steer_text).lstrip(),+ "display_kind": STEER_DISPLAY_KIND}++STEER_CHANNEL_NOTE = (# Only what the marker cannot say about itself: it is the ONLY trusted shape and carries full user authority.# Dieted (#95681, maintainer-directed). History: #40240 added this note when the marker was bare anddiff --git a/agent/turn_iteration_prep.py b/agent/turn_iteration_prep.pyindex 189c0c6b8fd..7116fc6de79 100644--- a/agent/turn_iteration_prep.py+++ b/agent/turn_iteration_prep.py@@ -235,8 +235,8 @@ def _inject_steer_after_newest_tool_result(agent: Any, messages: Any, steer_textfor _si in range(len(messages) - 1, -1, -1):_sm = messages[_si]if isinstance(_sm, dict) and _sm.get("role") == "tool":- from agent.prompt_builder import format_steer_marker- messages.insert(_si + 1, {"role": "user", "content": format_steer_marker(steer_text)})+ from agent.prompt_builder import steer_user_row+ messages.insert(_si + 1, steer_user_row(steer_text))logger.debug("Pre-API-call steer drain: appended user row after tool msg at index %d", _si)return_lock = getattr(agent, "_pending_steer_lock", None)diff --git a/apps/desktop/src/types/hermes.ts b/apps/desktop/src/types/hermes.tsindex 16203d60525..1714cbfd13e 100644--- a/apps/desktop/src/types/hermes.ts+++ b/apps/desktop/src/types/hermes.ts@@ -603,7 +603,7 @@ export interface SessionMessage {reasoning_content?: null | stringreasoning_details?: unknowndisplay_kind?:- 'async_delegation_complete' | 'auto_continue' | 'hidden' | 'model_switch' | 'personality_switch' | string+ 'async_delegation_complete' | 'auto_continue' | 'hidden' | 'model_switch' | 'personality_switch' | 'steer' | string/*** A backend older than this app can still serve this as unparsed JSON text,* so readers must narrow before indexing into it.diff --git a/tests/run_agent/test_steer.py b/tests/run_agent/test_steer.pyindex 144ae4a8115..2ec668378cb 100644--- a/tests/run_agent/test_steer.py+++ b/tests/run_agent/test_steer.py@@ -553,7 +553,22 @@ class TestSteerInjection:# The tool row itself is untouched.assert messages[0]["content"] == "x"- def test_multimodal_content_list_preserved(self):+ def test_persisted_steer_row_is_never_merged_with_the_next_prompt(self):+ """A run that ends right after a steered batch leaves user(steer) as the persisted tail.+ The next real prompt makes two consecutive user rows; the alternation repair must leave+ the steer row byte-identical (append-only persistence cannot follow an in-place merge)."""+ from agent.agent_runtime_helpers import _merge_consecutive_users+ from agent.prompt_builder import steer_user_row++ steer = steer_user_row("focus on error handling")+ before = dict(steer)+ merged, repairs = _merge_consecutive_users([steer, {"role": "user", "content": "next question"}])+ assert steer == before+ assert repairs == 0+ assert [m["role"] for m in merged] == ["user", "user"]+ assert merged[-1]["content"] == "next question"++ def test_multimodal_tool_content_untouched_steer_lands_as_user_row(self):"""Anthropic-style list content on tool results is left untouched —the steer is appended as a standalone user message instead of beingmerged into the content blocks."""diff --git a/tui_gateway/session_history.py b/tui_gateway/session_history.pyindex 1a5cd76fca3..cafa2dafda9 100644--- a/tui_gateway/session_history.py+++ b/tui_gateway/session_history.py@@ -202,6 +202,10 @@ def _history_to_messages(history: list[dict]) -> list[dict]:except (json.JSONDecodeError, TypeError):args = {}tool_call_args[tc_id] = (fn["name"], args)+ if role == "user" and m.get("display_kind") == "steer":+ # Mid-turn /steer: show the user's own words, not the model-facing marker wrapper.+ from agent.conversation_compression import _extract_steer_text_from_message+ content_text = _extract_steer_text_from_message(m) or content_textif role == "tool":tc_name, tc_args = tool_call_args.get(m.get("tool_call_id") or "", (None, None))name = tc_name or m.get("tool_name") or "tool"