Architecture overview
CareSupport is organized into 6 domains with clear dependency rules and enforcement boundaries.Domain breakdown
1. Transport Plumbing
1. Transport Plumbing
Purpose: Moves bytes between messaging providers and the agent. No intelligence.Components:
webhook_receiver.py- Real-time push from Linq (iMessage/RCS)poll_inbound.py- 15-second cron poll (SMS fallback)linq_gateway.py- Send/receive client for Linq Partner API V3reaction_handler.py- iMessage tapback processing
runtime/scripts/Configuration: runtime/config.py (LinqConfig)Rules:- Plumbing never reasons. It routes.
- No business logic in this layer.
- Hands messages to the agent, gets responses back, delivers them.
iMessage support: The Linq API provides access to Apple’s iMessage network. This enables read receipts, typing indicators, and tapback reactions (👍, ❤️, ❓, etc.)
2. Agent Reasoning
2. Agent Reasoning
Purpose: The AI that reads family context, understands intent, and generates responses.Core handler:
runtime/scripts/sms_handler.py- 1243 lines
- 13-step pipeline (see How It Works)
- Async/await with 45s timeout per AI call
- Fallback chain: Haiku → Gemini Flash → GPT-4o-mini
SOUL.md- Identity and voice (~74 lines, loaded every message)agent_root.md- Routing logic for protocol selectioncapabilities.md- Explicit CAN/CANNOT listskills/*.md- Conversation patternslessons.md- Accumulated corrections (max 20 global + 30 per family)
fork/workspace/protocols/ (16 protocols)- appointment-coordination
- benefits-navigation
- care-plan-updates
- care-schedules
- caregiver-handoff
- daily-check-in
- emergency-response
- family-admin
- family-onboarding
- general-tools
- hospitalization
- insurance-benefits
- medication-management
- protocol-creation (meta)
- provider-communication
- wellness-monitoring
fork/simulation/ - 5 test families, 52 conversations, 99.5% success rateRules:- Reasoning never stores directly. It requests state changes through enforcement.
- All context is pre-filtered by access level before the AI sees it.
- Responses are post-checked for leakage before sending.
3. Safety Enforcement
3. Safety Enforcement
Purpose: Mechanical checks that run before and after the AI processes messages. Not prompt-level — code-level.Components:role_filter.py - Access control (lines: 40-180)
phi_audit.py - HIPAA audit logging
filter_family_context()- Pre-filters family.md by access levelcheck_outbound_message()- Post-checks for leakagecan_approve()- Determines who can approve changes
| Level | Who | Can See | Can Do |
|---|---|---|---|
| full | Coordinators | Everything | Approve changes, add members |
| limited | Caregivers, family | Care recipient info, schedules, team, meds | Request updates (need approval) |
| schedule | Community supporters | Schedules and basic contact | View only |
log_context_load()- Who accessed what, when, whylog_response_sent()- What was sent to whomlog_response_blocked()- What was blocked and whylog_unknown_number()- Rejected access attempts
apply_updates()- Edit, don’t overwrite- Creates backup before every change
- Atomic find-and-replace operations
- Validation after edit
classify_updates()- Auto-apply vs. needs-approvalcreate_pending()- Queue approval requestresolve_approval()- Process YES/NO response- Expires after 24 hours
- Per-family mutex (prevents race conditions)
- Automatic timeout after 30s
- Ensures two simultaneous messages to the same family don’t corrupt state
- Enforcement never reasons. It checks and gates.
- All checks are mechanical. No prompt engineering for safety.
- The AI never sees what it’s not allowed to see.
- If the AI tries to leak restricted info, the response is blocked.
4. State
4. State
Purpose: The persistent context that makes the system valuable over time.family.md - Per-family care context
- Source of truth for each family
- Markdown format (human-readable)
- Sections: Care Recipient, Team, Schedule, Medications, Issues, etc.
- Updated via surgical edits (append/prepend/replace)
- Spec:
docs/design-docs/family-md-spec.md - Example:
examples/rob-family.md
schedule.md- When family.md gets too longmedications.md- Detailed medication lists- Still loaded together as a unified context
conversations/{phone}/YYYY-MM.log- Last 50 messages loaded into agent context
- Format:
[timestamp] [INBOUND/OUTBOUND] message
families/{id}/timeline/YYYY-MM.log- Cross-member view of all activity
- Format:
[timestamp] [direction] [member name] message
- PHI audit trail (who accessed what)
- Agent run logs (performance, errors)
- Backup chain (before every edit)
families/{id}/members/{name}.md- Communication preferences
- Care responsibilities
- Personal context
- Interaction history
- Global:
runtime/learning/lessons.md(max 20 entries) - Per-family:
families/{id}/lessons.md(max 30 entries) - Corrections from conversations
- Auto-pruned (oldest removed when limit reached)
- State is passive. It’s read and written, never acts.
- All writes go through the enforcement layer.
- Backups before every edit.
- No direct DB — files are the database.
Why files? See How It Works - Key Design Decisions
5. Proactive Systems
5. Proactive Systems
Purpose: Crons that scan, alert, and maintain without waiting for an SMS.Planned components:Heartbeat (48-hour scan):
- Detects families with no activity for 48+ hours
- Sends check-in message to coordinator
- “Haven’t heard from you in 2 days — is everything okay?”
- Parses medication schedules from family.md
- Sends reminders 30 minutes before dose time
- Tracks confirmations (“reply DONE when given”)
- Extracts upcoming appointments from schedule
- Sends 24-hour and 2-hour reminders
- Includes location, time, and who needs to be there
- Archives old conversation logs
- Validates family.md structure
- Grades agent performance (accuracy, tone, safety)
- Prunes oldest lessons when limits reached
fork/PRODUCTION-PLAN.md. Not yet built as code.Rules:- Proactive systems trigger the agent (via the same pipeline as SMS)
- They don’t send messages directly — they ask the agent to
- All proactive actions are logged to the audit trail
6. Knowledge Layer
6. Knowledge Layer
Purpose: Documentation that agents (AI and human) read to understand the system.Entry point:
AGENTS.md - Master routing document- Routes by task type (“SMS Pipeline” / “Add Members” / “Security” etc.)
- Prevents reading unnecessary context
- Updated whenever new files are added
docs/design-docs/- Architecture decision records
- Indexed with verification status
- Examples: family-md-spec.md, primitive-shift.md
docs/product-specs/- SMS coordination spec
- Feature requirements
docs/exec-plans/active/- Current work in progresscompleted/- Donetech-debt-tracker.md- Known gaps
PRODUCT_STRATEGY.md- Complete strategy (network types, roles, policy packs, roadmap)VISION.md- North-star narrativeROADMAP.md- Phases and scaling challenges
QUALITY_SCORE.md- Grades per layer (A/B/C/D/F)RELIABILITY.md- System reliability assessmentSECURITY.md- Enforcement posture and threat model
docs/references/- Linq API setup
- HIPAA compliance guide
- Twilio setup (backup transport)
- Knowledge is versioned. It’s the ground truth for all agent sessions.
- Deliberately changed (by plan), not automatically.
- AI agents read this before starting work.
Dependency rules
The system follows strict dependency directions to maintain architectural clarity:Plumbing never reasons
Transport layer just routes. No business logic. No decisions about what a message means.
Reasoning never stores directly
The agent requests state changes through the enforcement layer. It doesn’t write to files directly.
Enforcement never reasons
Safety checks are mechanical. They don’t try to understand intent — they just apply rules.
State is passive
Files don’t do anything. They’re read and written, but they never act on their own.
The two file types
CareSupport has a core insight: there are two fundamentally different kinds of files.| family.md | PROTOCOL.md / docs | |
|---|---|---|
| Contains | Operational state of one care network | Agent knowledge, procedures, architecture |
| Changes | Every interaction | Deliberately, by plan |
| Purpose | What’s happening now | How to do things |
| One per | Family | Domain |
| Read by | Agent (every message) | Agent (when needed for intent) |
| Written by | Agent (via enforcement layer) | Humans (code changes) |
| Versioned | Backup chain + git | Git only |
Deep dive: See
docs/design-docs/primitive-shift.md for the full explanation of this architectural principle.State management
How family.md gets updated
- Agent requests update (via
family_file_updatesin response JSON) - Enforcement classifies (auto-apply vs. needs-approval)
- If approved: Backup → Find exact text → Replace → Validate
- If needs approval: Queue pending → Text coordinator → Wait for YES/NO
Concurrency control
Each family has a lock (mutex) that prevents concurrent edits:Backup chain
Every edit creates a timestamped backup:cp .backups/family.md.20260228_143022 family.md
Surgical edits
The agent never overwrites files. It uses find-and-replace: Append to section:old_content doesn’t match exactly → edit fails cleanly (no data loss)
What’s next?
How It Works
The 13-step SMS pipeline in detail
Security & Enforcement
PHI protection, access control, and audit logging
API Reference
Integrate CareSupport into your systems
Development Guide
Set up the development environment