Blog · Backend · · 4 min read
Rehearsing AI tours on the real viewer
Ptree’s question box answers with a guided tour on the visitor’s screen instead of a chat log. A quick opener speaks and classifies the question while the main guide inspects the tree, streams short stretches of UI moves paired with captions, and rehearses every stop against the live viewer code in a worker thread before a word reaches the browser.
Keeping the visitor ahead of the model
Waiting for a language model to plan a twenty-stop tour before anything moves leaves the visitor staring at a frozen screen. Ptree overlaps every stage in parallel so that classification, lookups, failed stops, and rewrites all finish behind a moving playback buffer:
- At
t = 0, a fast opener model starts streaming one non-committal spoken sentence while classifying the question’s size (command,fact,open, orsite), safety concern, language, and whether the question already matches a curated published tour. If a published tour matches, the background guide is canceled immediately and the curated script plays at zero guide cost. - Without waiting for the opener to finish, the guide starts its first batch of tree lookups in parallel. As soon as that first lookup names a property, the viewer switches the tree to that color while the opening line is still playing.
- Rather than planning the entire tour before speaking, the guide sends short stretches through
say. Eachsaycall reports how many seconds of verified playback are queued on the visitor’s screen. Thinking is free while beats are playing and only costs the visitor on a still screen, so a turn that thinks too long with an empty queue is cut short and told to write from what it already holds. - If the rehearsal worker catches a broken click during Stretch 2, it cuts the model’s stream immediately, discards everything from the failed stop onward, leaves the worker at the last valid stop, and returns the exact error to the guide. While Stretch 1 is still playing on the visitor’s screen, the guide rewrites Stretch 2 and queues the repaired beats ahead of the playhead. The visitor experiences one continuous tour with zero dead air and never sees the discarded attempt.
Reading what the visitor sees
The guide inspects the tree through read tools that return the exact formatting shown on screen:
seereads a taxon’s lineage, sibling and child rows, property readouts, numeric spreads, range descriptions, citations, interactions, and active filters.compareruns the multi-tree ancestry lookup and side-by-side property table from Compare.articleandlookread the offline Wikipedia book and describe the organism’s served photograph through a vision pass when appearance matters.readopens Ptree’s public documentation pages (/about/,/about/methods.html,/about/source-errors.html) for questions about the site itself.
Every row includes its bracketed node ID so follow-up lookups address exact taxa rather than guessing spellings.
Moves paired with captions
Instead of paragraphs of prose, the model calls say and answer with beats in Ptree’s tour grammar: a bracketed UI verb followed by a short spoken caption.
[click property=nutrition] “Nutrition colors every branch by how organisms feed.”
[click legend=parasitic] “Pressing parasitic lights every lineage that takes food from a host.”
In the browser, the tour player moves a cursor across the screen, clicks controls, brushes legend categories, drags filter thumbs, highlights sentences in Wikipedia articles, and speaks each caption sentence by sentence. When the tour finishes, the viewer stays in that state, and the visitor has watched every click needed to reproduce it.
Running every stop in a worker first
Models hallucinate UI targets: tiles folded into the gutter, legend cells belonging to another property, or interaction partners not listed on the current page. Rather than letting a broken click reach the visitor, the rehearsal stage boots the real viewer modules inside a linkedom worker thread against the local origin at the visitor’s exact route and column count.
As each beat streams from say or answer, the gate parses the grammar, resolves named places through /api/place, and executes the stop on the worker’s live DOM. Because the stream is cut on the first refusal rather than read to completion, the guide never wastes tokens writing six more stops against a screen state that will never exist.
Replaying links after data rebuilds
Every ordinary tour that plays to completion without a visible flaw receives a deterministic three-word link (/?tour=word-word-word) stored beside the data generation digest it passed against.
When Ptree rebuilds its biodiversity stores, taxonomy and traits can shift. Rather than discarding old links or serving broken scripts, the first request for a tour from an older generation runs a single-flight rehearsal against the new data. If every stop still lands, the tour is stamped with the new generation and replays at zero model cost. If a stop breaks, only that tour is rewritten once under the same link.