carefold
AGENTS.md2 starsChanged 59 days agoApache-2.0View on GitHub
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> Specification…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository24 other files it gives its agents.
- benefits-explainerSkill
- cardiology-prepSkill
- claims-appeals-prepSkill
- clinical-safety-boundariesSkill
- derma-prepSkill
- emergency-red-flagsSkill
- endocrinology-prepSkill
- ent-prepSkill
- formulary-navigationSkill
- gastro-prepSkill
- habit-checkinSkill
- nephrology-prepSkill
- neurology-prepSkill
- oncology-prepSkill
- ortho-prepSkill
- prior-auth-prepSkill
- pulmonology-prepSkill
- records-managementSkill
- rheuma-prepSkill
- _templateSkill
- urology-prepSkill
- vascular-prepSkill
- vision-prepSkill
- visit-prepSkill
The file
We split this AGENTS.md into the rules it gives an agent
10 rules. About 1 is common, 3 are distinctive, and 6 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Common: line 33
Patient Autonomy & Data Sovereignty: All reasoning occurs local-first (via local LLMs like Ollama or user-controlled API keys).
- Very specific: line 121
No production code in backend/src/ or apps/web/src/ may employ fake, dummy, or facade mock implementations.
- Very specific: line 122
All test doubles and mocks must reside exclusively within test directories (tests/fixtures/, backend/tests/conftest.py, or …
- Distinctive: line 164
If a red flag is detected, immediately terminates execution and returns a safe emergency directive.
- Distinctive: line 180
All AI coding assistants (e.g., Cursor, Claude Code, GitHub Copilot, Gemini CLI) operating within this repository must adhere to the …
- Very specific: line 185
Every .py, .ts, .tsx, .js, .mjs, and .css file must contain the official Spectrayan Apache-2.0 copyright header.
- Very specific: line 186
Verify license compliance using pnpm run check:licenses.
- Very specific: line 188
Never weaken clinical safety guardrails, emergency red-flag patterns, or PII regex filters in resources/ or subgraphs/extraction/.
- Very specific: line 189
Never bypass file path traversal protections in tools/sandboxed.py or tools/attachments.py.
- Distinctive: line 191
Before completing any task, execute the full verification matrix:
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Carefold Autonomous Agent Manifest
<!--
Carefold — Healthcare AI Agent Marketplace & Runtime
Copyright 2026 Spectrayan
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->Specification compliance: AGENTS.md v1.0.0
Runtime version: Carefold 0.4.0-beta.1
Last updated: 2026-10-04
1. Project Boundaries & Operational Constraints
Carefold is an open-source, local-first healthcare AI agent marketplace and execution runtime designed for privacy-preserving clinical visit preparation, health insurance navigation, and chronic care support.
1.1 Non-Clinical Boundary (Strict Safety Mandate)
- Informational and Administrative Navigation Only: Carefold agents provide educational context, visit preparation checklists, formulary navigation, and benefits explanation. Agents never provide formal medical diagnoses, drug dosage adjustments, clinical treatment decisions, or acute triage replacement.
- Emergency Escalation (Red Flags): When an acute life-threatening emergency is detected (e.g., crushing chest pain, symptoms of acute stroke, active suicidal ideation, anaphylaxis, severe respiratory distress), all agents must immediately halt delegation and trigger an emergency refusal protocol with local emergency contacts (e.g., call 911 / 988 or seek immediate emergency department care).
- Patient Autonomy & Data Sovereignty: All reasoning occurs local-first (via local LLMs like Ollama or user-controlled API keys). Patient data stays in the local runtime workspace and attachment sandbox; no background telemetry or unauthorized third-party exfiltration is permitted.
1.2 Human-in-the-Loop (HITL) Policy
- AI agents act as cognitive aids for patients and healthcare stewards. All generated summaries, appeal letters, and clinical visit prep dossiers must be reviewed and verified by a licensed human healthcare provider or the patient before submission or clinical action.
2. System Architecture & Topology
The Carefold repository is structured as a modular monorepo:
carefold/
├── backend/ # FastAPI + LangGraph multi-agent execution runtime
│ ├── src/carefold/
│ │ ├── engine/ # LangGraph workflow builder, runner, and SSE streaming service
│ │ ├── memory/ # Hexagonal ports (MemoryPort, CatalogPort) & SQLite FTS5 adapters
│ │ ├── model/ # Multi-provider LLM abstraction (Ollama, Anthropic, OpenAI, Google)
│ │ ├── tools/ # Sandboxed file, extraction, and delegation tools
│ │ └── workflows/ # LangGraph state machine, nodes, and extraction subgraphs
│ └── tests/ # Pytest suite & 47-attack penetration test harness
├── apps/web/ # Next.js 15 Tailwind CSS agent marketplace and consultation UI
├── packages/
│ ├── cli/ # Carefold CLI for agent authoring and local execution
│ └── runner/ # Standalone agent runtime sandbox
├── agents/ # 22 Specialist clinical/navigational agents + 6 system agents
├── skills/ # 23 Modular clinical skill packs with reference guidelines
├── docs/ # Verified MkDocs Material documentation & Living ADR framework
└── .github/ # GitHub Actions CI/CD matrix, CodeQL, and community templates2.1 Specialist Agent Topology (22 Specialists)
Carefold organizes clinical and administrative specialists under clear clinical risk classes (admin, wellness, clinical_assist, education):
| Agent Identifier | Domain | Category | Risk Class | Key Skills |
cardiology-guide | clinical | cardiology | clinical_assist | cardiology-prep, emergency-red-flags, clinical-safety-boundaries |
pulmonology-guide | clinical | pulmonology | clinical_assist | pulmonology-prep, emergency-red-flags, clinical-safety-boundaries |
derma-guide | clinical | dermatology | clinical_assist | derma-prep, clinical-safety-boundaries |
gastro-guide | clinical | gastroenterology | clinical_assist | gastro-prep, clinical-safety-boundaries |
neurology-guide | clinical | neurology | clinical_assist | neurology-prep, emergency-red-flags, clinical-safety-boundaries |
nephrology-guide | clinical | nephrology | clinical_assist | nephrology-prep, clinical-safety-boundaries |
endocrinology-guide | clinical | endocrinology | clinical_assist | endocrinology-prep, clinical-safety-boundaries |
rheuma-guide | clinical | rheumatology | clinical_assist | rheuma-prep, clinical-safety-boundaries |
ortho-guide | clinical | orthopedics | clinical_assist | ortho-prep, clinical-safety-boundaries |
urology-guide | clinical | urology | clinical_assist | urology-prep, clinical-safety-boundaries |
ent-guide | clinical | ent | clinical_assist | ent-prep, clinical-safety-boundaries |
eye-guide | clinical | ophthalmology | clinical_assist | vision-prep, clinical-safety-boundaries |
oncology-navigator | clinical | oncology | clinical_assist | oncology-prep, emergency-red-flags, clinical-safety-boundaries |
visit-steward | clinical | general | clinical_assist | visit-prep, emergency-red-flags, clinical-safety-boundaries |
benefits-guide | navigation | insurance | admin | benefits-explainer, records-management |
claims-appeals-guide | navigation | appeals | admin | claims-appeals-prep, benefits-explainer |
prior-auth-navigator | navigation | authorizations | admin | prior-auth-prep, records-management |
formulary-guide | navigation | pharmacy | admin | formulary-navigation, benefits-explainer |
records-coordinator | navigation | records | admin | records-management |
habit-companion | wellness | habits | wellness | habit-checkin |
_template | clinical | template | education | Starter template for community agents |
2.2 System Agents (agents/_system)
System agents manage orchestration, safety enforcement, document intelligence, and dynamic generation:
orchestrator: Two-hop intent classification, dynamic skill provisioning, and agent routing.document-extractor: Ingestion sandbox, PII sanitization, structured Pydantic dossier extraction, and numerical grounding validation.quality-reviewer: Clinical safety boundary audit, tone inspection, and persona alignment verification.skill-generator: Synthesis of dynamic skill manifests and validation templates from clinical guidelines.suggestion-generator: Context-aware follow-up suggestion chips presented in the client UI.triage-auditor: Compliance logging, risk tagging, and clinical safety telemetry.
3. Agent Toolsets & Sandbox Security
Agents interact with the environment exclusively through registered, sandboxed tools defined in backend/src/carefold/tools/.
3.1 Tool Registry
attach-read: Sandboxed reading of patient-uploaded medical records, bills, and PDFs inattachments/. Strict protection against path traversal (../), null bytes, and symlink escapes.workspace-note: Reading and writing ephemeral notes inworkspace/notes/.skill-docs: Authorized access to reference clinical guidelines declared on the agent's manifest. Attempting to access undeclared skill documentation is blocked immediately.delegate_to_agent: Inter-agent routing mechanism controlled by the orchestrator.list_agents: Querying theCatalogPortfor available specialist agents.sanitize_pii: Redacts Social Security Numbers (SSN), Medical Record Numbers (MRN), phone numbers, physical addresses, and patient identifiers.extract_structured_data: Transforms unstructured text into validated Pydantic models (InsuranceBenefitsDossier,ClinicalVisitDossier,GenericDocumentDossier).validate_grounding: Verifies that extracted numerical values (e.g., copays, deductibles, lab values) are strictly grounded in the source text.extract_document_dossier: Composite dual-invocation tool wrapping file ingestion, sanitization, extraction, and grounding.
3.2 Zero-Mock Production Policy
- No production code in
backend/src/orapps/web/src/may employ fake, dummy, or facade mock implementations. - All test doubles and mocks must reside exclusively within test directories (
tests/fixtures/,backend/tests/conftest.py, orapps/web/tests/mocks/).
4. Orchestration Nodes & LangGraph Lifecycle
Carefold executes multi-agent workflows using a 5-phase deterministic LangGraph state machine:
[User Input]
│
▼
┌────────────────────────────────────────┐
│ Phase 1: Context Load & Memory Recall │ ◄── MemoryPort.recall(query, WORKING/EPISODIC)
└────────────────────────────────────────┘
│
▼
┌────────────────────────────────────────┐
│ Phase 2: Input Guardrail & Validation │ ──► [Emergency / Safety Violation] ──► [RefusalNode]
└────────────────────────────────────────┘
│ (Passed)
▼
┌────────────────────────────────────────┐
│ Phase 3: Plan & Provision │ ◄── CatalogPort.search_agents() / Two-Hop Routing
└────────────────────────────────────────┘
│
▼
┌────────────────────────────────────────┐
│ Phase 4: Specialist Agent Execution │ ◄── ToolNode (Sandboxed Tools & Subgraphs)
└────────────────────────────────────────┘
│
▼
┌────────────────────────────────────────┐
│ Phase 5: Synthesize, Guard & Stream │ ──► [SSE Stream: Token, Tools, Suggestions, Disclaimer]
└────────────────────────────────────────┘- Phase 1: Context Load & Memory Recall (
InputGuardrailNode):- Ingests user query, conversation history, and thread state.
- Queries
MemoryPortfor relevant episodic and semantic memories using FTS5 search and salience ranking.
- Phase 2: Input Guardrail & Validation (
InputGuardrailNode,RefusalNode):- Evaluates emergency red flags and non-clinical boundary violations.
- If a red flag is detected, immediately terminates execution and returns a safe emergency directive.
- Phase 3: Plan & Provision (
OrchestratorNode):- Executes Two-Hop Routing: Hop 1 classifies domain; Hop 2 searches the
CatalogPortusing BM25 full-text matching against specialist manifests. - Injects authorized reference documents and tool schemas into the execution context.
- Executes Two-Hop Routing: Hop 1 classifies domain; Hop 2 searches the
- Phase 4: Specialist Execution (
AgentExecutionNode,ToolNode):- Invokes specialist agent with persona instructions and provisioned reference skills.
- Handles tool calling loops up to
DEFAULT_MAX_ITERATIONS(3 turns).
- Phase 5: Response Synthesis & Guardrails (
ResponseSynthesizerNode,OutputGuardrailNode,SuggestionNode):- Verifies grounding and persona purity.
- Generates contextual follow-up chips and attaches non-clinical disclaimers.
- Emits Server-Sent Events (SSE) to the web UI.
5. Rules of Engagement for AI Coding Agents
All AI coding assistants (e.g., Cursor, Claude Code, GitHub Copilot, Gemini CLI) operating within this repository must adhere to the following rules:
- Minimal Change Principle:
- Modify only files directly relevant to the assigned task. Never perform unsolicited refactoring or stylistic reformatting.
- License Header Integrity:
- Every
.py,.ts,.tsx,.js,.mjs, and.cssfile must contain the official Spectrayan Apache-2.0 copyright header. - Verify license compliance using
pnpm run check:licenses.
- Every
- Safety & Security Invariants:
- Never weaken clinical safety guardrails, emergency red-flag patterns, or PII regex filters in
resources/orsubgraphs/extraction/. - Never bypass file path traversal protections in
tools/sandboxed.pyortools/attachments.py.
- Never weaken clinical safety guardrails, emergency red-flag patterns, or PII regex filters in
- Verification Gates:
- Before completing any task, execute the full verification matrix:
# 1. License Check pnpm run check:licenses # 2. Backend Unit & Regression Tests backend/.venv/bin/pytest backend/tests/ # 3. Security Penetration Suite (47 Attacks) PYTHONPATH=backend/src backend/.venv/bin/python backend/tests/penetration_suite.py # 4. Frontend Typecheck pnpm --filter web typecheck # 5. Frontend Unit & Component Tests pnpm --filter web test --exclude "**/api/**" # 6. Frontend Production Build pnpm --filter web build
- Before completing any task, execute the full verification matrix:
- Documentation Integrity:
- Any modification to agent contracts, memory ports, or workflow state must be reflected in
PROJECT_CONTEXT.mdanddocs/adr/.
- Any modification to agent contracts, memory ports, or workflow state must be reflected in
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

