| title | Mental Health Patient Environment | ||||
|---|---|---|---|---|---|
| emoji | 🧠 | ||||
| colorFrom | blue | ||||
| colorTo | purple | ||||
| sdk | docker | ||||
| app_port | 8000 | ||||
| tags |
|
This Hugging Face Space hosts the MentalHealthPatientEnv, an interactive simulation environment designed for training and evaluating conversational AI agents in mental health scenarios.
The environment mimics a patient with dynamic psychological states, allowing agents to practice:
- Asking questions
- Building trust
- Detecting risk
- Making diagnoses
The system follows a reinforcement learning loop:
- Agent sends an action (question, reflection, etc.)
- Environment generates a patient response
- Reward is calculated
- Conversation continues until completion
| Action | Description |
|---|---|
| ask_open | Open-ended question |
| ask_direct | Specific question |
| ask_risk | Safety-related question |
| reflect | Show empathy |
| diagnose | Final diagnosis |
Each step requires:
{
"action_type": "ask_open",
"message": "How have you been feeling lately?"
}
The environment returns:
{
"response": "I’ve just been feeling really tired lately...",
"clarity": 0.72,
"emotional_state": "sad",
"trust_level": 0.45,
"risk_flag": false,
"reward": 0.63,
"done": false
}
- Focus: Correct diagnosis
- Focus: Questioning strategy
-
Focus:
- Empathy
- Safety (risk detection)
- Depth of conversation
- Rewards are normalized between 0 and 1
- Final score = average reward over steps
| Score Range | Meaning |
|---|---|
| 0.8 – 1.0 | Excellent |
| 0.5 – 0.8 | Good |
| < 0.5 | Needs improvement |
https://<your-space-name>.hf.space
GET /health
POST /reset
POST /step
The patient response is generated using an external LLM.
server/response_generator.py
Find:
"model": "liquid/lfm-2.5-1.2b-instruct:free"
Replace with any supported model:
liquid/lfm-2.5-1.2b-instruct:free(fastest)minimax/minimax-m2.5:freegoogle/gemma-4-31b-it:free(slower)
Find:
OPENROUTER_URL = "https://openrouter.ai/api/v1/chat/completions"
You can replace it with:
- Custom API endpoint
- Proxy server
Go to:
Space Settings → Variables
Add:
OPENROUTER_API_KEY=your_key_here
To improve speed:
- Use smaller models
- Reduce
max_tokensto 50 - Use hybrid responses (rule-based + LLM)
Example:
if action_type == "ask_open":
return "I’m not sure… just feeling low."
Input:
ask_open | How are you feeling?
Output:
"I don’t really know… just tired all the time."
- Do not hardcode API keys
- Always use environment variables
- Ensure dataset is included
| Issue | Solution |
|---|---|
| Slow response | Use smaller model |
| No response | Check API key |
| Import errors | Fix PYTHONPATH |
This HF Space provides a flexible platform to test and evaluate conversational AI in mental health scenarios.
You can customize:
- LLM models
- Reward functions
- Patient behavior
for research, experimentation, or production use.