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.1.tar.gz (36.7 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.1-py3-none-any.whl (59.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mentalsaathi_ai-0.2.1.tar.gz
  • Upload date:
  • Size: 36.7 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.1.tar.gz
Algorithm Hash digest
SHA256 7a863ae70428d95c8a0760cb00a08a9d3544e59475e1697c67a5102ca93f70e9
MD5 85be0ce96d768fca529152f308930884
BLAKE2b-256 07c24e3df7f4d517874521465e6d2b407bd0d4931a092b6481b12cdf07c3831a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mentalsaathi_ai-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 95ddf538f826e6352dddc87551bf6d5a9c3b57eaeb10386fc3577e280d6af1b2
MD5 744186cd095338cf5f1630ad3ba25597
BLAKE2b-256 435a30a69ac090d97e4ed5cd4409b66701e75f06e62f1027913f47a3f22ba3da

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