ColdGuard is a hardware-powered cold-chain monitor for temperature-sensitive medical products (drugs, vaccines). It tracks temperature, humidity, and light exposure against a product's safe-storage profile and flags conditions that risk spoilage.
This repository is the frontend interface to ColdGuard: a WhatsApp bot that lets a healthcare worker talk to an AI agent in plain language, which in turn calls tools on the ColdGuard hardware/backend over the Model Context Protocol (MCP). All reasoning is done by Qwen models via Alibaba Cloud's DashScope endpoint — no other LLM provider is used.
WhatsApp user <--> whatsapp-web.js client <--> Qwen agent <--> MCP server <--> ColdGuard device/backend
|
Redis (conversation memory)
- WhatsApp in/out — core/whatsapp.ts and whatsapp.js start a
whatsapp-web.jssession (you scan a QR code once to link the device). Only messages from the number inALLOWED_NUMBERare processed (main.ts). - MCP connection — core/fastmcp.ts opens a Streamable HTTP MCP connection to your ColdGuard MCP server (
MCP_URL). If the server requires OAuth, core/oauth_provider.ts opens a browser window for one-time authorization and caches the resulting client info indata/mcp_client_info.json. - Agent turn — handler/groq.ts builds the message list (system prompt + conversation history + the new message), fetches the available MCP tools (mcp_client/mcp_tools.ts), and calls the Qwen Responses API (core/groq.ts) with
tool_choice: "auto". - Tool calls — if Qwen decides it needs data or wants to act on the device, it returns a function call. mcp_client/mcp_tool_call_handler.ts routes the call either to the MCP server (e.g.
get_sensor_data) or to a locally-defined client tool (e.g.create_scheduled_agent_task). Results are fed back to Qwen, and this loop repeats until it produces a final answer. - Reports — some tools (e.g.
build_vaccine_report) return long-form text that's rendered into a PDF (utils/pdf.ts) and sent back as a WhatsApp file attachment. - Reply — the final text response is sent back to the user on WhatsApp.
Each user's conversation history is stored in Redis, keyed by their WhatsApp ID, with a 24-hour TTL (utils/redis.ts). Once a conversation grows past ~65 messages, older turns are automatically summarized by Qwen and replaced with a compact summary so the thread never blows past the model's context window.
Send the message clear at any time to wipe your history.
A user can ask for a recurring or future action (e.g. "send me a report every night at 9pm"). The agent calls create_scheduled_agent_task, which registers a cron job (tools/raw_tools/raw_tools.ts). When it fires, a fresh Qwen agent turn runs headlessly and messages the result back over WhatsApp. Scheduled jobs currently live in memory only and are lost on restart.
All inference goes through a single OpenAI-compatible client pointed at Alibaba Cloud's DashScope endpoint (core/groq.ts):
| Model | Used for |
|---|---|
qwen3.5-flash |
Main conversational agent |
qwen3.6-flash |
Scheduled/background agent runs, conversation summarization |
Set QWEN_API_KEY in your .env to authenticate.
npm installCopy .env.example to .env and fill in:
| Variable | Purpose |
|---|---|
QWEN_API_KEY |
Alibaba Cloud DashScope API key |
MCP_URL |
URL of your ColdGuard MCP server |
REDIS_URL_LOCAL / REDIS_URL |
Redis instance for conversation history |
ALLOWED_NUMBER |
The only WhatsApp ID the bot will respond to |
Run the bot once, send it any message, and your ID will be printed to the console. Copy that value into ALLOWED_NUMBER.
npm run devScan the printed QR code with WhatsApp > Linked Devices > Link a Device. Once connected, the bot is live.
The agent's knowledge of what's "safe" for the currently-monitored drug/vaccine lives in the system prompt at prompts/sys_pro.ts (temperature range, humidity ceiling, degradation behavior, etc.). Update this profile to match whatever product ColdGuard is tracking.
- Uses
whatsapp-web.js, an unofficial WhatsApp Web client — suitable for a demo/hackathon deployment, not a production messaging channel. - Scheduled jobs are in-memory and don't survive a restart.