Managing metabolic health is often a full-time job. Between monitoring Continuous Glucose Monitor (CGM) trends and trying to decipher which "healthy" salad actually contains 40g of hidden sugar, itβs easy to feel overwhelmed.
What if your health data didn't just sit in an app, but actually did something about it? In this guide, we are building a Digital Health Butler. Using autonomous AI agents, LangGraph orchestration, and browser-use automation, we'll create a system that detects blood sugar spikes via the Dexcom API and automatically finds low-GI meal alternatives on food delivery apps.
If you are looking for more production-ready examples of AI agents in healthcare, I highly recommend checking out the advanced patterns at wellally.tech/blog.
π The Architecture: A Self-Correcting Health Loop
We aren't just building a linear script. We are building a Reflexive Agent. This means the agent observes the data, reflects on the metabolic state, and takes action using a browser.
System Workflow
graph TD
A[Start: Dexcom API Fetch] --> B{Claude 3.5 Sonnet Analysis}
B -- "Normal Levels" --> C[Log & Sleep]
B -- "Spike/High Trend Detected" --> D[Reflection Node]
D --> E[BrowserUse Plugin]
E --> F[Search Low-GI Meals on Food App]
F --> G[Suggest Replacement to User]
G --> H[Wait for Feedback]
H --> A
π Tech Stack
- Orchestration: LangGraph (Stateful multi-agent workflows)
- LLM: Claude 3.5 Sonnet (Top-tier reasoning and reflection)
- Automation: Browser-use (Playwright-based web navigation)
- Data Source: Dexcom API (CGM Simulation)
π¨βπ» Step 1: Defining the Agent State
In LangGraph, everything revolves around the State. We need to track the current glucose levels, the agent's internal reasoning (reflection), and the final meal suggestions.
from typing import Annotated, TypedDict, List
from langgraph.graph import StateGraph, END
class AgentState(TypedDict):
glucose_value: float
trend: str
reflection: str
meal_suggestions: List[str]
is_critical: bool
Step 2: The Reflection Node (Powered by Claude 3.5 Sonnet) π₯
Standard RAG isn't enough here. We need the agent to reason about the trend. Claude 3.5 Sonnet is perfect for this because it understands the nuance between a "post-workout spike" and a "high-carb meal spike."
from langchain_anthropic import ChatAnthropic
model = ChatAnthropic(model="claude-3-5-sonnet-20240620")
def analyze_glucose(state: AgentState):
glucose = state['glucose_value']
# The 'Reflection' prompt
prompt = f"Current Glucose is {glucose} mg/dL. Trend is rising. \
Reflect on the dietary needs. Should we suggest a low-GI meal?"
response = model.invoke(prompt)
return {
"reflection": response.content,
"is_critical": glucose > 140 # Threshold for intervention
}
Step 3: Web Automation with Browser-Use π
This is where it gets futuristic. Instead of calling a static API, we use Playwright to let the agent "see" the web, search for a food delivery service, and filter for low-glycemic options.
from browser_use import Agent as BrowserAgent
async def find_low_gi_meals(state: AgentState):
if not state['is_critical']:
return {"meal_suggestions": []}
# Initialize the browser agent to act on behalf of the user
browser_agent = BrowserAgent(
task="Go to DoorDash, search for 'Mediterranean Salad' or 'Keto' near me. List top 3 items.",
llm=model
)
result = await browser_agent.run()
return {"meal_suggestions": result}
Step 4: Connecting the Graph
Now, we link the logic. We want the graph to check glucose, reflect on the trend, and then conditionally decide whether to trigger the browser search.
workflow = StateGraph(AgentState)
# Add Nodes
workflow.add_node("monitor", analyze_glucose)
workflow.add_node("browser_action", find_low_gi_meals)
# Define Edges
workflow.set_entry_point("monitor")
# Conditional Logic: Only search if is_critical is True
workflow.add_conditional_edges(
"monitor",
lambda x: "browser_action" if x["is_critical"] else END
)
workflow.add_edge("browser_action", END)
# Compile
app = workflow.compile()
Why This Matters: The Power of Reflection
Most health apps just send a notification: "Your sugar is high!" π. That adds mental load.
By using LangGraph, our agent performs reflection. It realizes: "Hey, the user is spiking. I've analyzed the trend. Instead of just alarming them, I've already opened a browser, found a high-protein salmon bowl nearby, and I'm presenting it as a solution."
This shift from Information to Action is the core of the next generation of AI agents. For more insights on building these "Action-Oriented" agents, the team at WellAlly Tech has documented several deep dives into LangGraph patterns for healthcare and fintech.
π Conclusion
Building a "Digital Health Butler" is no longer science fiction. By combining the reasoning of Claude 3.5 Sonnet, the orchestration of LangGraph, and the web-browsing capabilities of Playwright, we can create agents that truly look out for our well-being.
Next Steps for you:
- Clone the
browser-userepo to test local navigations. - Hook this up to a Twilio API to receive SMS meal suggestions.
- Check out wellally.tech/blog for advanced tips on deploying these agents to production.
What would you want your personal AI butler to automate next? Drop a comment below! π π»
Top comments (0)