LangChain-based AI engine for mental health support conversations
Project description
🌿 MentalSaathi AI Engine
The AI backbone of Mental Saathi — a mental health platform built for Indian college students. This package handles risk detection, LLM chains, prompt management, and agent orchestration.
Features
- Risk Detection Agent — analyses user-submitted text and returns a structured risk assessment (
risk_score,risk_level,summary) - LangChain-powered chains — modular, composable chains built on
langchain-core - Groq LLM integration — fast inference via
langchain-groq - Pydantic output schemas — structured, validated responses from every chain
- Pluggable prompt system — prompts and parsers are decoupled and easy to swap
Project Structure
mentalsaathi.backend/ai/
├── agent/ # High-level agents (entry points)
│ └── risk_detection.py
├── chains/ # LangChain chains
│ └── calculate_risk.py
├── core/ # App settings & config
│ └── settings.py
├── llms/ # LLM instantiation
│ └── llm.py
├── prompts/ # Prompt templates & parsers
│ └── risk.py
└── schemas/ # Pydantic output schemas
└── risk.py
Installation
Requires Python 3.11+.
# Clone the repo
git clone https://github.com/your-org/mentalsaathi.git
cd mentalsaathi.backend
# Install the AI package in editable mode
pip install -e ".[dev]"
Configuration
Create a .env file in mentalsaathi.backend/:
GROQ_API_KEY=your_groq_api_key
GROQ_MODEL=llama3-8b-8192
All settings are loaded via ai.core.Settings (Pydantic BaseSettings).
Usage
Risk Detection
from ai.agent import risk_agent
result = risk_agent.invoke({"user_input": "I've been feeling really hopeless lately..."})
print(result.risk_level) # e.g. "HIGH"
print(result.risk_score) # e.g. 78
print(result.summary) # e.g. "User expresses signs of hopelessness..."
Risk Levels
| Level | Description |
|---|---|
MINIMAL |
No significant distress detected |
LOW |
Mild emotional difficulty |
MODERATE |
Noticeable distress, worth monitoring |
HIGH |
Significant risk, prompt attention needed |
CRITICAL |
Immediate intervention recommended |
Dependencies
Key packages used:
| Package | Purpose |
|---|---|
langchain-core |
Chain & prompt abstractions |
langchain-groq |
Groq LLM integration |
pydantic |
Output schema validation |
python-dotenv |
Environment variable loading |
rich |
Pretty console output |
langsmith |
Tracing & observability |
Full list in pyproject.toml.
Development
# Run a quick smoke test on the risk agent
python -c "from ai.agent import risk_agent; print(risk_agent.invoke({'user_input': 'test'}))"
Make sure the package is installed from the repo root so absolute imports (from ai.x import ...) resolve correctly.
License
MIT © 2026 Mental Saathi
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mentalsaathi_ai-0.1.0.tar.gz.
File metadata
- Download URL: mentalsaathi_ai-0.1.0.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58b8e3953a4dfb725dc9c600c6fb62cfb2594b2647466b561c35d391c62cecb7
|
|
| MD5 |
37539d057ae095da97d40cdd754cb442
|
|
| BLAKE2b-256 |
a40310e77602a4f8ae08024fe68c328d0401f562006d3a774b23b0d777396dbc
|
File details
Details for the file mentalsaathi_ai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mentalsaathi_ai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 35.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5f9104edfe3a76f7558b56d1d1603dc89e0102408de99dd804bb82d4a28cb1a
|
|
| MD5 |
e87cbfc1802166361a5422689416e03b
|
|
| BLAKE2b-256 |
89bab480d838b137a90d92448ec2a0178ca360b20d4bce0745760f95cdceab77
|