Tamo · system architecture

Tamo — A Longitudinal Health Digital Twin for Companion Animals

System architecture overview

Cat health monitoring with structured daily records and natural-language conversations as entry points. The system turns expressions such as “he’s been squinting since the weekend, and he threw up twice yesterday” into a structured longitudinal health record; tracks symptom courses across days; identifies urgent situations; reorganizes those courses daily using the latest observations; and produces a report for veterinarians.

Status. TestFlight within a small group.

Stack. React Native / Expo (TypeScript) client; PostgreSQL (Supabase) with row-level security; LLM access through a server-side gateway; nightly reasoning driven by pg_cron.

Benchmark. Recorded tests of what the system records, organizes and reasons over across days. See the results.

Today
Stool · Detailed
Symptom course
Dialogue
The running build, one day. Above, the daily record: eight modules; tapping Stool opens its detailed form. Below, the symptom course (§2), and the conversation that draws on it (§3) — Tamo remembers the course when the owner comes back. Deployed build, seeded demonstration cat.

0. Concept

Design principles

  1. The model judges; code routes.
    The recurring failure mode in LLM-backed record systems is asking the model to do bookkeeping — to decide simultaneously what was said, what it means, where it belongs, and whether it is still open. Here the model performs narrow, individually checkable judgments; a deterministic state machine owns routing, identity, idempotency, and lifecycle.
  2. Failure directions are chosen, not inherited.
    Every judgment is arranged so that its failure mode falls on the safe, over-reporting side: missing polarity reads as abnormal, never as silently normal; an unresolved time is stored as unresolved rather than guessed; a failed nightly round is retried rather than marked done.
  3. Expressed certainty must never exceed actual certainty.
    The report asserts only what was observed, distinguishes “not observed” from “negative”, and hides any section it cannot honestly populate — “not recorded” is never rendered as “normal”.
  4. Provenance is never destroyed.
    The owner’s original account is stored verbatim; every derived record cites the narratives it was compiled from. Structure extraction is additive — a later re-interpretation can be re-derived from testimony rather than from a lossy earlier parse.

1. The digital twin

The twin and its symptom vocabulary. Ten normalized modules; alongside them the closed 19-category body-system vocabulary that feeds the single symptom entity described in §2.
  • Stable record pointers. An application-assigned id (rec_NNNNNN) is what retrieval hands to the model, what the model cites back, and what cross-module references use — identity stays stable across turns, across days, and across the client/server boundary.
  • Relational spine, JSONB leaves. Typed columns for everything queried or joined; a GIN-indexed semantic-tag array for retrieval; JSONB for the open-ended per-category long tail. Schema evolution without migration, with every index-bearing predicate still in a real column.
  • Time modeled for lay speech. A record carries an absolute time where one exists, otherwise an age-anchor pair plus the owner’s own phrasing — a kitten-era event and a dated event live on one timeline without either being forced into the other’s representation.

2. Symptom model: two orthogonal axes

Course lifecycle. Horizons are model-proposed but floor-clamped: an acute course cannot decay to closed merely by going unmentioned, and a chronic course may go quiet but never auto-closes.

The core entity holds both a single-day observation and a multi-day episode, distinguished by lifecycle state — a course is what a day becomes, not a different kind of object.

  • Type axis. 19 closed body-system categories. A category names a body system, not a verdict.
  • Polarity axis. Three independently sourced judgments — the owner’s explicit assertion, a pure function of the structured fields, and the extraction model’s own reading — resolved by a database-generated column: any-abnormal-wins, and all-null resolves to abnormal (a false alarm, never a missed finding). Source attribution survives, so post-hoc analysis can ask which channel mislabels.
  • Normal findings are first-class data. “His stool looked fine today” writes a normal row — including during an open episode, where a normal day is diagnostically meaningful. Tri-state booleans and an explicit “not observed” enum member throughout the field schemas are what make pertinent negatives representable at all: “I checked his gums, they’re pink” ≠ “I didn’t look”.
  • Episode layer. An open course carries a per-day trajectory (onset / worsening / improving / unchanged / normal) and an append-only per-statement log — because a merged field-wise view has no unit for “one statement”, and three sentences about one ear in one day would otherwise collapse into a superposition true at no single moment.
  • Lifecycle floors. Transitions (active → passive → closed, plus dormant) use model-proposed horizons clamped by floors the model cannot override: a minimum observation window, and a rule that a chronic course may go passive but never auto-closes.

3. Conversational pipeline: response ≠ recording

One message can need an answer now and a reliable record for later. Tamo first retrieves from the Digital Twin; reply and recording then proceed concurrently along separate paths.

