Skip to main content

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

mentalsaathi_ai-0.2.0.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mentalsaathi_ai-0.2.0-py3-none-any.whl (35.7 kB view details)

Uploaded Python 3

File details

Details for the file mentalsaathi_ai-0.2.0.tar.gz.

File metadata

  • Download URL: mentalsaathi_ai-0.2.0.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for mentalsaathi_ai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 83a7d9c8345521d2660f8e420124921e4cf9244c2d643f778b30ce1041b0be33
MD5 9449f9362374c74f99b06eb4c6870b55
BLAKE2b-256 493671b0e14da6dfacec662c7df9ff1745392f4dfb17c4da9db66f9646fe0732

See more details on using hashes here.

File details

Details for the file mentalsaathi_ai-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mentalsaathi_ai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 260ec5e3094813c0a926235f45423101851d85e4aebdf878aef5a99866787020
MD5 0ad9e2820e2c204b12faace7e3c1eb2c
BLAKE2b-256 6f243bd2d9affd1bb32992bcb8b07cfa087ad861a52b41852ecac1c158a452ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page