Objective
A clinical safety review asks three questions about any algorithm near a patient:
- Could it have changed the chart?
- What exactly did it recommend, when, and off which observation?
- Can you prove that record hasn't been edited since?
Most AI deployments answer the first with a code review, the second with application logs, and the third not at all. This recipe answers all three with database mechanics — a deterioration-watch agent whose inability to write is enforced by the engine, whose every recommendation is recorded automatically, and whose record is sha256 hash-chained so an edit is detectable.
Nothing here is a policy document. It is all SELECT-able.
Synthetic data only. The observations below are invented. This recipe demonstrates governance and traceability mechanics — it is not a validated clinical tool.
Requires: SynapCores v1.9.1+ (the decision-lineage columns on
_system_agent_runs). Every statement below was validated end-to-end on a stock v1.11.0-ce container. The agent runs on a tool-capable chat model: on 2.5.1, CE picksqwen2.5:7bwhen its inference budget is 8 GiB or more and downloads it on first start, or setmodel = "qwen2.5:7b"under[query.ai_service]to pin it.
Step 1: The observations table
CREATE TABLE IF NOT EXISTS recipe_patient_observations (
obs_id INTEGER PRIMARY KEY,
patient_ref TEXT,
heart_rate INTEGER,
resp_rate INTEGER,
temp_c DOUBLE,
systolic_bp INTEGER,
lactate_mmol DOUBLE,
recorded_at TIMESTAMP
);
Step 2: Create the agent — decision support that structurally cannot act
CREATE AGENT recipe_deterioration_watch
PERSONA 'aidb-assistant'
TASK 'A new vitals observation was recorded. Using execute_query on recipe_patient_observations, assess deterioration risk. Reply with exactly one of ESCALATE, MONITOR or ROUTINE, then the two vital signs that drove it. Under 50 words. You are decision support only; you never alter the chart.'
ON INSERT INTO recipe_patient_observations
WITH (
max_iterations = 3,
allow_writes = FALSE, -- enforced by the engine, not the prompt
timeout_seconds = 120,
budget_tokens_per_day = 200000,
on_budget_exhausted = 'pause',
memory = 'stateless' -- no cross-patient carryover
);
Two choices matter more here than anywhere else:
allow_writes = FALSEis the whole safety argument. The task text says "you never alter the chart" — but text is a request. This flag is the only route by which an agent's database tools may mutate a row, and it is off. The prompt is advisory; the envelope is enforced.memory = 'stateless'means no reasoning context carries between runs. Patient B's assessment cannot be contaminated by patient A's. For cohort-level work you would choose'persistent'; for per-patient triage, statelessness is the control.
Step 3: Record observations
INSERT INTO recipe_patient_observations VALUES
(7001,'PT-4417', 128, 26, 38.9, 88, 3.4, '2026-07-22 03:14:00'),
(7002,'PT-2290', 74, 16, 36.8, 122, 0.9, '2026-07-22 03:20:00');
Returns in milliseconds. Charting never waits on inference — the agent runs asynchronously off the write path, and it observes committed rows only (AFTER-semantics), so it can never abort or alter the write that woke it.
Allow 30–60 seconds per run on a local 7B model before Step 4.
Step 4: Read the recommendations
SELECT agent_name, activation, started_at, status, output
FROM _system_agent_runs
ORDER BY started_at;
| activation | status | output |
|---|---|---|
| INSERT ON recipe_patient_observations | success | ESCALATE — Heart Rate: 128 (above threshold); Lactate: 3.4 (above threshold) |
| INSERT ON recipe_patient_observations | success | ROUTINE — Systolic BP: 122 (within normal range); Heart Rate: 74 (within normal range) |
The tachycardic, febrile, hypotensive, hyperlactatemic patient gets ESCALATE; the stable one gets ROUTINE. More importantly for a safety review: both recommendations were recorded by the engine, with the observation that triggered them, without the application being asked to log anything.
Step 5: Show the safety envelope as data
DESCRIBE AGENT recipe_deterioration_watch;
Persona | aidb-assistant
Bindings | INSERT ON recipe_patient_observations
Enabled | true
max_iterations | 3
allow_writes | false
timeout_seconds | 120
budget_tokens_per_day | 200000
on_budget_exhausted | pause
memory | stateless
max_retries | 1
Created At | 2026-07-24T00:39:12Z
Updated At | 2026-07-24T00:39:12Z
allow_writes | false, with a creation and modification timestamp. That is the evidence that answers "could it have changed the chart?" — and Updated At tells a reviewer whether the envelope was ever loosened after go-live.
Step 6: The hash chain
SELECT agent_name, prev_hash, entry_hash, verified
FROM _system_agent_runs
ORDER BY started_at;
recipe_deterioration_watch prev 000000000000… -> entry e0bca42809f0… verified: true
recipe_deterioration_watch prev e0bca42809f0… -> entry 332923460100… verified: true
Every run's entry_hash is sha256(prev_hash ‖ the run's immutable content), linking back to the run before it and ultimately to a genesis value of 64 zeros.
verified is computed, not stored: the engine recomputes the chain on every read. Alter a recommendation in storage and that row stops hashing to its recorded value, and the next run's prev_hash no longer links. Retroactively softening an ESCALATE to a MONITOR after a bad outcome is exactly the scenario this defeats.
The chain is per tenant — all agents share one ledger, so one agent's history cannot be excised without breaking every record written after it.