Skip to content

The agent that grows with you

fix(onboarding): set_theme settling a beat tells the model the next step

alt-glitch6bcc2d40532c
diff --git a/agent/onboarding_flow.py b/agent/onboarding_flow.py
index cd903d451e8..00277d9e924 100644
--- a/agent/onboarding_flow.py
+++ b/agent/onboarding_flow.py
@@ -351,9 +351,14 @@ def _applied_beats(event: Applied) -> list[tuple[str, dict]]:
def _applied(record: dict, event: Applied, facts: Facts, now: float) -> Step:
+ """The reminder names the last beat this result newly settled, so the model moves on instead of
+ recording it again with setup_beat. ``after_<beat>``, not ``Beat.after``: the tour already started."""
+ settled = ""
for beat, patch in _applied_beats(event):
+ if record["beats"][beat] != DONE:
+ settled = beat
_settle(record, beat, patch)
- return Step(record, {})
+ return Step(record, {}, f"after_{settled}" if settled else "")
_HANDLERS: dict[type, Callable[[dict, Any, Facts, float], Step]] = {
diff --git a/agent/onboarding_record.py b/agent/onboarding_record.py
index 092e55c7e2f..16d7ee5e9ec 100644
--- a/agent/onboarding_record.py
+++ b/agent/onboarding_record.py
@@ -17,6 +17,7 @@ from typing import Any
from agent.onboarding_flow import (
Applied, Event, Facts, Step, applies_to, apply, expire, is_active, new_record,
)
+from agent.onboarding_text import reminder
logger = logging.getLogger(__name__)
@@ -113,16 +114,21 @@ def active_session_id(db) -> str | None:
return next(iter(open_session_ids(db)), None)
-def observe_tool_result(agent, name: str, args: Mapping[str, Any], result: Any) -> None:
+def observe_tool_result(agent, name: str, args: Mapping[str, Any], result: Any) -> Any:
"""Settle a beat from a general tool's result (``set_theme``, ``manage_connections`` display,
``gui_tour``). Runs for every tool result; only an onboarding chat (one whose agent carries
- ``setup_beat``) reads its record."""
+ ``setup_beat``) reads its record. Returns *result*, with the next-step reminder added when it
+ settled a beat."""
if not applies_to(name) or "setup_beat" not in (getattr(agent, "valid_tool_names", None) or ()):
- return
+ return result
db, session_id = getattr(agent, "_session_db", None), getattr(agent, "session_id", "") or ""
try:
parsed = json.loads(result) if isinstance(result, str) else result
if isinstance(parsed, dict) and load(db, session_id) is not None:
- advance(db, session_id, Applied(name, dict(args or {}), parsed))
+ step = advance(db, session_id, Applied(name, dict(args or {}), parsed))
+ text = reminder(step.reminder, step.record, Facts.from_stored(step.record["facts"]))
+ if text and isinstance(result, str):
+ return json.dumps({**parsed, "reminder": text}, ensure_ascii=False)
except Exception:
logger.warning("onboarding: %s result did not update the run record", name, exc_info=True)
+ return result
diff --git a/agent/tool_executor.py b/agent/tool_executor.py
index 556e01069e7..69f9c962cc3 100644
--- a/agent/tool_executor.py
+++ b/agent/tool_executor.py
@@ -1088,7 +1088,7 @@ def _commit_tool_result(
observe_tool_outcome(agent, function_name, is_error)
if not (blocked or is_error):
- observe_onboarding_result(agent, function_name, function_args, function_result)
+ function_result = observe_onboarding_result(agent, function_name, function_args, function_result)
if observed:
if not blocked:
function_result = agent._append_guardrail_observation(
diff --git a/tests/agent/test_onboarding_flow.py b/tests/agent/test_onboarding_flow.py
index 45d1358dc35..1ea89858368 100644
--- a/tests/agent/test_onboarding_flow.py
+++ b/tests/agent/test_onboarding_flow.py
@@ -105,6 +105,21 @@ def test_run_hrs0_typed_answer_is_applied_and_never_reshows_the_card():
assert next_beat(applied.record) == "connectors"
+def test_set_theme_settling_the_layout_beat_tells_the_model_the_next_beat():
+ """Without a reminder the model recorded the applied layout with setup_beat and was refused."""
+ facts = MACHINES["mac"]
+ steps = run(facts, Shown("name"), Answered("name", {"name": "Sid"}), Shown("theme"),
+ Answered("theme", {"accent": "Ultraviolet"}), Shown("layout"), Said("layout", "basic"),
+ Applied("set_theme", {"layout": "sidebar-left"}, {"success": True, "applied": {"layout": "sidebar-left"}}),
+ Applied("set_theme", {"layout": "terminal-deck"}, {"success": True, "applied": {"layout": "terminal-deck"}}))
+
+ settled, again = steps[-2], steps[-1]
+ assert settled.reminder == "after_layout"
+ text = reminder(settled.reminder, settled.record, facts)
+ assert text.startswith("Layout Basic is on.") and 'setup_beat(beat="next") shows the connectors card' in text
+ assert again.reminder == ""
+
+
def test_run_hrs0_off_script_questions_keep_one_card_and_continue_settles_it():
"""hrs0: each off-script question re-rendered the apps cards (four open copies), and a typed
"continue" left the beat shown. Bringing a card back is a new Shown of the same beat; a value