@mohamedmegahed/personal-health-navi

8
7
flwr new @mohamedmegahed/personal-health-navi

Personal Health Navi πŸ’€

  • not completed app, we will try to work on it later. -

A Flower AgentApp that helps users explore and understand their sleep habits through a multi-agent workflow.

Personal Health Navi is a personal-health assistant built with the Flower Agent Framework. It uses several specialized AI agents that work together to analyze sleep-related questions and provide evidence-based, personalized insights.

The idea is simple:

User question β†’ Sleep data β†’ Specialist agents β†’ Evidence β†’ Personalized answer

For example, a user could ask:

"Why have I been sleeping poorly during the last two weeks?"

The application can analyze the user's available sleep data, identify relevant patterns, and explain possible relationships between sleep duration, sleep consistency, bedtime, wake time, and other available factors.

Important: Personal Health Navi is designed to support users in understanding their health data. It does not diagnose medical conditions or replace professional medical advice.


🧠 Concept

Personal Health Navi uses a multi-agent workflow instead of asking a single AI agent to perform the entire task.

Each agent has a specific responsibility.

StageAgentResponsibility
1agent/sleep_query_agent.pyUnderstands the user's question and determines which sleep data is needed
2agent/sleep_analysis_agent.pyAnalyzes sleep data, detects patterns and calculates relevant metrics
3agent/health_summary_agent.pyExplains the findings in clear language and provides personalized, evidence-based guidance

The main orchestrator coordinates the agents and passes the relevant information from one stage to the next.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚       User          β”‚
                    β”‚ "Why is my sleep    β”‚
                    β”‚  worse recently?"   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  Sleep Query Agent  β”‚
                    β”‚                     β”‚
                    β”‚ Understand question β”‚
                    β”‚ Select data needed  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚ Sleep Analysis Agentβ”‚
                    β”‚                     β”‚
                    β”‚ Analyze sleep data  β”‚
                    β”‚ Find patterns       β”‚
                    β”‚ Calculate metrics   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚ Health Summary Agentβ”‚
                    β”‚                     β”‚
                    β”‚ Explain findings    β”‚
                    β”‚ Give context        β”‚
                    β”‚ Cite evidence       β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚ Personalized Answer β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸŒ™ Example Use Cases

Personal Health Navi can support questions such as:

Sleep duration

"How many hours do I usually sleep?"

The system can calculate average sleep duration and compare different periods.

Sleep consistency

"Is my sleep schedule regular?"

The agents can analyze variations in bedtime and wake time.

Recent changes

"Has my sleep changed compared with last month?"

The system can compare recent sleep patterns with historical data.

Sleep patterns

"What patterns can you see in my sleep?"

The analysis agent can look for relationships between available sleep metrics.

Natural-language questions

Users do not need to understand the underlying data.

Instead of:

"Calculate my 14-day average sleep duration."

they can simply ask:

"How well have I been sleeping lately?"

The query agent translates the natural-language question into an appropriate analysis task.


πŸ€– Multi-Agent Architecture

The application consists of several components.

personal-health-navi/
β”‚
β”œβ”€β”€ agent/
β”‚   β”œβ”€β”€ agent_app.py
β”‚   β”œβ”€β”€ query_agent.py
β”‚   β”œβ”€β”€ sleep_analysis_agent.py
β”‚   β”œβ”€β”€ health_summary_agent.py
β”‚   β”œβ”€β”€ runtime.py
β”‚   β”œβ”€β”€ events.py
β”‚   └── connectors/
β”‚
β”œβ”€β”€ ui/
β”‚   β”œβ”€β”€ server.py
β”‚   └── ...
β”‚
β”œβ”€β”€ README.md
β”œβ”€β”€ RUNNING.md
β”œβ”€β”€ pyproject.toml
└── ...

1. Query Agent

agent/query_agent.py

The first agent acts as the sleep-data navigator.

It receives the user's natural-language question and determines:

  • What the user wants to know
  • Which sleep metrics are relevant
  • Which time period should be analyzed
  • Whether additional context is required
  • What analysis should be performed

