Introduction
In the field of mobile health (mHealth), Just-In-Time Adaptive Interventions (JITAIs) leverage Reinforcement Learning (RL) to deliver personalized messages that encourage healthy behaviors, such as physical activity. While RL is effective for long-term optimization, it faces significant challenges in real-world deployment: slow adaptation to individual user needs and "context blindness." Standard RL agents typically rely on a fixed set of numerical features and cannot account for sudden changes in user state—such as an injury or illness—unless specifically programmed to do so. Sending a motivational message like "Go for a walk!" to a user suffering from a migraine is counterproductive, leading to user annoyance and eventual disengagement.
The LLM+TS Framework
To address these limitations, we propose LLM+TS, a hybrid architecture that integrates Large Language Models (LLMs) with Thompson Sampling (TS). This framework allows users to express their current state or preferences in natural language, which the LLM then uses to refine the RL agent's actions in real-time.
The system operates as follows:
- RL Action Selection: A Thompson Sampling agent selects an action $a$ based on the current state. TS is utilized for its sample efficiency, which is critical in human-centric studies with limited data.
- LLM Filtering: If the RL agent decides to send a message ($a > 0$), the system checks for recent free-text user feedback (e.g., "I sprained my ankle").
- Hybrid Decision: An LLM, prompted with the app's behavioral rules and the user's history, evaluates the appropriateness of the action. If the LLM determines the message is unsuitable given the text preference, it overrides the action to $a=0$ (no message).
This approach treats the LLM as a zero-shot reasoner that enforces real-time constraint satisfaction without requiring environment-specific training.
Experimental Setup: StepCountJITAI for LLM
Evaluating such systems is challenging due to the lack of mHealth datasets containing paired text preferences. We developed StepCountJITAI for LLM, a simulation benchmark that models user habituation and disengagement risks. The simulator includes a hidden binary state $W$, representing whether a user "can walk" ($W=1$) or "cannot walk" ($W=0$).
When the simulator enters the "cannot walk" state, it generates one of 20 text-based reasons to simulate user feedback. This allows us to test the LLM's ability to interpret diverse natural language inputs and prevent inappropriate interventions.
Key Results and Insights
Our experiments demonstrate that the LLM+TS framework significantly outperforms standard RL methods. In scenarios with intermittent user incapacity, LLM+TS achieved a median total reward of 919.9, compared to 622.5 for the standalone TS agent.
Analysis of action histograms showed that the hybrid system correctly suppressed messages during periods of user incapacity, thereby protecting the user from disengagement. Furthermore, the performance remained consistent across various modern LLMs (e.g., Llama 3, Gemma), indicating that the reasoning logic is robust to the choice of the underlying foundation model. While the LLM occasionally struggled with ambiguous text (e.g., "I am dealing with anxiety"), such errors occurred in less than 6% of cases and did not undermine the overall system gains.
Conclusion and Future Work
The LLM+TS framework successfully bridges the gap between long-term RL optimization and immediate, context-aware reasoning. By using LLMs as a real-time filter, we can prevent "incorrectly contextualized" messaging that leads to user attrition. Future research will explore using LLMs not just as filters, but as generative components to rewrite or tailor messages based on specific user feedback, further enhancing the personalization of digital health interventions.
Summary updated