Inspiration

The inspiration came from a simple, frustrating reality: Medical Billing Opacity. We realized that while laws like the No Surprises Act exist to protect patients, enforcing them requires expensive legal knowledge that most people simply don't have. We saw a dummy bill charging $250 for a single Tylenol pill (a 5,000% markup) and realized that this isn't just a billing error—it's an information asymmetry problem. Hospitals have algorithms to maximize billing; patients have nothing. We built The Advocate to be that equalizer: an autonomous digital defense system that works for the patient, not the provider.

What it does

The Advocate is an Autonomous Agentic Swarm that ingests medical bills and insurance policies to generate a federal dispute letter. It operates in four distinct layers:

Ingestion (Layer 1): It uses Gemini 1.5 Flash (Vision) to OCR messy, unstructured bill images into clean JSON data.

Discovery Swarm (Layer 2): Two specialized agents work in parallel.

    The Auditor cross-references CPT codes against CMS Medicare rates to flag price gouging.

    The Shark scans the insurance policy to find specific "Coverage Mandate" clauses.

Litigation Strategy (Layer 3): The Litigator Agent synthesizes this evidence to draft a formal dispute letter citing Public Law 116-260.

Adversarial Quality Control (Layer 4): This is the core innovation. A "Skeptic Agent" acts as a hostile critic. It reviews the draft and rejects it if the tone is too soft or citations are missing. The system recursively rewrites the argument until it meets a strict legal standard.

How we built it

We prioritized a Code-First approach over simple low-code wrappers.

Core Engine: Built in Python using a custom state-machine architecture to manage the agent lifecycle.

AI Models: We used a hybrid approach. Gemini 1.5 Flash handles high-volume tasks (OCR, Auditing) to minimize latency, while Gemini 1.5 Pro handles the complex legal reasoning and adversarial critique.

Grounding: To prevent hallucinations, we injected a static "Legal Knowledge Base" containing the actual text of the No Surprises Act and FDCPA directly into the context window.

Frontend: We built a "Command Center" in Streamlit that visualizes the swarm's internal logs and the chat-based conflict between the Litigator and the Skeptic in real-time.

Challenges we ran into

The "Nice Guy" Problem: Initially, our Skeptic Agent was too polite. It would approve weak letters just to be agreeable. We had to heavily engineer the system prompts to make it a "ruthless" critic that demands specific federal citations.

Rate Limits: Coordinating a 5-agent swarm hit API rate limits (429 errors) quickly. We solved this by downgrading the non-reasoning agents (Auditor/Shark) to the lighter Flash model and implementing pacing delays in the main loop.

Structured Output: Getting the LLM to output clean JSON for the frontend metrics while simultaneously writing long-form legal text required strict schema definitions and error handling.

Accomplishments that we're proud of

The Adversarial Loop: Watching the system reject its own draft, reason about why it failed ("Tone too soft"), and then self-correct to produce a perfect letter was a major technical win.

Real-Time Transparency: We successfully visualized the "Neural Activity" of the agents in the sidebar, turning a backend process into an engaging user experience.

Legal Precision: The final output accurately cites the No Surprises Act and 45 CFR Part 149, moving beyond generic complaints to specific legal demands.

What we learned

That AI limit is way higher than what we expected, AI will definely help more people than previously expected. People think AI will affect poor people as its expected to take repetitive jobs. But with tools like the advocate, AI comes into a field that will help people fight against giants

What's next for The Advocate

Physical Integration: Connecting to a specialized API to physically mail the generated Certified Letters to hospital billing departments.

Domain Expansion: Retraining the "Shark" agent to analyze Tenant Lease Agreements and Employment Contracts for similar automated defense workflows.

Built With

  • agents
  • artificial-intelligence
  • enforcing-them-requires-expensive-legal-knowledge-that-most-people-simply-don't-have.-we-saw-a-dummy-bill-charging-$250-for-a-single-tylenol-pill-(a-5
  • frustrating-reality:-medical-billing-opacity.-we-realized-that-while-laws-like-the-no-surprises-act-exist-to-protect-patients
  • google-gemini
  • ocr
  • python
  • streamlit
Share this project:

Updates