For example:

User:
"Why was my sleep worse this week?"

        ↓

Query Agent:

time_range = last_7_days

metrics:
- sleep_duration
- bedtime
- wake_time
- sleep_consistency

analysis:
- compare with previous period
- identify significant changes

The agent does not immediately generate the final answer. It prepares a structured task for the next agent.


2. Sleep Analysis Agent

agent/sleep_analysis_agent.py

The second agent works with the user's available sleep data.

It can perform tasks such as:

  • Calculate average sleep duration
  • Compare different time periods
  • Analyze bedtime and wake-time consistency
  • Identify changes over time
  • Detect unusually short or long sleep periods
  • Calculate sleep variability
  • Compare weekdays and weekends
  • Identify correlations between available variables

For example:

Last 7 days

Average sleep:        6h 42m
Previous 7 days:      7h 21m

Average bedtime:      23:48
Previous period:      23:12

Average wake time:     06:31
Previous period:       06:34

The result is structured evidence that can be consumed by the final agent.


3. Health Summary Agent

agent/health_summary_agent.py

The final agent transforms the analysis into an understandable response.

It should:

  • Explain the relevant findings
  • Distinguish observations from possible explanations
  • Avoid unsupported medical conclusions
  • Clearly communicate uncertainty
  • Use the user's own sleep data
  • Provide practical context where appropriate
  • Recommend professional medical advice when a situation warrants it

For example:

"Your average sleep duration decreased by approximately 39 minutes compared with the previous week. Most of the change appears to come from later bedtimes, while your wake time remained relatively stable."

The agent should not turn this observation into an unsupported diagnosis.


πŸ”„ AgentApp Orchestration

agent/agent_app.py is the main orchestrator.

It:

  1. Receives the user's question
  2. Reconstructs the conversation context
  3. Runs the Query Agent
  4. Passes the structured task to the Sleep Analysis Agent
  5. Passes the analysis to the Health Summary Agent
  6. Stores the pipeline result in context.state
  7. Streams relevant events to the UI

Conceptually:

query_result = query_agent.run(user_question)

analysis_result = sleep_analysis_agent.run(
    query=query_result,
    sleep_data=sleep_data,
)

final_answer = health_summary_agent.run(
    query=user_question,
    analysis=analysis_result,
)

This separation makes each agent easier to test, modify, and improve.


πŸ“Š Sleep Data

The application can be designed to work with structured sleep information such as:

{
  "date": "2026-09-15",
  "sleep_duration": "7h 12m",
  "bedtime": "23:05",
  "wake_time": "06:17",
  "sleep_score": 82
}

A larger dataset could contain:

  • Date
  • Sleep duration
  • Bedtime
  • Wake time
  • Sleep score
  • Sleep stages
  • Resting heart rate
  • Heart-rate variability
  • Activity
  • Exercise
  • Other user-provided contextual information

The exact available metrics depend on the connected health-data source.


πŸ” Privacy by Design

Personal Health Navi is intended for personal health data, so privacy is an important part of the architecture.

The application should follow principles such as:

  • Minimize the amount of health data sent to an AI model
  • Process data locally where practical
  • Avoid unnecessary storage of raw health data
  • Separate identifying information from analytical data
  • Use explicit user consent for data access
  • Keep audit logs free of sensitive health information where possible
  • Clearly communicate how data is processed

The multi-agent architecture also allows the application to control which data is exposed to each agent.

For example, the Query Agent may only need metadata about available metrics, while the Analysis Agent receives the actual sleep measurements.


πŸ–₯️ Browser UI

The ui/ folder provides a local interface for observing the agent workflow.

The UI can display:

  • User question
  • Current agent
  • Agent status
  • Sleep data used for analysis
  • Analysis results
  • Events generated by each agent
  • Final response

