DEV Community

CBT Tools
CBT Tools

Posted on

I Built 3 AI Agents for Mental Health Analysis and Submitted Them to an AI App Store

I've been building mental health tools with vanilla JavaScript for a while — 24 standalone CBT (Cognitive Behavioral Therapy) tools that run entirely in the browser, no backend, no signup, no ML. But recently I wondered: what if I could package the analysis logic as AI agents and put them on a marketplace?

So I built 3 agents and submitted them to aitopia.ai, an AI App Store with a credit-based monetization system and a 70/30 BYOM (Bring Your Own Model) revenue split. Here's the architecture.

The 3 Agents

1. CBT Thought Analyzer

Analyzes text for 10 cognitive distortions (all-or-nothing thinking, overgeneralization, mental filter, disqualifying the positive, jumping to conclusions, magnification, emotional reasoning, should statements, labeling, personalization). Each detected distortion comes with a CBT reframe.

2. Procrastination Pattern Detector

Identifies 8 procrastination patterns: perfectionism block, fear of failure, task overwhelm, waiting for motivation, task avoidance, all-or-nothing approach, guilt-procrastination cycle, and minimization trap. Each pattern includes a behavioral activation intervention.

3. Attachment Style Detector

Classifies attachment into 4 types based on Bartholomew (1990): Secure, Preoccupied/Anxious, Fearful, and Dismissing/Avoidant. Each type comes with CBT-based guidance for relationship patterns.

The Architecture

User → aitopia.ai marketplace → my Render endpoint → CBT detection logic → response
Enter fullscreen mode Exit fullscreen mode

The key design decision: remote_http agent type. Instead of uploading a model bundle to the marketplace, I host the analysis logic on my own server and aitopia.ai proxies user invocations to my endpoint. This means:

  • I keep full control of the detection logic
  • I can update the algorithms without re-deploying to the marketplace
  • The endpoint is a standard HTTP API — no special runtime needed

The Endpoint

The server is a Python FastAPI app deployed on Render:

@app.post("/analyze")
async def analyze_thoughts(request: Request):
    data = await request.json()
    text = data.get("text", "")
    distortions = detect_distortions(text)
    return {"distortions": distortions, "count": len(distortions)}

@app.post("/procrastination")
async def detect_procrastination(request: Request):
    data = await request.json()
    text = data.get("text", "")
    patterns = detect_patterns(text)
    return {"patterns": patterns, "count": len(patterns)}

@app.post("/attachment")
async def detect_attachment(request: Request):
    data = await request.json()
    responses = data.get("responses", [])
    style = classify_attachment(responses)
    return {"style": style, "guidance": get_guidance(style)}
Enter fullscreen mode Exit fullscreen mode

The Detection Logic

No machine learning. No NLP libraries. No sentiment analysis. Just keyword-pattern matching — the same approach I use in my browser-based CBT toolkit:

DISTORTIONS = {
    "all_or_nothing": {
        "keywords": ["always", "never", "completely", "totally", "absolute"],
        "reframe": "Is it really 100% or 0%? What would 80% look like?"
    },
    "overgeneralization": {
        "keywords": ["everything", "nothing", "everyone", "no one", "always"],
        "reframe": "One instance doesn't define a pattern. What's the evidence?"
    },
    # ... 8 more distortions
}

def detect_distortions(text):
    text_lower = text.lower()
    found = []
    for name, data in DISTORTIONS.items():
        matches = [kw for kw in data["keywords"] if kw in text_lower]
        if matches:
            found.append({
                "distortion": name,
                "matched_keywords": matches,
                "reframe": data["reframe"]
            })
    return found
Enter fullscreen mode Exit fullscreen mode

Why rule-based instead of ML? For mental health analysis:

  • Determinism: Same input → same output every time. Non-determinism is a bug in a clinical tool.
  • Explainability: The matched keywords ARE the explanation. No black box.
  • Zero latency: No model inference, no API calls to an LLM.
  • Zero cost: No per-request API fees.
  • Privacy: Thoughts stay on the server, never sent to a third-party LLM.
  • Small known output space: 10 distortions from decades of CBT research. You don't need a language model to classify into 10 categories.

The Submission Process

Each agent was submitted to aitopia.ai with:

  • Agent type: remote_http (aitopia.ai calls my endpoint)
  • Pricing: byom (Bring Your Own Model) — 5 credits per run
  • Endpoint URL: https://cbt-thought-analyzer.onrender.com/analyze (or /procrastination or /attachment)
  • Revenue split: 70/30 (I keep 70% of paid credits)

The validation process checked:

  1. Namespace — my developer namespace (octoberk)
  2. Pricing — BYOM model with 5 credits/run
  3. Endpoint health — aitopia.ai actually called my Render endpoint to verify it responds

All 3 passed validation. They're now in the review queue awaiting admin approval.

Honest Status

The agents are in review, not yet live. I don't know the review timeline — the docs 404. It could be hours, days, or weeks. Revenue is $0 until at least one agent is approved and users start invoking it.

But the architecture works. The endpoint is live and responding. The detection logic is functional. And the marketplace model (remote_http + BYOM) means I don't have to upload anything — just register a URL.

What I Learned

  1. AI agent marketplaces are real — aitopia.ai has a developer program, SDK, and revenue split. This isn't vaporware.
  2. remote_http is the right model for analysis APIs — you keep control of the logic and the marketplace handles distribution + billing.
  3. Rule-based > ML for constrained clinical domains — when the output space is 10 categories from decades of research, you don't need a language model.
  4. One FastAPI server, 3 routes, 3 agents — YAGNI. Don't deploy 3 separate services when 3 routes on one server works.

Try It

The CBT toolkit (24 browser-based tools, no signup) is at github.com/alexcoledev/cbt-toolkit.

The API endpoint is live at https://cbt-thought-analyzer.onrender.com/analyze — you can POST a JSON body with a "text" field and get back detected cognitive distortions with reframes.

The agents are pending review on aitopia.ai. If they get approved, I'll write a follow-up on the revenue numbers.


This is not medical advice. CBT tools are educational, not a substitute for professional therapy.

Top comments (0)