Skip to content
mekala27-45Public

About

WhatsApp booking agent for a fictional clinic: Postgres slot locking, webhook retries, auditable refusals

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

frontdesk

No clinical data is persisted or logged. This fictional clinic demo handles appointment logistics only. Incoming text is transient; durable conversations contain generated summaries, structured tool calls, and a fixed demo visitor alias.

A WhatsApp booking agent built around the hard parts: competing claims, webhook retries, and auditable safety decisions. FastAPI, PostgreSQL, typed tools, and a Next.js evidence explorer.

CI Pages

Open the public evidence explorer · Architecture · Measured results · Case study

No setup or login needed. Explore recorded test results, search scenarios, step through persisted tool traces, and compare expected calls with observed decisions. The public site serves archived synthetic evidence. The full booking simulator and operations console run locally against the real API.

Public evidence explorer

Review path

Engineering question Inspect the proof Read the implementation
Can competing requests double-book? Concurrency test Provider and slot locks
What happens after a retry or restart? Webhook tests Durable conversation engine
Does the agent actually refuse unsafe requests? Scenario explorer Safety rules and deterministic scorer
Can a tool cross a tenant boundary? Tenant isolation tests Scoped tool dispatch
Can the published numbers drift? Database claim gate Public evidence exporter

The scheduling proof

Measured against real Postgres, through concurrent HTTP requests to the FastAPI application:

Inspect the measured concurrency record
{
  "booking_rows": 1,
  "confirmed": 1,
  "duration_seconds": 0.166377,
  "errors": 0,
  "measured_at": "2026-09-22T02:37:03.724659+00:00",
  "pool": "warm",
  "rejected": 49,
  "requests": 50,
  "transport": "HTTP ASGI client to real Postgres",
  "under_two_seconds": true
}

The connection pool is warmed before timing. This is a local ASGI benchmark, not an internet latency measurement. Full results include tenant isolation, daylight saving transitions, duplicate delivery and every scenario.

Watch the local booking simulator walkthrough

Recorded local simulator walkthrough

Try it locally

uv sync --frozen
docker compose up -d
uv run alembic upgrade head
uv run python -m scripts.seed
uv run uvicorn frontdesk_api.app:app --port 8001 --no-access-log

In another terminal:

cd web
npm ci
npm run dev

Open the simulator or operations console. The local console token is in .env.example. Keep the API bound to loopback until deployment secrets are configured.

The default path uses the deterministic offline policy, DevTransport and NullCalendarAdapter. No Meta, model, or Google credentials are required. The simulator submits Meta-shaped payloads to the same ingestion function as the signed webhook.

Model Context Protocol slice

The Model Context Protocol surface exposes check_availability and get_my_bookings by default, plus scoped resources frontdesk://clinic/catalog, frontdesk://me/bookings, and frontdesk://me/bookings/{booking_id}, and a plan_booking prompt. Write tools book_slot, reschedule_booking, and cancel_booking appear only when the host sets FRONTDESK_MCP_ENABLE_WRITES=1. All tools use the same scoped dispatch as the booking agent. Clinic, owner, and conversation identity come from the host process environment. They are not tool arguments, so model input cannot change caller scope.

Run the self-contained demo with fictional in-memory data:

make mcp-demo

Run the TypeScript client against the same demo server over standard input and output:

cd examples/mcp-client
npm ci
npm run demo

For the Postgres-backed server, set DATABASE_URL, FRONTDESK_MCP_CLINIC_ID, FRONTDESK_MCP_OWNER_ID, and FRONTDESK_MCP_CONVERSATION_ID in the host environment, then run make mcp-serve. Add FRONTDESK_MCP_ENABLE_WRITES=1 only for a client that can render confirmation elicitation. Each write requires an idempotency key. A retry with the same key and arguments returns the stored result. Reuse with different arguments fails. The booking change and audit record commit in one transaction.

What was measured

The deterministic suite passed 50 of 50 scenarios. Application statement coverage is 92.31 percent.

Category Passed Total
booking 8 8
changes 6 6
ambiguous 6 6
injection 10 10
medical 6 6
privacy 4 4
concurrency 4 4
boundaries 6 6

The interesting decision

Refusal is a named tool call. Safety scoring queries persisted tool calls instead of asking a model to judge a reply. A model judging its own family's safety behavior creates a conflict of interest; a missing required tool call is a fact.

The emergency override runs before the optional model policy in every conversation state. Booking confirmation requires a successful scheduling transaction. Provider locks prevent overlap between different service types, and ownership checks apply inside each tool.

Deployment state and limits

The public portfolio is a static GitHub Pages evidence explorer with no API credentials or live booking endpoint. Its JSON is rendered from verified PostgreSQL evidence, and publication waits for successful CI. The local simulator and API are verified. A live Meta webhook round trip, Google Calendar delivery and a real-device recording have not been verified. No credentialed provider calls were made. No custom reminder template was submitted or approved. The default template is Meta's sample and is only a transport demonstration, not a useful appointment reminder.

An always-on public API is optional for this portfolio. Fly.io no longer offers a free tier, so no funded backend was provisioned. See the showcase publication guide or the API deployment runbook.

English only. Rule-based interpretation is deliberately limited. No unrestricted medical conversation, payments, or production readiness claim. The console uses a demo token, not individual operator authentication. There is no HIPAA compliance claim.

Meta can accept a message before a connection fails. Ambiguous sends are marked for human review instead of automatic retry. This avoids duplicate send attempts at the cost of possible missed delivery. Architecture and guarantees.

Reproduce and contribute

uv run python -m scripts.measure
uv run python -m scripts.check_published_numbers
uv run python -m scripts.showcase
uv run python -m scripts.check_no_em_dash
uv run python -m scripts.check_timezones
uv run ruff check .
uv run mypy

Measurement requires Docker and refuses silent skipping. The claim gate reloads the relational evidence snapshot, checks source audit rows, and compares whole rendered documents. Edit templates rather than published results. Contributing · Data boundaries · Safety · WhatsApp integration.

About

WhatsApp booking agent for a fictional clinic: Postgres slot locking, webhook retries, auditable refusals

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages