Skip to content

Repository files navigation

Type1 Agent - AI-Powered CGM Assistant

Summary

An automated, AI-powered Continuous Glucose Monitor (CGM) assistant designed to help individuals managing Type 1 Diabetes. Built entirely on AWS Serverless infrastructure, this application integrates with the Abbott FreeStyle Libre ecosystem to deliver proactive Blood Glucose (BG) telemetry alerts. Additionally, it features a Telegram-based conversational interface powered by a Retrieval-Augmented Generation (RAG) pipeline, allowing users to query their recent glucose trends in natural language.

Tech Stack

Core: Python uv poethepoet
AI / LLM: Groq Llama
Interface: Telegram
Cloud Infrastructure: AWS AWS Lambda DynamoDB S3 EventBridge
Data Engineering: PyArrow Parquet
Architecture: RAG Serverless Event Driven Hybrid Memory
Designed around lightweight serverless constraints, minimising cold start overhead and deployment package size where possible (e.g., no polars/pandas).

-- Project Status: [MVP Live / Closed Beta Testing]

Features

Unlike traditional threshold-based alerting systems, this application combines AWS serverless infrastructure with LLM-powered analysis to act as an intelligent “follower” system. It connects to the LibreLinkUp API via a central monitoring account, aggregates glucose data from multiple users, and provides:

  1. Proactive Alerts: Notifications for rapid rises, falls, or threshold breaches via Telegram.
  2. AI Chatbot (RAG): Users can query recent glucose behaviour in natural language (e.g. “How have my glucose levels been since lunch?”). The assistant uses short-term contextual memory stored in DynamoDB to generate personalised summaries without providing medical advice.
  3. Hybrid Memory Architecture: Recent data is cached in DynamoDB for low-latency retrieval, while historical data is archived to S3 in Parquet format for long-term analytics and future modelling work.

System Architecture & Data Flow

AI Chat Interaction (On Demand):

  1. Trigger: User sends a message via Telegram ("How is my trend?").
  2. Routing: Telegram Webhook invokes the Lambda.
  3. Context Retrieval: Lambda queries DynamoDB for the user's last 6 hours of readings + recent chat history.
  4. Inference: Sends the user query + glucose context to Groq (Llama 3).
  5. Response: The AI interprets the trend and replies to the user in natural language.

Scheduled Monitor Loop (Every 15 Mins):

  1. Trigger: AWS EventBridge fires the Lambda function.
  2. Auth: Lambda logs in using a single "Monitor" account credential.
  3. Discovery: Scans DynamoDB for active users and maps them to their LibreView Patient IDs.
  4. Fetch & Store:
    • Pulls the latest glucose stream for every active patient.
    • Hot Storage: Upserts latest readings to DynamoDB (TTL: 30 days) for the AI context window.
    • Cold Storage: Archives raw data to AWS S3 (Parquet) for long-term dataset building.
  5. Analyse: Checks for rapid trends or threshold breaches.
  6. Notify: Pushes alerts to the specific user's Telegram Chat ID.

Motivation

As someone diagnosed with late-onset Type 1 diabetes, I found that maintaining stable BG levels can be difficult alongside normal day-to-day activities such as work, exercise, and social life. Continuous monitoring is important, but in practice it is easy to miss rapid changes in glucose trends without proactive alerts.

Carbohydrate counting and insulin dosing are also highly variable. The same meal may require different insulin doses depending on factors such as recent activity levels, stress, illness, or insulin sensitivity on a given day. This variability can lead to BG excursions outside the desired range.

One particular concern is hypoglycemia (low BG), which can occur when insulin dosing exceeds the body's immediate glucose requirements. Severe hypoglycemia can impair cognitive function and, in extreme cases, lead to loss of consciousness or other medical emergencies. Further information can be found via the NHS overview of hypoglycaemia, or general information regarding Type 1 diabetes via Diabetes UK:

This project was initially developed as a personal monitoring and alerting tool to help identify rapid glucose changes earlier and provide more contextual awareness around glucose trends throughout the day.

🛠️ Developer Setup & Deployment

This project relies on AWS Serverless infrastructure.

  1. Environment Variables: Requires .env configuration for LibreLinkUp (MONITOR_EMAIL, MONITOR_PASSWORD), Telegram (TELEGRAM_BOT_TOKEN), and Groq (GROQ_API_KEY).
  2. Infrastructure: - AWS DynamoDB (Tables: type1_users, type1_readings with TTL enabled).
    • AWS S3 (Data lake for Parquet archiving).
    • AWS Lambda (Triggered via EventBridge for telemetry sweeps and API Gateway for Telegram webhooks).
  3. Efficient Cloud Economics:
    • Designed strictly around serverless execution (EventBridge -> Lambda) and NoSQL hot-storage (DynamoDB).

🚀 User Onboarding Flow (Closed Beta)

To comply with vendor API rate limits and prevent account suspension, public registration is currently disabled. The system is operating in a closed testing environment. Prior onboarding flow can be found below for completeness:

To use this bot, you do not need to share your password or sensitive information. You simply invite the Agent to "follow" you. This is free and open-source, but again, I refer you to the medical disclaimer.

  1. Open LibreLink App: On your phone, go to Menu > Connected Apps > LibreLinkUp (Manage).
  2. Add Connection: Click "Add Connection" and invite:
  3. Get Your Chat ID:
    • Open Telegram App and search for [@my_t1_alert_bot] or open https://t.me/my_t1_alert_bot if on PC
    • Click Start. The bot will reply with a unique ID number (e.g., 123456789).
  4. Register: Send an email to delstonai@outlook.com with:
    • Your Name (as it appears in LibreLink).
    • Your Telegram ID (e.g., 123456789).
    • Your desired Low/High and Change thresholds (e.g., Low: 4.0, High: 10.0, Rapid BG Change: 1.5).
    • The admin will approve your request, and you will start receiving alerts immediately.

✅ Roadmap

  • [ ] Conversational Memory: fully utilize Type1_ChatHistory table so the AI remembers previous context from the conversation (multi-turn chat).
  • [ ] User Self-Onboarding: Create a simple method or Telegram flow to allow users to set their own thresholds without emailing admin.

Contacts

For questions, feedback, or collaboration, feel free to reach out.

Email 1: delstonai@outlook.com

Email 2: delstonds@outlook.com (monitored more often)

⚠️ Legal, Intellectual Property & Medical Disclaimer

1. Medical Safety Warning

This software is an experimental, personal assistive and educational tool. It is NOT a medical device, it is not approved by any regulatory medical authority (such as the FDA or MHRA), and it should NEVER be used to make clinical decisions, insulin dosing calculations, or treatment adjustments. Always rely on official vendor hardware, certified software, and professional medical guidance.

This project is intended as a personal assistive and educational tool only and should not be considered a replacement for professional medical advice or clinical monitoring systems. This is an experimental engineering project, not a medical device. It should not be used to make dosing decisions.

2. Intellectual Property & Terms of Service

This project is an independent, open-source development. It is NOT affiliated with, endorsed, sponsored, or supported by Abbott Laboratories, Abbott Diabetes Care, or any of their subsidiaries.

All product names, logos, trademarks, and registered trademarks (including "FreeStyle", "Libre", "LibreLink", and "LibreLinkUp") are property of their respective owners.

This application interfaces with publicly accessible endpoints via reverse-engineered protocols for private educational and interoperability purposes. Use of this software may violate the Terms of Service of the respective platform vendors. The author assumes no responsibility or liability for account suspensions, IP blocks, or legal actions taken by third-party vendors resulting from the use of this codebase.

About

A serverless RAG AI agent for live Type1 Diabetes monitoring. Built with AWS (Lambda, DynamoDB, S3, EventBridge), Groq (Llama 3) and Libre for real-time alerts and contextual chat via Telegram.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages