From b860dbf29165c0aa869f88d92e7f2e2b6b97721d Mon Sep 17 00:00:00 2001 From: dhonitheja Date: Sun, 22 Nov 2026 02:18:56 -0600 Subject: [PATCH 1/3] README: rework as a front page Structure only; every fact, number, command and guarantee is kept. - Quick start near the top: one-line install from the v0.3.0 tag, the watch() example, and the demo (which needs a clone). - "What it catches" combines the findings and verifiers tables and adds the `pending` finding. - New "Results with real models" table replaces a 1,300-character table cell. - Security model rows are shorter; long details move to numbered notes. - "What is tested" splits the overloaded adapter row into watched(), MCP and LangGraph rows. - Development section collects tests, scans, real-model runs and sandbox validation. Co-Authored-By: Claude Opus 5.5 --- README.md | 359 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 214 insertions(+), 145 deletions(-) diff --git a/README.md b/README.md index 1a43df2..7a6c504 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![tests](https://github.com/dhonitheja/agent-readback/actions/workflows/tests.yml/badge.svg)](https://github.com/dhonitheja/agent-readback/actions/workflows/tests.yml) -Check what an AI agent says it did against the system of record. +**Check what an AI agent says it did against the system of record.** An agent that books an appointment, issues a refund or updates a row usually ends with "Done." That message is a claim. Readback treats it as one: it @@ -30,45 +30,52 @@ flowchart LR G --> H ``` -| Problem | Example | Finding | -|---|---|---| -| The write never landed | API answered 201, nothing was stored | `missing` | -| A field is wrong | Appointment saved a day late, refund for the wrong amount | `wrong_value` | -| Something extra happened | Duplicate booking, double refund, unclaimed extra row | `extra_effect` | -| The check could not run | System of record was down | `unreachable` | +## Quick start -## What is tested and what is not +Install (Python 3.10+; the only runtime dependency is `httpx`): -Version 0.3.0. All 162 offline tests pass with the optional test dependencies -installed. A separate public HAPI FHIR R4 -sandbox run verified 10 scripted operations (6 bookings, 1 reschedule, -3 cancellations); this is a compatibility smoke test, not production validation. -A Stripe test-mode run produced the expected verdict for all four refund -scenarios, using a separate restricted key that was confirmed unable to -create refunds. +```bash +pip install "agent-readback @ git+https://github.com/dhonitheja/agent-readback@v0.3.0" +``` -| Part | Tested against | Not yet tested against | -|---|---|---| -| FHIR appointment verifier (create, update, cancel) | in-memory mock, incomplete pagination, stale-search regression, off-server next links; public HAPI R4 sandbox smoke test | a production EHR, authenticated read-only isolation | -| Stripe refund verifier and sandbox runner | mock refunds endpoint; test-key guards; Stripe test mode with a read-only restricted key: success, missing, wrong-amount and duplicate scenarios | live mode, a refund left pending by the bank | -| SQL row verifier | SQLite, including insert with concurrent deletion | Postgres or any other database | -| Anthropic and OpenAI-compatible agent loops | Mock responses cover each API's message format, Responses tool-call chaining with and without storage, and a once-per-evaluation warning for a model HTTP 400. Earlier live Anthropic runs (claude-sonnet-5-5 and claude-haiku-5-5, 50 tasks each, 20% injected faults) caught every false completion and matched the scripted baseline run for run. On the same tasks and faults, gpt-6-luna with `--reasoning-effort none` caught all 13 injected faults plus 6 of its own wrong reschedule or cancel values. With `--provider openai-responses --reasoning-effort medium`, it caught all 13 and matched the scripted baseline run for run, both with server-side storage and with `--no-store` (OpenAI echoed `store: false`; encrypted reasoning was sent back each turn instead of `previous_response_id`). The LangGraph agent (`examples/healthcare/langgraph_agent.py`, 50 tasks per model, seed 7, 20% injected faults) gave the same task verdict and finding kinds as `run_eval` and the scripted baseline in every run for claude-sonnet-5-5, claude-haiku-5-5 and gpt-6-luna (LangChain default reasoning effort); all three evidence chains were intact. Haiku and gpt-6-luna: 37 `done_and_verified`, 13 `false_completion`. Sonnet: 37, 11 and 2 `reported_failure`: in one run whose write the verifier failed, it reported the failure instead of claiming DONE. | Reasoning efforts other than `none` and `medium`; LangGraph with other models | -| Evidence log, redaction, report, dashboard, webhook | unit tests, including HTML escaping of hostile context values and a BROKEN dashboard for a tampered log | production load | -| `watched()` adapters | Sync and async functions, including off-loop verifier reads when an async tool raises, a verdict even when an AnyIO cancel scope cancels the tool after it writes, and objects with `async def __call__`. MCP 1.30 and 2.3 `ClientSession` run against in-memory FastMCP, a local stdio subprocess, and the same server over Streamable HTTP on 127.0.0.1, both backed by SQLite; over HTTP a booking the agent misdescribes is `failed` on the field read back from the database. LangGraph 0.2 and 1.2 run a wrapped `StateGraph` node and a wrapped LangChain tool in `ToolNode`, plus a full agent/`ToolNode` loop (`examples/healthcare/langgraph_agent.py`) that catches every false DONE under injected faults. Mock FHIR tests catch injected drop, wrong-time, wrong-practitioner and duplicate faults. | MCP over HTTP to a remote host, with TLS or auth | +Wrap the call your agent makes. Readback snapshots before it, reads back after +it, and logs the verdict even if the agent raises: -No security or compliance review has been done. +```python +import httpx +from agent_readback import Claim, EvidenceLog, WebhookAlert, watch +from agent_readback.verifiers import FhirAppointmentVerifier + +verifier = FhirAppointmentVerifier(httpx.Client(base_url=FHIR_URL, headers=READ_ONLY_AUTH)) +log = EvidenceLog("evidence.jsonl") + +expected = {"patient": "Patient/123", "practitioner": "Practitioner/7", + "start": "2027-01-04T15:00:00Z", "status": "booked"} +probe = Claim("fhir.appointment.create", "", expected) -## Install and run +with watch(verifier, probe, log, settle_attempts=3, on_verdict=[WebhookAlert(ALERT_URL)]) as w: + message = my_agent.book(...) # your agent, unchanged + w.claims(Claim(probe.action, message, expected)) + +if not w.verdict.ok: + escalate_to_human(w.verdict) +``` + +Give the verifier its own read-only credentials. If the agent and the verifier +share a write path, the check proves nothing. + +### See it catch false completions + +The demo and examples live in the repository, not the installed package: ```bash +git clone https://github.com/dhonitheja/agent-readback && cd agent-readback pip install -e ".[dev]" -pytest python -m examples.healthcare.run_eval --provider scripted --runs 200 --inject-faults 0.2 ``` -That last command uses a scripted agent that always makes the correct tool -calls, and a mock FHIR server told to mishandle 20% of writes while still -answering "success". Output: +A scripted agent always makes the correct tool calls, and a mock FHIR server +is told to mishandle 20% of writes while still answering "success": ``` Requests: 200 @@ -84,74 +91,58 @@ Why the false completions failed: The 15% is produced by the injected faults. It demonstrates the mechanism and is not a measurement of any real agent. -## Measure a real model - -Keep the key in your shell environment. Do not put it in a file you commit. +## What it catches -```bash -export ANTHROPIC_API_KEY=... -python -m examples.healthcare.run_eval --provider anthropic --model claude-haiku-5-5 --runs 100 --out results-haiku.json - -export OPENAI_API_KEY=... -python -m examples.healthcare.run_eval --provider openai --model gpt-6-luna --reasoning-effort none --runs 100 --out results-luna.json -python -m examples.healthcare.run_eval --provider openai-responses --model gpt-6-luna --reasoning-effort medium --runs 100 --out results-luna-reasoning.json -``` - -Add `--no-store` to the Responses command to send the conversation and -encrypted reasoning with each tool follow-up instead of using stored response IDs. - -The agent receives requests in plain English with Central Time dates, must -convert them to UTC, and must find the right appointment before changing it. -With no injected faults, every false completion in the result is the model's -own. Add `--fhir-url ` to run against a real FHIR R4 test server; -only synthetic patients and practitioners are created. - -## Use it around your own agent - -```python -import httpx -from agent_readback import Claim, EvidenceLog, WebhookAlert, watch -from agent_readback.verifiers import FhirAppointmentVerifier - -verifier = FhirAppointmentVerifier(httpx.Client(base_url=FHIR_URL, headers=READ_ONLY_AUTH)) -log = EvidenceLog("evidence.jsonl") +| Problem | Example | Finding | +|---|---|---| +| The write never landed | API answered 201, nothing was stored | `missing` | +| A field is wrong | Appointment saved a day late, refund for the wrong amount | `wrong_value` | +| Something extra happened | Duplicate booking, double refund, unclaimed extra row | `extra_effect` | +| The check could not run | System of record was down | `unreachable` | +| Not settled yet | Stripe refund matches but the bank has not settled it | `pending` | -expected = {"patient": "Patient/123", "practitioner": "Practitioner/7", - "start": "2027-01-04T15:00:00Z", "status": "booked"} -probe = Claim("fhir.appointment.create", "", expected) +| Verifier | Actions | Catches | +|---|---|---| +| `FhirAppointmentVerifier` | `fhir.appointment.create`, `.update`, `.cancel` | never stored, wrong time or practitioner, duplicate booking, wrong appointment changed | +| `StripeRefundVerifier` | `stripe.refund.create` | refund never issued, wrong amount or currency, failed refund, double refund | +| `SqlRowVerifier` | `sql.row.insert`, `sql.row.update` | row absent, wrong column value, unclaimed extra or deleted rows | -with watch(verifier, probe, log, settle_attempts=3, on_verdict=[WebhookAlert(ALERT_URL)]) as w: - message = my_agent.book(...) # your agent, unchanged - w.claims(Claim(probe.action, message, expected)) +To add one, implement `snapshot(claim)` and `check(claim, before)` from +`agent_readback/core.py`. -if not w.verdict.ok: - escalate_to_human(w.verdict) -``` +## Results with real models -### Re-checking later: refunds the bank has not settled +Healthcare tasks (book, reschedule, cancel) given in plain English with +Central Time dates; the model converts them to UTC and picks its own tool +calls. 20% of writes were sabotaged by the mock server while it still answered +"success". -A Stripe refund that matches the claim but is still `pending` gives an -`unverified` verdict with a `pending` finding. Keep `verdict.to_dict()` in your -own queue and judge it again once the bank has had time: +| Agent | Harness | Result | +|---|---|---| +| claude-sonnet-5-5, claude-haiku-5-5 | `run_eval`, 50 tasks each | Caught every false completion; matched the scripted baseline run for run | +| gpt-6-luna, `--reasoning-effort none` | `run_eval`, 50 tasks | Caught all 13 injected faults plus 6 of the model's own wrong reschedule or cancel values | +| gpt-6-luna, `--provider openai-responses --reasoning-effort medium` | `run_eval`, 50 tasks | Caught all 13; matched the scripted baseline run for run, with server-side storage and with `--no-store` | +| claude-sonnet-5-5, claude-haiku-5-5, gpt-6-luna | LangGraph agent, 50 tasks each, seed 7 | Same task verdict and finding kinds as `run_eval` and the scripted baseline in every run; all evidence chains intact | -```python -from agent_readback import recheck +LangGraph outcomes: Haiku and gpt-6-luna 37 `done_and_verified` and 13 +`false_completion`; Sonnet 37, 11 and 2 `reported_failure`, because in one run +whose write the verifier failed it reported the failure instead of claiming +DONE. gpt-6-luna ran with LangChain's default reasoning effort. With +`--no-store`, OpenAI echoed `store: false` and encrypted reasoning was sent back +each turn instead of `previous_response_id`. An earlier 3-run LangGraph smoke +test (2026-11-19, 30% faults) gave 2 verified and 1 false DONE caught per +model; too small to compare models. -again = recheck(StripeRefundVerifier(client), stored_dict, log) # verified, failed, or still pending -``` +To run these yourself, see [Measure a real model](#measure-a-real-model). -Only the refunds seen at the first check are judged; refunds created since -then are not counted. The new verdict is logged with -`context["recheck_of"]` set to the first `checked_at`. A verified or failed -verdict is never re-checked. The stored dict holds the observed refund values, -so protect the queue like the system of record itself. +## Integrations ### One-line adapters: MCP tool calls and LangGraph nodes -`watched()` wraps any sync or async function with the same `watch()` cycle. `to_claim` -gets the call's arguments and returns the claim to check, or `None` to skip. The result -is returned unchanged; verdicts go to `on_verdict`. Neither MCP nor LangGraph is a -dependency. +`watched()` wraps any sync or async function with the same `watch()` cycle. +`to_claim` gets the call's arguments and returns the claim to check, or `None` +to skip. The result is returned unchanged; verdicts go to `on_verdict`. Neither +MCP nor LangGraph is a dependency. ```python from agent_readback import Claim, mcp_text, watched @@ -177,19 +168,30 @@ python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate, or source .venv/Scripts/activate in Git Bash python -m pip install -e ".[dev,langgraph]" python -m examples.healthcare.langgraph_agent --runs 20 --inject-faults 0.3 # scripted agent, no API key +python -m examples.healthcare.langgraph_agent --provider anthropic --model claude-haiku-5-5 --runs 10 +python -m examples.healthcare.langgraph_agent --provider openai --model gpt-6-luna --runs 10 ``` -With a real model through `langchain-anthropic` or `langchain-openai` (keys from -the environment or `.env`; the model gets book, reschedule and cancel requests -in Central time and picks its own tool calls), in the same activated venv: +Real models run through `langchain-anthropic` or `langchain-openai`, with keys +from the environment or `.env`. -```bash -python -m examples.healthcare.langgraph_agent --provider anthropic --model claude-haiku-5-5 --runs 10 -python -m examples.healthcare.langgraph_agent --provider openai --model gpt-6-luna --runs 10 +### Re-checking later: refunds the bank has not settled + +A Stripe refund that matches the claim but is still `pending` gives an +`unverified` verdict with a `pending` finding. Keep `verdict.to_dict()` in your +own queue and judge it again once the bank has had time: + +```python +from agent_readback import recheck + +again = recheck(StripeRefundVerifier(client), stored_dict, log) # verified, failed, or still pending ``` -A 3-run smoke test with each model (2026-11-19, 30% injected faults) gave -2 verified and 1 false DONE caught per model. Too small to compare models. +Only the refunds seen at the first check are judged; refunds created since +then are not counted. The new verdict is logged with `context["recheck_of"]` +set to the first `checked_at`. A verified or failed verdict is never +re-checked. The stored dict holds the observed refund values, so protect the +queue like the system of record itself. ### Rate limiting the verifier's reads @@ -214,18 +216,6 @@ sql = SqlRowVerifier(limit_reads(connect, limit), "orders", "id") # every c - A 429 the server still sends is a read error, so `unverified`. It is not retried. -## Verifiers - -| Verifier | Actions | Catches | -|---|---|---| -| `FhirAppointmentVerifier` | `fhir.appointment.create`, `.update`, `.cancel` | never stored, wrong time or practitioner, duplicate booking, wrong appointment changed | -| `StripeRefundVerifier` | `stripe.refund.create` | refund never issued, wrong amount or currency, failed refund, double refund | -| `SqlRowVerifier` | `sql.row.insert`, `sql.row.update` | row absent, wrong column value, unclaimed extra or deleted rows | - -To add one, implement `snapshot(claim)` and `check(claim, before)` from -`agent_readback/core.py`. Give every verifier its own read-only credentials. -If the agent and the verifier share a write path, the check proves nothing. - ## Evidence log Every verdict is appended to a JSON-lines file in which each record carries @@ -240,21 +230,35 @@ readback verify-log --require-key evidence.jsonl # audits: fail unless READBAC # exit codes: 0 intact, 1 broken or untrustworthy, 2 bad arguments, 3 file error ``` -The dashboard shows the same redacted data as the log, with every value -HTML-escaped. A sample is in [`docs/sample-report.html`](docs/sample-report.html). - -With `READBACK_LOG_KEY` set (or `EvidenceLog(path, key=...)`) every hash is an -HMAC-SHA256, so nobody without the key can rewrite the chain and pass it off -as genuine. Always set it in production. The file is created readable by its -owner only and opened append-only; use one writer per file. - -Truncation (dropping the newest records) cannot be seen from the file alone, -so anchor the head outside it. `FileAnchor` rewrites a small file with the -record count and head hash after every append; put that file where the log -writer cannot change it (another volume or account, a synced or append-only -store). Any callable `anchor(count, head)` works, for example one that posts to -a ticket or a KMS-signed store. A failed anchor never breaks the agent: it -warns and sets `log.anchor_error`. +On Windows the `readback` script may land outside `PATH`; use +`python -m agent_readback` instead. The dashboard shows the same redacted data +as the log, with every value HTML-escaped. A sample is in +[`docs/sample-report.html`](docs/sample-report.html). + +- **Keyed hashes.** With `READBACK_LOG_KEY` set (or `EvidenceLog(path, key=...)`) + every hash is an HMAC-SHA256, so nobody without the key can rewrite the chain + and pass it off as genuine. Always set it in production. +- **Owner-only, append-only.** The file is created readable by its owner only + and opened append-only; use one writer per file. +- **Redacted by default.** The log stores no values from the system of record + and no agent text, only field names, match results and a hash of the agent's + message. Pass `keep_fields=["status"]` to keep named fields, or + `keep_fields="*"` for synthetic data. `Claim.context` is stored as given, so + keep personal data out of it. Decide where the log lives and who can read it + before pointing Readback at a system that holds personal data. +- **Crashes still leave evidence.** If the agent raises inside the `watch` + block, the check still runs and the verdict is logged before the exception + propagates. + +### Detecting truncation + +Dropping the newest records cannot be seen from the file alone, so anchor the +head outside it. `FileAnchor` rewrites a small file with the record count and +head hash after every append; put that file where the log writer cannot change +it (another volume or account, a synced or append-only store). Any callable +`anchor(count, head)` works, for example one that posts to a ticket or a +KMS-signed store. A failed anchor never breaks the agent: it warns and sets +`log.anchor_error`. ```python from agent_readback import EvidenceLog, FileAnchor @@ -271,17 +275,6 @@ Records added after the anchored head are reported, not rejected. Whoever can edit both the log and the anchor can still truncate undetected, and without a key they can also forge new records after the anchored head. -By default the log stores no values from the system of record and no agent -text, only field names, match results and a hash of the agent's message. Pass -`keep_fields=["status"]` to keep named fields, or `keep_fields="*"` for -synthetic data. `Claim.context` is stored as given, so keep personal data out -of it. Decide where the log lives and who can read it before pointing Readback -at a system that holds personal data. - -If the agent raises inside the `watch` block, the check still runs and the -verdict is still logged before the exception propagates: a crash after a write -leaves evidence, not a gap. - ## Security model What Readback protects: the integrity of the evidence (it is the audit proof), @@ -297,13 +290,13 @@ restricted key with `refunds: read`, a database role with `SELECT` only). | Agent claims success, system disagrees | Independent read-back; verdict is deterministic, never from an LLM | | Agent crashes after writing | `watch` still checks and logs before the exception propagates | | Evidence record edited, deleted or reordered | Sequence number + hash chain; `verify-log` reports the first bad record | -| Whole chain rewritten by someone with file access | HMAC-SHA256 with `READBACK_LOG_KEY`; a chain built without the key fails verification. Without the key, an OK is labelled `UNKEYED` (not forgery-proof); `--require-key` makes audits fail instead. Keyed records carry `"mac": "hmac-sha256"`, so a keyed log checked without its key says so rather than "edited" | -| Newest records dropped | Not detectable from the file alone. `EvidenceLog(anchor=FileAnchor(...))` records the count and head after every append; `verify-log --anchor FILE` or `--head HASH` reports BROKEN when the anchored head is missing. The anchor must live where the log writer cannot change it | +| Whole chain rewritten by someone with file access | HMAC-SHA256 with `READBACK_LOG_KEY`; a chain built without the key fails verification (see note 1) | +| Newest records dropped | `EvidenceLog(anchor=FileAnchor(...))` plus `verify-log --anchor FILE` or `--head HASH` reports BROKEN when the anchored head is missing; the anchor must live where the log writer cannot change it | | Personal data in the log | Redacted by default: no observed values, no agent text (keyed digest only), expected values replaced unless named in `keep_fields` | -| Verifier given a key that can also write | `StripeRefundVerifier` refuses a client that sends a secret key (`sk_live_` or `sk_test_`, Basic or Bearer); use a restricted `rk_` key with refunds read. It checks the prefix of static keys only (httpx `BasicAuth` or a Bearer header; custom auth flows are never run during the check and their keys are not seen) and cannot prove an `rk_` key is read-only | -| Other Windows accounts reading the log | Mode `0600` does nothing on Windows, so a new log is created empty, has every existing access entry (explicit and inherited) removed with `icacls` and is granted to this process's own SID (read from its access token with `whoami`; System32 located with `GetSystemDirectoryW`; `USERNAME`, `SystemRoot` and `PATH` are never used), all before the first record is written. If that fails the log is still written and a `RuntimeWarning` says so. A process that opens the file in the instant between creation and restriction keeps its handle: put logs in a folder only you can access. Logs created before this change and anchor files keep their folder's access | +| Verifier given a key that can also write | `StripeRefundVerifier` refuses a client that sends a Stripe secret key (`sk_live_`, `sk_test_`); use a restricted `rk_` key with refunds read (see note 2) | +| Other Windows accounts reading the log | A new log is restricted to the process's own account before its first record is written (see note 3) | | Alert spoofing | `WebhookAlert` signs every body with `X-Readback-Signature: sha256=` when `READBACK_ALERT_KEY` is set; receivers must check it | -| Alert receiver forging the log | The alert key is separate from `READBACK_LOG_KEY` and the log key is never used for alerts. `WebhookAlert` refuses a key equal to `READBACK_LOG_KEY` or to a key passed to any `EvidenceLog` in the same process, at creation and before each send. It cannot see keys used only by other processes: keep explicit log and alert keys separate yourself | +| Alert receiver forging the log | The alert key is separate from `READBACK_LOG_KEY` and the log key is never used for alerts (see note 4) | | Server-supplied paging link sends the verifier's token elsewhere | Each FHIR next link is resolved the way httpx will send it (so `//host/x` and similar forms count) and must stay on the client's scheme, host and port; anything else is `unverified` and is never requested | | Evidence log overwritten by the dashboard | `readback dashboard` refuses an output path that is the log itself or any existing `.jsonl` | | Hostile or broken server pages forever | FHIR and Stripe reads are page-capped; the result is `unverified`, not a hang | @@ -311,14 +304,90 @@ restricted key with `refunds: read`, a database role with `SELECT` only). | Verifier overloading the system of record | Opt-in `limit_reads(..., RateLimit(...))` caps every read; it only delays reads, and with `max_wait` an over-long wait is `unverified`, never `failed` (see [Rate limiting the verifier's reads](#rate-limiting-the-verifiers-reads)) | | Unreadable system of record | `unverified`, never `verified` and never `failed` | +Notes: + +1. Without the key, an OK result is labelled `UNKEYED` (not forgery-proof); + `--require-key` makes audits fail instead. Keyed records carry + `"mac": "hmac-sha256"`, so a keyed log checked without its key says so + rather than "edited". +2. The check looks only at the key's prefix, and only for static keys (exactly + httpx `BasicAuth`, not a subclass, or a Bearer header); custom auth flows are + never run during the check and their keys are not seen. A prefix cannot + prove an `rk_` key is read-only. +3. Mode `0600` does nothing on Windows. A new log is created empty, has every + existing access entry (explicit and inherited) removed with `icacls`, and is + granted to the SID of the process's own access token, read with `whoami`. + System32 is located with `GetSystemDirectoryW`; `USERNAME`, `SystemRoot` and + `PATH` are never used. If that fails the log is still written and a + `RuntimeWarning` says so. A process that opens the file in the instant + between creation and restriction keeps its handle, so put logs in a folder + only you can access. Logs created before this change and anchor files keep + their folder's access. +4. `WebhookAlert` refuses a key equal to `READBACK_LOG_KEY` or to a key passed + to any `EvidenceLog` in the same process, at creation and before each send. + It cannot see keys used only by other processes: keep explicit log and alert + keys separate yourself. + Known limits: `Claim.context` is stored as given; `Verdict.observed` holds real values in memory (do not print it in production logs); a pending Stripe refund is `unverified` until you `recheck` it, and scheduling that is up to -you; rate limiting is opt-in (`limit_reads`) and does not retry a 429. No external security or compliance review has been done. +you; rate limiting is opt-in (`limit_reads`) and does not retry a 429. No +external security or compliance review has been done. + +## What is tested and what is not + +Version 0.3.0. All 162 offline tests pass with the optional test dependencies +installed. A separate public HAPI FHIR R4 sandbox run verified 10 scripted +operations (6 bookings, 1 reschedule, 3 cancellations); this is a +compatibility smoke test, not production validation. A Stripe test-mode run +produced the expected verdict for all four refund scenarios, using a separate +restricted key that was confirmed unable to create refunds. + +| Part | Tested against | Not yet tested against | +|---|---|---| +| FHIR appointment verifier (create, update, cancel) | In-memory mock, incomplete pagination, stale-search regression, off-server next links; injected drop, wrong-time, wrong-practitioner and duplicate faults; public HAPI R4 sandbox smoke test | A production EHR, authenticated read-only isolation | +| Stripe refund verifier and sandbox runner | Mock refunds endpoint; test-key guards; Stripe test mode with a read-only restricted key: success, missing, wrong-amount and duplicate scenarios | Live mode, a refund left pending by the bank | +| SQL row verifier | SQLite, including insert with concurrent deletion | Postgres or any other database | +| Anthropic and OpenAI-compatible agent loops | Mock responses for each API's message format, Responses tool-call chaining with and without storage, a once-per-evaluation warning for a model HTTP 400; live runs in [Results with real models](#results-with-real-models) | Reasoning efforts other than `none` and `medium`; LangGraph with other models | +| `watched()` adapters | Sync and async functions, off-loop verifier reads when an async tool raises, a verdict even when an AnyIO cancel scope cancels the tool after it writes, objects with `async def __call__` | | +| MCP | MCP 1.30 and 2.3 `ClientSession` against in-memory FastMCP, a local stdio subprocess, and the same server over Streamable HTTP on 127.0.0.1, both backed by SQLite; over HTTP a booking the agent misdescribes is `failed` on the field read back from the database | MCP over HTTP to a remote host, with TLS or auth | +| LangGraph | LangGraph 0.2 and 1.2: a wrapped `StateGraph` node, a wrapped LangChain tool in `ToolNode`, and a full agent/`ToolNode` loop (`examples/healthcare/langgraph_agent.py`) that catches every false DONE under injected faults | | +| Evidence log, redaction, report, dashboard, webhook | Unit tests, including HTML escaping of hostile context values and a BROKEN dashboard for a tampered log | Production load | + +No security or compliance review has been done. + +## Development + +```bash +pip install -e ".[dev]" +pytest +pip install -e ".[security]" && python -m bandit -r agent_readback examples -q && python -m pip_audit --skip-editable +``` + +### Measure a real model + +Keep the key in your shell environment. Do not put it in a file you commit. + +```bash +export ANTHROPIC_API_KEY=... +python -m examples.healthcare.run_eval --provider anthropic --model claude-haiku-5-5 --runs 100 --out results-haiku.json + +export OPENAI_API_KEY=... +python -m examples.healthcare.run_eval --provider openai --model gpt-6-luna --reasoning-effort none --runs 100 --out results-luna.json +python -m examples.healthcare.run_eval --provider openai-responses --model gpt-6-luna --reasoning-effort medium --runs 100 --out results-luna-reasoning.json +``` + +Add `--no-store` to the Responses command to send the conversation and +encrypted reasoning with each tool follow-up instead of using stored response +IDs. The agent receives requests in plain English with Central Time dates, +must convert them to UTC, and must find the right appointment before changing +it. With no injected faults, every false completion in the result is the +model's own. Add `--fhir-url ` to run against a real FHIR R4 test +server; only synthetic patients and practitioners are created. -## Repeat sandbox validation +### Repeat sandbox validation -Run from this directory with fresh output paths: +Run from the repository root with fresh output paths: ```bash python -m examples.healthcare.run_eval --provider scripted --runs 10 --seed 7 --fhir-url https://hapi.fhir.org/baseR4 --log fhir-evidence.jsonl --out fhir-results.json @@ -338,15 +407,15 @@ effects. It retains test objects and writes redacted evidence by default. These are small compatibility checks, not load tests. The public FHIR sandbox permits anonymous writes, so this check does not -validate credential isolation. Only synthetic records are created and retained. -The initial run exposed cached pre-write searches; the verifier now requests -fresh reads with `Cache-Control: no-cache`. After that change, all 10 operations -verified, and the evidence chain was intact. +validate credential isolation. Only synthetic records are created and +retained. The initial run exposed cached pre-write searches; the verifier now +requests fresh reads with `Cache-Control: no-cache`. After that change, all +10 operations verified, and the evidence chain was intact. -## Project layout +### Project layout ``` -agent_readback/ core types, adapters, evidence log, report, dashboard, CLI +agent_readback/ core types, adapters, evidence log, rate limiting, report, dashboard, CLI agent_readback/verifiers/ FHIR, Stripe, SQL examples/healthcare/ mock FHIR server, agent tools, model providers, evaluation runner, LangGraph agent examples/stripe_sandbox.py Stripe test-mode validation runner From 6465b6d97047ef87643c9ecc76ad3f842b059367 Mon Sep 17 00:00:00 2001 From: dhonitheja Date: Sun, 22 Nov 2026 02:28:00 -0600 Subject: [PATCH 2/3] Correct FileAnchor guidance; fix the 0.3.0 release date FileAnchor rewrites the anchor file with the log writer's own permissions, so advising to put it where the writer cannot change it would make anchoring fail. README, Security model row and docstring now say the file is only as safe as the log, and to check against a copy the writer cannot rewrite or use an append-only anchor callable. CHANGELOG: 0.3.0 was merged and tagged on 2026-11-22 (UTC). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 14 +++++++++++++- README.md | 16 ++++++++++------ agent_readback/evidence.py | 9 ++++++--- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37fe064..ed7e386 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,19 @@ All notable changes to `agent-readback`. Dates are UTC. -## 0.3.0 — 2026-11-21 +## Unreleased + +### Documentation + +- README reworked as a front page: quick start near the top, a results table, + shorter security cells with notes. +- `FileAnchor` guidance corrected: the log writer itself rewrites the anchor + file, so the file is only as safe as the log. Check against a copy the + writer cannot rewrite, or pass an anchor callable that appends to an + independent append-only store. (The old text said to put the file where the + writer cannot change it, which would make anchoring fail.) + +## 0.3.0 — 2026-11-22 ### Breaking changes diff --git a/README.md b/README.md index 7a6c504..e413d0c 100644 --- a/README.md +++ b/README.md @@ -254,11 +254,15 @@ as the log, with every value HTML-escaped. A sample is in Dropping the newest records cannot be seen from the file alone, so anchor the head outside it. `FileAnchor` rewrites a small file with the record count and -head hash after every append; put that file where the log writer cannot change -it (another volume or account, a synced or append-only store). Any callable -`anchor(count, head)` works, for example one that posts to a ticket or a -KMS-signed store. A failed anchor never breaks the agent: it warns and sets -`log.anchor_error`. +head hash after every append, using the log writer's own permissions. On its +own that file is only as safe as the log: whoever can rewrite the log can +rewrite it too. It catches truncation when the copy you check against is out +of the writer's reach, for example a synced folder whose version history the +writer cannot erase, or a backup it cannot modify; pass that copy to +`verify-log --anchor`. For a stronger anchor, pass any callable +`anchor(count, head)` that appends to an independent append-only store, such as +a write-once bucket, a ticket system or a KMS-signed service. A failed anchor +never breaks the agent: it warns and sets `log.anchor_error`. ```python from agent_readback import EvidenceLog, FileAnchor @@ -291,7 +295,7 @@ restricted key with `refunds: read`, a database role with `SELECT` only). | Agent crashes after writing | `watch` still checks and logs before the exception propagates | | Evidence record edited, deleted or reordered | Sequence number + hash chain; `verify-log` reports the first bad record | | Whole chain rewritten by someone with file access | HMAC-SHA256 with `READBACK_LOG_KEY`; a chain built without the key fails verification (see note 1) | -| Newest records dropped | `EvidenceLog(anchor=FileAnchor(...))` plus `verify-log --anchor FILE` or `--head HASH` reports BROKEN when the anchored head is missing; the anchor must live where the log writer cannot change it | +| Newest records dropped | `EvidenceLog(anchor=FileAnchor(...))` plus `verify-log --anchor FILE` or `--head HASH` reports BROKEN when the anchored head is missing; only as strong as the anchor copy the writer cannot rewrite (see [Detecting truncation](#detecting-truncation)) | | Personal data in the log | Redacted by default: no observed values, no agent text (keyed digest only), expected values replaced unless named in `keep_fields` | | Verifier given a key that can also write | `StripeRefundVerifier` refuses a client that sends a Stripe secret key (`sk_live_`, `sk_test_`); use a restricted `rk_` key with refunds read (see note 2) | | Other Windows accounts reading the log | A new log is restricted to the process's own account before its first record is written (see note 3) | diff --git a/agent_readback/evidence.py b/agent_readback/evidence.py index 9615ccd..f8ad113 100644 --- a/agent_readback/evidence.py +++ b/agent_readback/evidence.py @@ -152,9 +152,12 @@ def _owner_only(path: Path) -> None: class FileAnchor: """Keep a log's newest (record count, head hash) in a separate small file. - Put the file where the log writer cannot rewrite it: another volume or - account, a synced or append-only store. Whoever can edit both the log and - the anchor can still truncate undetected. + The log writer replaces this file after every append, so on its own it is + only as safe as the log. Check against a copy the writer cannot rewrite (a + synced replica whose history it cannot erase, a backup), or pass an anchor + callable that appends to an independent append-only store instead. Whoever + can edit both the log and the anchor copy you check against can still + truncate undetected. """ def __init__(self, path: str | Path) -> None: From 5d1cf07539e4bcf419a5ddf75c66b612428d8e53 Mon Sep 17 00:00:00 2001 From: dhonitheja Date: Sun, 22 Nov 2026 02:35:38 -0600 Subject: [PATCH 3/3] FileAnchor docs: the anchor copy must hold the current head; monitor anchor_error An older copy such as a backup only proves the log still reaches the head it recorded, so records added since could be dropped undetected (confirmed: a 3-record backup passes against a log cut from 5 records to 4). Replacement can also fail, so say to monitor anchor_error when relying on the anchor. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 8 +++++--- README.md | 15 +++++++++------ agent_readback/evidence.py | 15 +++++++++------ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed7e386..2f507e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,11 @@ All notable changes to `agent-readback`. Dates are UTC. shorter security cells with notes. - `FileAnchor` guidance corrected: the log writer itself rewrites the anchor file, so the file is only as safe as the log. Check against a copy the - writer cannot rewrite, or pass an anchor callable that appends to an - independent append-only store. (The old text said to put the file where the - writer cannot change it, which would make anchoring fail.) + writer cannot rewrite that holds the current head (an older copy such as a + backup lets records added since be dropped undetected), or pass an anchor + callable that appends to an independent append-only store; monitor + `anchor_error` if you rely on the anchor. (The old text said to put the file + where the writer cannot change it, which would make anchoring fail.) ## 0.3.0 — 2026-11-22 diff --git a/README.md b/README.md index e413d0c..8acc00c 100644 --- a/README.md +++ b/README.md @@ -257,12 +257,15 @@ head outside it. `FileAnchor` rewrites a small file with the record count and head hash after every append, using the log writer's own permissions. On its own that file is only as safe as the log: whoever can rewrite the log can rewrite it too. It catches truncation when the copy you check against is out -of the writer's reach, for example a synced folder whose version history the -writer cannot erase, or a backup it cannot modify; pass that copy to -`verify-log --anchor`. For a stronger anchor, pass any callable -`anchor(count, head)` that appends to an independent append-only store, such as -a write-once bucket, a ticket system or a KMS-signed service. A failed anchor -never breaks the agent: it warns and sets `log.anchor_error`. +of the writer's reach and holds the current head, for example a synced folder +whose version history the writer cannot erase; pass that copy to +`verify-log --anchor`. An older copy, such as a backup, only proves the log +still reaches the head it recorded: records added since can be dropped +undetected. For a stronger anchor, pass any callable `anchor(count, head)` that +appends to an independent append-only store, such as a write-once bucket, a +ticket system or a KMS-signed service. A failed anchor never breaks the agent: +it warns and sets `log.anchor_error`, so monitor that if you rely on the +anchor. ```python from agent_readback import EvidenceLog, FileAnchor diff --git a/agent_readback/evidence.py b/agent_readback/evidence.py index f8ad113..36dc247 100644 --- a/agent_readback/evidence.py +++ b/agent_readback/evidence.py @@ -152,12 +152,15 @@ def _owner_only(path: Path) -> None: class FileAnchor: """Keep a log's newest (record count, head hash) in a separate small file. - The log writer replaces this file after every append, so on its own it is - only as safe as the log. Check against a copy the writer cannot rewrite (a - synced replica whose history it cannot erase, a backup), or pass an anchor - callable that appends to an independent append-only store instead. Whoever - can edit both the log and the anchor copy you check against can still - truncate undetected. + The log writer tries to replace this file after every append, so on its own + it is only as safe as the log. Check against a copy that the writer cannot + rewrite and that holds the current head, such as a synced replica whose + history it cannot erase; an older copy (a backup) only proves the log still + reaches that older head. Or pass an anchor callable that appends to an + independent append-only store instead. A failed replacement does not stop + the append: it warns and sets ``EvidenceLog.anchor_error``, so monitor that + if you rely on the anchor. Whoever can edit both the log and the anchor copy + you check against can still truncate undetected. """ def __init__(self, path: str | Path) -> None: