Megalodon MD Devpost Submission

Inspiration

The same box of Metformin costs 45,000 VND at one pharmacy and 135,000 VND at another a 200% markup for the identical drug. Academic research using WHO methodology found Vietnamese drug prices reach 47x international reference prices for branded products, with 40–60% of generic drug costs going to kickbacks rather than medicine. Vietnam has 57,000+ pharmacies, a $8.3 billion retail pharmaceutical market growing 8% annually, and zero unified pricing infrastructure. The government's 2024 Amended Pharmacy Law mandates price transparency but provides no enforcement mechanism. We built Megalodon MD to be that mechanism an autonomous pharmaceutical price intelligence platform powered by parallel AI web agents that turns every pharmacy website in Vietnam into a queryable, real-time pricing API.

What it does

Snap a photo of a Vietnamese prescription and Megalodon MD deploys a swarm of autonomous agents across Vietnam's five largest pharmacy chains simultaneously.

Qwen 2.5 72B (via OpenRouter) normalizes the extracted names resolving Vietnamese diacritics, typos, and brand variations so that "thuốc hạ đường huyết" becomes "Metformin" and "Glucophage XR 500mg" maps to the same active compound.

Why TinyFish?

Vietnamese pharmacy chains are JavaScript-rendered SPAs with no public APIs and active bot detection a standard HTTP request returns an empty div, so the only way to get live pricing is a real browser that executes JS, navigates search flows, and extracts results visually. TinyFish is the only tool that does this with natural language goals instead of very weak/loose CSS selectors, meaning when Pharmacity redesigns their site next month, our agents still work because the goal is "find the price of adderall 500mg" not "extract text from div."

Our Tier 3 scout-spawn architecture is only possible because TinyFish accepts dynamic URLs at runtime. When Exa discovers a generic alternative, we spawn new agents to price drugs that didn't exist in our system 10 seconds earlier, across 5 pharmacy sites simultaneously.

Five parallel TinyFish stealth agents then navigate Long Chau (2,117 stores), Pharmacity (957 stores), An Khang (527 stores), Than Thien (100+ stores), and Medicare (50+ stores) in real time. Every agent uses anti-detection browser profiles with BrightData proxy and Vietnam geo-targeting on the three largest chains as a fallback layer beneath TinyFish stealth mode.

As pharmacy results stream in, Exa semantic search discovers generic alternatives and therapeutic variants that were not in the original query. Megalodon MD then dynamically spawns new TinyFish agents to price every discovered variant no URL after Tier 1 is hardcoded. Every agent after the initial search is navigating a page discovered at runtime by a previous agent.

Results are cross-validated by a Qwen 2.5 72B analyst agent that generates a confidence-scored verdict from five weighted signals: source agreement, price convergence, government ceiling compliance, anomaly detection, and variant coverage. Exa provides WHO international reference pricing badges showing how Vietnamese prices compare to global benchmarks (e.g., "3.7× WHO price"), drug information cards with indications and side effects, and counterfeit risk research reports triggered automatically when anomalously cheap products are detected.

The dashboard auto-plays a Vietnamese voice summary via ElevenLabs ("Metformin 500mg, giá rẻ nhất tại Long Châu, 45.000 đồng, tiết kiệm 90.000 đồng so với nơi đắt nhất"). Persistent monitoring re-scans on a configurable schedule and sends Discord alerts with ElevenLabs Vietnamese voice notes attached when prices drop or compliance violations are detected.

One prescription photo in, optimized sourcing plan out with confidence scores, compliance checks, counterfeit flags, and a Vietnamese voice briefing.

How we built it

5-Tier Agent Cascade (TinyFish): The core architecture is a multi-tier scout-spawn pattern. Tier 0 parses prescriptions via GPT-4o with structured function calling. Tier 1 dispatches 5 parallel TinyFish agents with browser_profile: "stealth" across pharmacy chains, using production-grade goal prompts with numbered steps, cookie dismissal, CAPTCHA detection, and exact JSON output schemas tailored per pharmacy site. Tier 2 uses Exa semantic search with includeText filtering to discover generic alternatives and brand variants. Tier 3 dynamically spawns new TinyFish agents for every variant discovered at runtime the scout-spawn pattern that makes this genuinely autonomous. Tier 4 generates a confidence-scored analyst verdict via Qwen 2.5 72B with 5-signal cross-validation. Tier 5 investigation agents use Exa deep research and WHO reference pricing to produce counterfeit risk reports on anomalous products.

Backend: FastAPI with async TinyFish dispatch via asyncio.gather with return_exceptions=True for graceful degradation 4 out of 5 agents succeed even if one pharmacy is down. The prescription optimizer uses TinyFish's /run-batch endpoint for atomic multi-drug submission (e.g., 5 drugs × 5 pharmacies = 25 runs in a single POST). 23 distinct SSE event types stream agent lifecycle, model routing, compliance checks, and analyst verdicts to the dashboard in real time.

