AI Psychological Therapist — CLI Edition
A pure JavaScript + Node.js CLI application that provides empathetic, professional psychological support through a multi-Agent pipeline. Designed with a focus on user experience, it actively probes context, detects psychological defense mechanisms, and delivers tailored therapeutic responses.
- Multi-Agent Pipeline — Three specialized agents work in sequence: Organizer → Strategist → Therapist
- 6 Psychological Dimensions — Covers emotion, psychology, personality, attachment, self-worth, and defense mechanisms
- Adaptive Strategy — Dynamically adjusts approach based on detected user defense and engagement
- Session Persistence — Full conversation history stored locally for multi-session continuity
- Multi-LLM Support — Pluggable provider architecture (Volcano, DeepSeek, OpenAI, Zhipu, Baidu, MiniMax, Ali, Tiwen)
- Context Engineering — 6-layer prompt architecture from base persona to therapeutic output
- Ethics & Boundaries — Built-in safeguards: no diagnosis, emergency referral for crisis, privacy protection
User Input
│
▼
┌─────────────┐
│ Organizer │ ← Extracts known/missing knowledge across emotion / psychology / personality
└─────────────┘
│
▼
┌─────────────┐
│ Strategist │ ← Detects defense mechanisms, plans conversation strategy
└─────────────┘
│
▼
┌─────────────┐
│ Therapist │ ← Synthesizes final empathetic response with targeted questions
└─────────────┘
│
▼
User Response
| Level | Layer | Description |
|---|---|---|
| 1 | Base Persona | Fixed therapist identity, ethical boundaries, professional background |
| 2 | Professional Glossary | ~90 psychological terms auto-injected when detected |
| 3 | Dynamic Boundary Control | Rules: no diagnosis, crisis referral, privacy protection |
| 4 | Knowledge (Organizer Output) | Known/missing knowledge across 3 dimensions + session delta |
| 5 | Strategy (Strategist Output) | Conversation thread + defense analysis + strategy selection |
| 6 | Therapeutic Output | Final user-facing response |
src/
├── entry/ # CLI entry, argument parsing, REPL loop
│ ├── index.js # Main entry point
│ ├── setup.js # LLM provider configuration commands
│ └── session.js # Session management
├── dispatch/ # Core dispatcher orchestrating the 3-Agent pipeline
│ └── dispatcher.js
├── agents/ # Three core agents
│ ├── organizer/ # Organizer Agent — knowledge extraction
│ ├── strategist/ # Strategist Agent — defense detection & strategy planning
│ └── therapist/ # Therapist Agent — final response synthesis
├── models/ # Data models
│ ├── state.js # Global session state
│ ├── knowledge.js # Knowledge structures (emotion/psychology/personality)
│ └── strategy.js # Strategy output structure
├── utils/ # Utilities
│ ├── llm.js # LLM HTTP API caller (multi-endpoint, multi-format)
│ ├── prompt.js # Prompt builders for each agent
│ ├── history.js # Context window management
│ ├── storage.js # Session file persistence (~/.therapist/sessions/)
│ └── ui.js # CLI rendering (banners, bubbles, colors, tables)
└── config/ # Configuration
├── llm.js # Reads llm.json, exports active LLM config
├── constants.js # System prompts, boundary rules, glossary
└── questionBank.js # 6-dimension psychological assessment question bank
# Install dependencies
npm install
# Run (single prompt mode)
npm start
# Run (interactive / continuous chat mode)
npm run start:interactive
# or
node src/entry/index.js --interactive| Command | Description |
|---|---|
| (any text) | Chat with the therapist |
help / ? |
Show command help |
clear / cls |
Clear the screen |
q / quit / exit |
Exit the program |
setup |
Interactive LLM provider configuration |
setup list |
Show current LLM configuration |
setup use <provider> |
Switch LLM provider |
setup test |
Test LLM connection |
session new |
Create a new session |
session list |
List all saved sessions |
session select <id> |
Switch to a session |
session delete <id> |
Delete a session |
session info <id> |
Show session details |
session clear |
Clear current session data |
Configure your API credentials in llm.json. The active provider is set via the provider field.
# Interactive setup
node src/entry/index.js
> setup
# Or edit llm.json directlySupported providers: volcano (default), deepseek, openai, zhipu, baidu, minimax, tiwen, ali
The Strategist Agent triggers assessment questions across 6 dimensions. Questions are camouflaged as casual conversation (penetration-type) or confirm previously inferred conclusions (verification-type):
- emotion — short-term state ("I feel...")
- psychology — medium-term stress ("lately I...")
- personality — long-term traits ("since I was a child...")
- attachment — relationship patterns
- selfWorth — self-esteem
- defense — how the user protects themselves
The architecture is designed for future expansion:
- Port/Server Mode — Replace the CLI entry with an HTTP server;
dispatcher.jslogic is reusable - Web Frontend — A basic Express server scaffold exists in
/web - Multi-User Support — Auth layer (email + SMTP verification) + SQLite database planned
MIT