π§ AI-Powered Mental Health Assistant using hierarchical agentic architecture
- Built with Google's ADK (Agent Development Kit), FastAPI, and Gemini 2.5 Flash for providing empathetic, intelligent mental health support with safety-first crisis detection.
- Project Structure: from himlamtech
VietMindAI-ADK is a sophisticated mental health AI assistant that uses a hierarchical multi-agent system to provide:
- β Crisis Detection & Intervention: Automatic detection and handling of mental health emergencies
- β Empathetic Conversations: Context-aware, supportive dialogue for mental wellness
- β RAG-Enhanced Responses: Knowledge retrieval with hybrid search and reranking
- β Specialized Therapeutic Agents: CBT, mindfulness, and general mental health support
- β ReAct Framework: Systematic reasoning and action for agent orchestration
Root Agent (ReAct Orchestrator)
βββ Crisis Detection Agent β οΈ
β βββ Google Search Integration
β βββ Emergency Protocol Tools
βββ General Agent π¬
β βββ Basic Mental Health Support
βββ RAG Agent π
β βββ Hybrid Search (Vector + Atlas)
β βββ Document Reranking
β βββ Answer Generation
βββ CBT Agent π§ (Cognitive Behavioral Therapy)
βββ Mindfulness Agent πΈ (Meditation & Wellness)
Root Agent uses a ReAct (Reasoning and Acting) framework to:
- Observe user messages for emotional indicators and crisis signals
- Think about appropriate routing and safety protocols
- Act by delegating to specialized sub-agents
- Monitor responses and ensure user safety
- Python 3.12+
- uv package manager
- PostgreSQL with pgvector extension
- Google Gemini API key
# Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
exec $SHELL
# Clone and setup project
git clone <your-repo>
cd VietMindAI-ADK
# Install dependencies and setup hooks
make setupCopy .env.example to .env and configure:
cp .env.example .envRequired environment variables:
GEMINI_API_KEY: Your Google Gemini API key (primary LLM)DATABASE_URL: PostgreSQL connection with pgvector supportENV: Environment (dev/prod)LOG_LEVEL: Logging level (INFO, DEBUG, etc.)
# Run the development server
make dev
# or
make run
# Format code
make format
# Run linting
make lint
# Run type checking
make type
# Run tests
make test
# Run all pre-commit hooks
make hooksThis project follows hexagonal architecture with agentic AI components:
app/
βββ agents/ # Multi-agent system
β βββ agent.py # Root agent (ReAct orchestrator)
β βββ prompt.py # Root agent instructions
β βββ sub_agents/ # Specialized agents
β βββ crisis_detection_agent/ # Crisis handling
β βββ general_agent/ # General support
β βββ RAG_agent/ # Knowledge retrieval
β βββ CBT_agent/ # CBT therapy
β βββ mindfulness_agent/ # Mindfulness guidance
βββ api/ # FastAPI routes and transport
βββ core/ # Domain logic and use cases
βββ services/ # Application services (LLM, embeddings)
βββ infra/ # Infrastructure (DB, vector store)
βββ config/ # Configuration and logging
Crisis Detection Protocol:
- Automatic detection of suicide ideation, self-harm, or severe distress
- Immediate routing to Crisis Detection Agent
disallow_transfer_to_parent = Trueprevents escalation loops- Integration with emergency resources and search tools
- LLM: Google Gemini 2.5 Flash (ONLY)
- Agent Framework: Google ADK (Agent Development Kit)
- API: FastAPI + Pydantic v2
- Database: PostgreSQL + pgvector
- Embeddings: gemini-embedding-001
- Monitoring: Langfuse
- Package Manager: uv
β NO Langchain, LlamaIndex, or other LLM frameworks β NO OpenAI, Claude, Cohere (only Gemini) β NO SQLite, MySQL, ChromaDB, Pinecone β NO Flask, Django
Once running, access the API at http://localhost:2003:
- Swagger UI: http://localhost:2003/docs
- ReDoc: http://localhost:2003/redoc
- Health Check: http://localhost:2003/health
- uv: Fast Python package manager
- FastAPI: Modern async web framework
- Pre-commit: Code quality hooks
- Ruff: Fast linting and formatting
- MyPy: Strict type checking
- Pytest: Testing framework
- Google ADK: Agent orchestration
make setup: Install dependencies and setup pre-commit hooksmake run: Start development server on port 2003make format: Auto-format code with ruff and isortmake lint: Run linting checksmake type: Run mypy type checkingmake test: Run pytest test suitemake hooks: Run all pre-commit hooksmake clean: Clean cache files
All code must meet these standards:
- β 100% Type Hints: All functions and methods
- β Async/Await: All I/O operations must be async
- β Error Handling: Try-catch blocks in all service methods
- β Structured Logging: All operations logged
- β Pydantic Validation: All API input/output
- β Docstrings: All classes and public methods
- Files:
snake_case.py - Classes:
PascalCase - Functions/Variables:
snake_case - Constants:
UPPER_SNAKE_CASE
The Root Agent follows a systematic ReAct framework:
- Observation: Analyzes user emotional state and crisis indicators
- Thought: Reasons about routing and safety protocols
- Action: Delegates to specialized sub-agents
- Repeat: Monitors and iterates until user needs are met
Advanced mental health crisis detection with:
- Keyword analysis for suicide ideation and self-harm
- Emotional tone and urgency assessment
- Immediate escalation to crisis agent
- Google Search integration for emergency resources
Hybrid search system combining:
- Vector similarity search (pgvector)
- Atlas text search
- Document reranking for relevance
- Context-aware answer generation
Primarily Vietnamese language for mental health context in Vietnam, with English support for technical documentation.
- Follow the hexagonal architecture
- Use Google ADK for all agent implementations
- Maintain 100% type hint coverage
- Run
make hooksbefore committing - Add tests for new features
- Document all public APIs
MIT License
This is an AI assistant for mental health support and not a replacement for professional medical care. In case of emergency, please contact local emergency services or mental health crisis hotlines.