Example:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Personal Health Navi                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                              β”‚
β”‚ User: Why has my sleep been worse lately?   β”‚
β”‚                                              β”‚
β”‚ βœ“ Query Agent                                β”‚
β”‚   Identified: last 7 days                    β”‚
β”‚                                              β”‚
β”‚ βœ“ Sleep Analysis Agent                       β”‚
β”‚   Average sleep: 6h 42m                      β”‚
β”‚   Previous period: 7h 21m                    β”‚
β”‚                                              β”‚
β”‚ ● Health Summary Agent                       β”‚
β”‚   Generating explanation...                  β”‚
β”‚                                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Run the local UI with:

uv sync --extra ui

uv run python ui/server.py

If a live model and connected data sources are configured:

uv run python ui/server.py --live

Open the URL printed by the server and submit a sleep-related question.


🌸 Why Flower?

Flower provides the AgentApp runtime and workflow infrastructure.

Instead of building a custom orchestration system, Personal Health Navi can use Flower to coordinate specialized agents.

The architecture can later be extended beyond sleep.

For example:

Personal Health Navi
                         β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚              β”‚              β”‚
          β–Ό              β–Ό              β–Ό
       Sleep          Activity       Nutrition
       Agents          Agents          Agents
          β”‚              β”‚              β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β–Ό
                 Health Context Agent
                         β”‚
                         β–Ό
                  User Explanation

This makes the project a potential foundation for a broader personal health navigation system, while keeping each domain modular.


🧩 Flower Runtime

Flower Runtime provides the model/runtime configuration and task context.

The AgentApp can access configured tools and connectors through the Flower runtime rather than embedding provider credentials directly in the application.

Connector access follows the AgentApp workflow, for example:

agent.connectors.tools(...)
agent.connectors.call(...)

This keeps external integrations separated from the individual agents.


πŸš€ Build

Install the project:

uv sync

Build the Flower App Bundle:

uv run flwr build

▢️ Run with Flower

Log in to Flower SuperLink/SuperGrid as required by your environment:

uv run flwr login supergrid

Run the application:

uv run flwr run . supergrid --stream

You can override the default input:

uv run flwr run . supergrid \
  --run-config 'agent.input="How consistent is my sleep schedule?"' \
  --stream

πŸ§ͺ Example Conversation

User

"How has my sleep changed over the last two weeks?"

Query Agent

Identifies:

Period:
14 days

Required metrics:
- sleep duration
- bedtime
- wake time
- sleep consistency

Sleep Analysis Agent

Produces:

Average sleep:
6h 58m

Sleep variability:
42m

Average bedtime:
23:41

Average wake time:
06:39

and compares these values with the user's previous period when available.

Health Summary Agent

Produces a natural-language explanation:

Over the last two weeks, your sleep duration has been relatively
consistent, but your bedtime has varied considerably between days.

The main observable pattern is therefore sleep-schedule variability
rather than a large change in total sleep duration.

This is an observation from the available sleep data, not a medical
diagnosis.

πŸ› οΈ Customization

The main workflow can be modified in:

agent/agent_app.py

Individual agent behavior can be changed in:

agent/query_agent.py
agent/sleep_analysis_agent.py
agent/health_summary_agent.py

Possible future extensions include:

  • Apple Health integration
  • Google Health Connect integration
  • Wearable-device data
  • Garmin data
  • Fitbit data
  • Oura data
  • Activity and exercise data
  • Personalized sleep goals
  • Long-term trend analysis
  • Multimodal health-data analysis
  • Evidence retrieval from trusted health sources
  • Local LLM inference
  • Privacy-preserving federated workflows

πŸ—ΊοΈ Future Vision

The long-term idea is to turn Personal Health Navi into a natural-language interface for personal health data.

Instead of manually navigating dashboards, users can ask questions such as:

"How did I sleep last week?"

"Is my sleep schedule becoming more regular?"

"What changed compared with last month?"

"Show me the days when my sleep duration was lowest."

"What patterns can you find in my sleep data?"

The agent workflow translates these questions into data queries and analyses, then converts the results into explanations that are easier to understand.

The goal is not to replace a doctor or make medical decisions.

The goal is to make personal health data easier for people to explore, understand, and discuss with qualified professionals when needed.


πŸ“š Learn More


License

Add the project license here.