Skip to content

The agent that grows with you

fix(onboarding): a closed apps or plugins card reports what is connected or installed

alt-glitch8af55c1f7548
diff --git a/agent/onboarding_flow.py b/agent/onboarding_flow.py
index 9517da42a19..b4488a18260 100644
--- a/agent/onboarding_flow.py
+++ b/agent/onboarding_flow.py
@@ -69,26 +69,34 @@ class Answered:
answer: Mapping[str, Any]
+# ``present`` on the events below: the beat's picks as this machine has them now (the apps connected,
+# the plugins installed), so a card closed without its own answer still reports them.
+
+
@dataclass(frozen=True)
class Said:
beat: str
text: str
+ present: Any = None
@dataclass(frozen=True)
class TimedOut:
beat: str
+ present: Any = None
@dataclass(frozen=True)
class Recorded:
beat: str
value: str
+ present: Any = None
@dataclass(frozen=True)
class Skipped:
beat: str
+ present: Any = None
@dataclass(frozen=True)
@@ -227,7 +235,8 @@ def _shown(record: dict, event: Shown, facts: Facts, now: float) -> Step:
record["beats"][event.beat] = SKIPPED
return Step(record, {"beat": event.beat, "skipped": True, "next": _next_field(record)}, "moved_on")
if event.beat == "build" and (error := _build_picks_error(record, event, facts)):
- return Step(record, {"beat": "build", "error": error})
+ # No ``beat``: no card was shown, so the transcript draws nothing for this refusal.
+ return Step(record, {"error": error})
# A later card on screen means the user moved on from an earlier card left open.
for earlier in BEAT_IDS[:BEAT_IDS.index(event.beat)]:
if record["beats"][earlier] == SHOWN:
@@ -274,14 +283,21 @@ def _answered(record: dict, event: Answered, facts: Facts, now: float) -> Step:
BEAT_BY_ID[event.beat].after(record["picks"]))
+def _note_present(record: dict, event: Said | TimedOut | Recorded | Skipped) -> dict:
+ """Record the beat's picks as the machine has them now; returns them for the result."""
+ present = {key: value for key, value in (event.present or {}).items() if key in BEAT_BY_ID[event.beat].picks}
+ record["picks"].update(present)
+ return present
+
+
def _said(record: dict, event: Said, facts: Facts, now: float) -> Step:
record["waiting"] = None
- return Step(record, {"beat": event.beat, "said": event.text}, "said")
+ return Step(record, {"beat": event.beat, "said": event.text, **_note_present(record, event)}, "said")
def _timed_out(record: dict, event: TimedOut, facts: Facts, now: float) -> Step:
record["waiting"] = None
- return Step(record, {"beat": event.beat, "timed_out": True}, "timed_out")
+ return Step(record, {"beat": event.beat, "timed_out": True, **_note_present(record, event)}, "timed_out")
# Beats a general tool applies; their result settles the beat, so a value given in words would only
@@ -299,12 +315,14 @@ def _recorded(record: dict, event: Recorded, facts: Facts, now: float) -> Step:
return Step(record, {"error": f"value for {event.beat} must be one of: {', '.join(accepted)}.",
"next": _next_field(record)})
_settle(record, event.beat, {beat.value: event.value} if beat.value else {})
- return Step(record, {"recorded": event.beat, "next": _next_field(record)}, beat.after(record["picks"]))
+ present = _note_present(record, event)
+ return Step(record, {"recorded": event.beat, **present, "next": _next_field(record)}, beat.after(record["picks"]))
def _skipped(record: dict, event: Skipped, facts: Facts, now: float) -> Step:
record["beats"][event.beat] = SKIPPED
- return Step(record, {"recorded": event.beat, "skipped": True, "next": _next_field(record)}, "moved_on")
+ present = _note_present(record, event)
+ return Step(record, {"recorded": event.beat, "skipped": True, **present, "next": _next_field(record)}, "moved_on")
def _end(record: dict, event: End, facts: Facts, now: float) -> Step:
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.ts
index aae5542c7bb..ccbf56f4f29 100644
--- a/apps/shared/src/gateway-contract.generated.ts
+++ b/apps/shared/src/gateway-contract.generated.ts
@@ -4555,11 +4555,12 @@ export interface SetupChooseResult {
label?: string | string[] | null
said?: string | null
}
-/** ``card`` is the beat's data (``agent/onboarding_flow.py::BEATS``): name, theme, connectors and plugins have their own shape; layout, tour and build carry ``options``. */
+/** ``card`` is the beat's data (``agent/onboarding_flow.py::BEATS``): name, theme, connectors and plugins have their own shape; layout, tour and build carry ``options``. ``tool_call_id`` is the setup_beat call the card belongs to: only that transcript row draws it. */
export interface SetupBeatRequestParams {
session_id: string
beat: SetupBeat
question?: string | null
+ tool_call_id?: string | null
card: SetupNameCard | SetupThemeCard | SetupOptionsCard | SetupConnectorsCard | SetupPluginsCard
}
export type SetupBeat = 'name' | 'theme' | 'layout' | 'connectors' | 'plugins' | 'tour' | 'build'
diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.json
index 40b4649cac7..2b9151a0824 100644
--- a/apps/shared/src/gateway-contract.openrpc.json
+++ b/apps/shared/src/gateway-contract.openrpc.json
@@ -33504,7 +33504,7 @@
},
"SetupBeatRequestParams": {
"additionalProperties": false,
- "description": "``card`` is the beat's data (``agent/onboarding_flow.py::BEATS``): name, theme, connectors and\nplugins have their own shape; layout, tour and build carry ``options``.",
+ "description": "``card`` is the beat's data (``agent/onboarding_flow.py::BEATS``): name, theme, connectors and\nplugins have their own shape; layout, tour and build carry ``options``. ``tool_call_id`` is the\nsetup_beat call the card belongs to: only that transcript row draws it.",
"properties": {
"session_id": {
"title": "Session Id",
@@ -33525,6 +33525,18 @@
"default": null,
"title": "Question"
},
+ "tool_call_id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "title": "Tool Call Id"
+ },
"card": {
"anyOf": [
{
diff --git a/tests/tools/test_setup_beat_tool.py b/tests/tools/test_setup_beat_tool.py
index c99e39dd90b..91112be08c6 100644
--- a/tests/tools/test_setup_beat_tool.py
+++ b/tests/tools/test_setup_beat_tool.py
@@ -28,6 +28,16 @@ def db(tmp_path, monkeypatch):
store.close()
[email protected](autouse=True)
+def machine(monkeypatch):
+ """What this machine has connected and installed right now, read when a card closes without its answer."""
+ present = {"connected": ["slack"], "installed": ["blender"]}
+ monkeypatch.setattr("tools.setup_beat_tool._PRESENT", {
+ "connectors": lambda: {"connected": present["connected"]},
+ "plugins": lambda: {"installed": present["installed"]}})
+ return present
+
+
@pytest.fixture
def desktop():
"""A card answerer: replies come off a queue; every payload it was shown is kept."""
@@ -50,7 +60,8 @@ def test_a_card_answer_settles_the_beat_and_names_the_next(db, desktop):
result = call(db, desktop, beat="theme", question="Pick one.")
- assert desktop.shown == [{"beat": "theme", "question": "Pick one.", "card": {"picker": "accent"}}]
+ assert desktop.shown == [{"beat": "theme", "question": "Pick one.", "card": {"picker": "accent"},
+ "tool_call_id": "call_1"}]
assert result["answer"] == {"accent": "Ultraviolet"} and result["next"] == "name"
assert "Ultraviolet" in result["reminder"]
assert onboarding_record.load(db, SID)["beats"]["theme"] == "done"
@@ -79,6 +90,18 @@ def test_no_answer_closes_the_card_and_typed_words_come_back_as_said(db, desktop
assert onboarding_record.load(db, SID)["waiting"] is None
+def test_a_card_closed_by_words_a_value_or_the_deadline_reports_what_is_connected_and_installed(db, desktop):
+ onboarding_record.start(db, SID, FACTS)
+ timed_out = call(db, desktop, beat="plugins")
+ desktop.replies.append({"said": "done"})
+ said = call(db, desktop, beat="connectors", call_id="call_2")
+ continued = call(db, desktop, beat="connectors", value="continue")
+
+ assert timed_out["installed"] == ["blender"] and said["connected"] == ["slack"]
+ assert continued["connected"] == ["slack"] and "Connected: slack" in continued["reminder"]
+ assert onboarding_record.load(db, SID)["picks"]["installed"] == ["blender"]
+
+
def test_suggest_pins_connectors_and_value_or_skip_records_without_a_card(db, desktop):
onboarding_record.start(db, SID, FACTS)
desktop.replies.append({"answer": {"connected": ["slack"], "newly_connected": ["slack"]}})
diff --git a/tools/setup_beat_tool.py b/tools/setup_beat_tool.py
index 740f9e90307..963e81952e3 100644
--- a/tools/setup_beat_tool.py
+++ b/tools/setup_beat_tool.py
@@ -9,6 +9,7 @@ The ``onboarding`` toolset carrying it is folded in only for the onboarding chat
from __future__ import annotations
import json
+import logging
from collections.abc import Callable, Mapping
from typing import Any
@@ -16,18 +17,48 @@ from agent import onboarding_flow as flow
from agent.onboarding_text import QUESTIONS, finish_reminder, reminder
from tools.registry import registry, tool_error
+logger = logging.getLogger(__name__)
+
BEATS = ("next", *flow.BEAT_IDS, "done")
+def _connected() -> dict:
+ from tools.connectors.display import connected_slugs
+ from tools.connectors.gateway.client import ConnectorClient
+
+ return {"connected": sorted(connected_slugs(ConnectorClient()))}
+
+
+def _installed() -> dict:
+ from hermes_cli.plugin_catalog_presence import onboarding_names
+ from hermes_cli.plugins_cmd import _catalog_installed_dir
+
+ return {"installed": [name for name in onboarding_names() if _catalog_installed_dir(name) is not None]}
+
+
+# A card closed without its own answer (words, a value, a skip, the deadline) still reports these.
+_PRESENT = {"connectors": _connected, "plugins": _installed}
+
+
+def _present(beat: str) -> dict | None:
+ if (read := _PRESENT.get(beat)) is None:
+ return None
+ try:
+ return read()
+ except Exception:
+ logger.warning("onboarding: could not read what the %s beat has on this machine", beat, exc_info=True)
+ return None
+
+
def _direct_event(beat: str, args: Mapping[str, Any]) -> flow.Event | None:
"""An event the call carries in itself (no card): done, a value given in words, or a skip. Only the
Skip setup button (onboarding.skip) ends onboarding early; the model never decides the user quit."""
if beat == "done":
return flow.Done()
if args.get("skip"):
- return flow.Skipped(beat)
+ return flow.Skipped(beat, _present(beat))
value = args.get("value")
- return flow.Recorded(beat, value.strip()) if isinstance(value, str) and value.strip() else None
+ return flow.Recorded(beat, value.strip(), _present(beat)) if isinstance(value, str) and value.strip() else None
def _reply_event(beat: str, reply: Mapping[str, Any] | None) -> flow.Event:
@@ -35,9 +66,10 @@ def _reply_event(beat: str, reply: Mapping[str, Any] | None) -> flow.Event:
said = reply.get("said")
if isinstance(said, str) and said.strip():
# Words typed while the name card waits are the name, like its own text box.
- return flow.Answered(beat, {"name": said.strip()}) if beat == "name" else flow.Said(beat, said.strip())
+ return (flow.Answered(beat, {"name": said.strip()}) if beat == "name"
+ else flow.Said(beat, said.strip(), _present(beat)))
answer = reply.get("answer")
- return flow.Answered(beat, answer) if isinstance(answer, dict) and answer else flow.TimedOut(beat)
+ return flow.Answered(beat, answer) if isinstance(answer, dict) and answer else flow.TimedOut(beat, _present(beat))
def _installed_skills() -> Callable[[str], bool]:
@@ -92,7 +124,8 @@ def setup_beat_tool(args: Mapping[str, Any], *, db=None, session_id: str = "", t
if shown.result: # refused, or a beat this machine skips
return _result(shown)
question = str(args.get("question") or "").strip() or QUESTIONS[beat]
- reply = callback({"beat": beat, "question": question, "card": _card(beat, shown, args)})
+ reply = callback({"beat": beat, "question": question, "card": _card(beat, shown, args),
+ "tool_call_id": tool_call_id or None})
after = records.load(db, session_id)
if after is not None and after["phase"] == flow.PHASE_SKIPPED:
# Skip setup closed the card (onboarding.skip already wrote the record).
diff --git a/tui_gateway/contracts/server_requests.py b/tui_gateway/contracts/server_requests.py
index f450aed7788..2347358b762 100644
--- a/tui_gateway/contracts/server_requests.py
+++ b/tui_gateway/contracts/server_requests.py
@@ -134,10 +134,12 @@ class SetupPluginsCard(Params):
class SetupBeatRequestParams(ServerRequestParams):
"""``card`` is the beat's data (``agent/onboarding_flow.py::BEATS``): name, theme, connectors and
- plugins have their own shape; layout, tour and build carry ``options``."""
+ plugins have their own shape; layout, tour and build carry ``options``. ``tool_call_id`` is the
+ setup_beat call the card belongs to: only that transcript row draws it."""
beat: SetupBeat
question: str | None = None
+ tool_call_id: str | None = None
card: SetupNameCard | SetupThemeCard | SetupOptionsCard | SetupConnectorsCard | SetupPluginsCard