LLM Orchestration (OpenRouter): OpenRouter routes across a multi-model pipeline: Qwen 2.5 72B for Vietnamese pharmaceutical normalization and analyst verdicts, GPT-4o for prescription OCR with function calling, with automatic fallback to Claude Sonnet. Natural language queries like "I need diabetes and blood pressure medications for a clinic" are parsed by the LLM into structured multi-drug searches with AI-generated procurement recommendations. All models are configurable via environment variables with a fallback chain.

Drug Intelligence (Exa): Six distinct Exa use cases: (1) variant discovery finding generic alternatives across Vietnamese manufacturers, (2) WHO reference pricing via category: "research paper" search with inline multiplier badges, (3) drug information cards via summary: true, (4) counterfeit risk research triggered by Z-score anomaly detection, (5) scout-spawn triggers that feed discovered variants back to TinyFish Tier 3, and (6) investigation swarms that auto-research anomalously priced products. Results are cached with 1-hour TTL and degrade gracefully to local brand-to-generic mappings if Exa is unavailable.

Anti-Bot Resilience (BrightData): BrightData proxy with Vietnam geo-targeting (-country-vn) applied to Long Chau, Pharmacity, and An Khang the three largest chains with the most aggressive bot protection. Proxy credentials are masked in logs, health-checked on a 5-minute interval, and stored exclusively as environment variables.

Voice Intelligence (ElevenLabs): Two integration points. Post-search: the dashboard auto-plays a Vietnamese TTS summary via ElevenLabs eleven_multilingual_v2 model with Vietnamese-optimized voice settings (stability 0.65, similarity boost 0.80). Proactive alerts: when persistent monitoring detects price drops or compliance violations, ElevenLabs generates a Vietnamese voice note attached to Discord webhook notifications. Voice fallback chain across two verified voices ensures TTS never silently fails.

Persistence: SQLite in WAL mode for concurrent reads. APScheduler for recurring price monitoring. Government DAV ceiling prices seeded for compliance checking. Price fluctuation analysis compares current scans against historical records.

Challenges we ran into

Vietnamese pharmacy sites render drug names inconsistently across chains. "Metformin Stada 500mg" on Long Chau becomes "Metformin hydroclorid 500mg Stada" on Pharmacity and simply "Thuốc tiểu đường Metformin" on An Khang. We built a fuzzy normalization layer using Qwen 2.5 72B to match variants across sources, combined with local brand-to-generic mappings for major Vietnamese manufacturers (Stada, Domesco, DHG Pharma, Imexpharm).

Pharmacy search pages use heavy client-side JavaScript rendering, meaning standard HTTP requests return empty HTML. TinyFish stealth browser profiles with full JS execution solved this, but some chains layered Cloudflare-style anti-bot protection on top requiring BrightData proxy as a secondary fallback layer.

Managing concurrent agent calls without hitting rate limits required careful batch sizing. We used TinyFish's /run-batch endpoint for the prescription optimizer (atomic submission of up to 100 runs) and implemented 15-minute LRU caching with 200-entry eviction to avoid duplicate requests.

Price comparison across sources required normalization beyond drug names: Long Chau might show "45,000 VND / hộp 30 viên" (per box of 30) while Pharmacity shows "2,500 VND / viên" (per tablet). We normalize to price-per-unit across all sources for apples-to-apples comparison.

Distinguishing "infrastructure worked" from "data was extracted" required custom validation. TinyFish returns COMPLETED when the browser session ends, not when data is successfully scraped. We built a validation layer that distinguishes infrastructure failure, goal failure, CAPTCHA detection, and partial results ensuring no silent failures reach the dashboard.

Trae's Builder Mode proved especially useful for rapid UI prototyping during a 36-hour hackathon — describing a "5-column pharmacy card grid with SSE-driven status updates and bioluminescent glow effects" and getting a working component scaffold in seconds let us focus engineering time on the agent architecture rather than boilerplate React setup.

Accomplishments I had

We verified real price differences of 40–120% on common OTC medications across Vietnamese pharmacy chains live during our demo, confirming the problem we set out to solve.

The scout-spawn architecture produces genuinely autonomous behavior. Every agent after Tier 1 navigates a URL discovered at runtime by a previous agent. When Exa discovers that Metformin has a branded equivalent called Glucophage, new TinyFish agents spawn to price Glucophage across all pharmacies dynamically, without any hardcoded URLs. The system explores pharmacy sites the way a human researcher would, but across five chains simultaneously.

Our 5-signal confidence scoring (source agreement 30%, price convergence 20%, compliance clearance 15%, anomaly detection 20%, variant coverage 15%) goes beyond "cheapest price" to give procurement officers actionable trust signals with a 0–

Built With

Share this project:

Updates