One turn. Intent resolves first. Retrieval reads committed records; the solid arrow supplies the response, while the dashed arrow passes selected candidates toward extraction. The dashed return from Response represents optional refill.

When a message needs recording, background extraction in the App can run alongside the reply. The reply can use the owner's words from this turn and existing records, but neither waits for nor reads the structured results extracted in this turn.

The diagram's “Write” includes validation and deterministic routing after extraction; the model does not write directly to the Digital Twin. When time is unknown, the system preserves that uncertainty rather than guessing a date.

  • Today → an observation can fold into the daily record.
  • Past → an observation can become a dated history record.
  • Ambiguous → the original time expression remains available for clarification or later review; no date is invented.

Occurrence and onset are separate questions: “is it happening today?” and “since when?” A current observation can have an earlier onset. The nightly server-side round is a later, distinct loop that organizes committed observations into courses.

4. Three time scales

One day, end to end. The day’s records and conversation close into a nightly round that organizes symptom courses and decides what tomorrow should carry; the next morning Tamo opens the conversation from that agenda rather than from a blank slate.
loopperiodjob
turnseconds extract, route to ledger, retrieve, respond
round (review)
server-side, per pet-local day
nightly organize the latest observations into courses; emit a diagnosis frame (current + append-only log); adjudicate leftover ambiguous entries; run lifecycle transitions; seed tomorrow’s follow-up agenda
(idempotent, catches up missed dates; concurrency guarded, failures retried without being marked complete)
longitudinalweeks–months periodic recalibration of each animal’s normal daily habits, version-to-version drift, assessment staleness (§5)

5. The steady-state profile, and staleness by construction

The normal-activity profile. Each animal’s own steady state, re-measured on a roughly quarterly cadence — the previous version is archived so the two can be compared.

Each animal has a versioned normal-activity profile — its own steady state (stool frequency and form, intake, activity) — archived exactly once per re-measurement session, so two versions can be compared.

It is deliberately not a per-day comparator. Daily judgment runs on discrete rules with no “normal range” and no weighted deviation score; an earlier design that scored each day against a fitted normal was abandoned. Two scoped exceptions survive:

  • body-condition score compares against its own previous value;
  • the frequency axis reads two baseline fields for a relative call, falling back to absolute thresholds when the baseline is unavailable.

The profile’s real job is longitudinal: version-to-version drift — continuous fields at ≥30%, food ≥25%; ordinal fields by rank distance.

Drift feeds the persisted health assessment, which is keyed by a hash over its own inputs — and those inputs are restricted to the persistent portrait: banded age rather than exact, chronic background rather than active courses, long-term medication, the profile and its drift. Nothing transient enters, so the hash does not churn daily. There is no “refresh the assessment” code path at all:

re-measuring archives a version → drift becomes computable → the hash changes → the assessment reads as stale and offers regeneration, user-triggered rather than silently spending a model call.

Staleness is a derived property, not an event someone has to remember to fire.

6. Memory across a turn and a longitudinal history

Each reply dynamically assembles context for that turn: recent dialogue rolls forward, and records relevant to the current conversation are retrieved from the Digital Twin as needed. Dynamic working memory stores questions awaiting answers or clarification. The Digital Twin also selectively supplies long-term, stable health background.

Context for one dialogue turn. Relevant records are retrieved from the Digital Twin, while selected health background enters through a steadier path.
  • Changing context. Recent dialogue moves forward with each turn. Records relevant to the current conversation are retrieved as needed.
  • Dynamic working memory. Questions actually asked and details still needing clarification can carry across turns. An answer can resolve the question; working memory limits repeated follow-up questions from Tamo across turns.
  • Long-term background and history. Selected background, ongoing courses and chronic observations provide relatively stable context. The Digital Twin holds the broader dated observations, current and past courses, facts and events from which the turn is assembled. The selection can change as committed records change.

New observations enter the longitudinal record only after the recording path has processed them; this turn’s reply uses previously committed records.

7. Engineering commitments

  • Pure core, IO shell. Every decision rule — merge, eviction, polarity, day-attribution, lifecycle, routing — is a pure function in a module with no I/O. That is what makes the ~150 harnesses and mutation testing possible.
  • Invariants live in the database. Constraints, generated columns and cross-table triggers reject invalid states. For pet-linked records, row-level security matches pet_id to pets.id and requires pets.user_id to equal the signed-in account.
  • One source of truth per concept. “Which day does this belong to”, “what is today” — each exists once, imported by both the client and the server legs.