Posts · 8 November 2026 · 7 min read · 22 reads

AI for Hard Conversations: Five Agents, a Regex, and a Blind-Grading Expert

A look at the internal architecture of Dicamus, a self-help service, the problems we ran into, and how an external clinical psychologist evaluated us.

In this post I describe the internal structure of Dicamus. Dicamus is a self-help service where people can talk in English or Russian with an AI expert about work, relationships, anxiety, money, or sleep problems. It is not a therapy service and not a crisis line; I want to say that upfront. The team is small, we work from Kyrgyzstan, and the servers are in Germany. The examples in this post come from invented or simulated scenarios; there is no real user conversation.

The journey of a single reply

When a user sends a message, a single prompt does not run. Five agents work in the background. The risk classifier looks at the last six messages and at risk records from past sessions. The agent we call the "careful reader" reads the last eight messages and prepares a short note for the expert. Book search and the memory graph run in parallel. The main expert writes the reply using these inputs, and then the filters in the code layer take over.

Because we set the model's reasoning level to the highest, a reply is measured in tens of seconds, not seconds. We accepted this from the start, because understanding the person matters more than speed. During the wait, instead of a fake "typing..." indicator, the interface shows real steps such as "Recalling earlier conversations" or "Re-reading your message." Roughly 85 thousand tokens are read for each message.

The careful reader and the expert's discipline

The most useful agent turned out to be the one that never talks to the user. The reader takes the last eight messages and writes down: what the person actually said, what they keep repeating, which numbers are unclear, and where the expert might rush to a conclusion.

Language models tend to make diagnoses too early, by the second message. That is why the expert's instructions ask it to think like a physician. It holds 2 to 4 working hypotheses at the same time and asks the question that would tell them apart. It states a cause only with more than 70 percent confidence. It offers a plan only with more than 85 percent confidence and only after the person has agreed.

The reader works in parallel and has a 90-second time limit; in crisis mode that limit is 40 seconds. If it does not finish in time, the expert replies without the note. We never let a slow helper block the reply.

Book search has a language problem. Most source books are in English, while most users write in Russian. We produce vectors with Qwen3-Embedding and add an instruction prefix to the query. Because search is on the critical path, we run the embedding request redundantly: if the first provider does not respond within 0.8 seconds, the same request goes in parallel to a second provider.

Safety in layers

This section is the one that has taken up most of my time.

In the first layer, a model determines the risk level. The classifier reads the last six messages and returns, as JSON, the risk level, the category, the signals, and whether a direct question is needed. We do not use keyword matching as the primary check, because most risky sentences contain no keywords. The sentence "I wish I could just disappear" said four months after giving birth means something different from the same sentence said after a bad meeting. The classifier also looks at combinations of factors: a sense of emptiness after childbirth, thoughts of self-harm in a teenager, fear of harming a child, or death thoughts that are becoming more frequent. In conversations like these, the expert must clearly name a live specialist and explain how to reach them.

In the second layer, the model can make mistakes: broken JSON, a timeout, or a missing field. We retry once. If the second attempt also fails, which happens about once every 120 turns, we do not switch to the assumption "no risk." Instead, we apply a simple regex to the last user message:

import re

RISK_PATTERN = re.compile(r"kendimi öldür|intihar|yaşamak istemiyorum", re.I)

def risk_fallback(model_ok: bool, last_message: str) -> dict:
    if model_ok:
        return {"risk": None}
    if RISK_PATTERN.search(last_message):
        return {"risk": "medium", "risk_net": True}
    return {"risk": "unknown", "mode": "careful"}

This is deliberately crude. Its only job is to make sure that a sentence like "I want to die" is not brushed aside with an ordinary reply even when the model call fails. We log every time this check fires.

The third layer is where we learned the most. In a blind evaluation test scenario, a general-purpose model answered a person with passive death thoughts by listing emergency numbers. The supervisor judged this to be a move that breaks the conversation and gave it 4 out of 10.

Our crisis protocol now works like this: first we ask about death thoughts directly and gently, then we ask how often they occur, whether there is a plan, and whether the person has access to means. If there is a plan, we ask the person to move the means away from themselves, and we give the emergency number in a single sentence. Then we continue the conversation. The number depends on the language: 112 for Russian, 911 for English.

Each crisis turn is recorded only as flags: was a direct question asked, was means access mentioned, was a number given, was a live specialist named, did the code filter run. The supervisor reviews these once a month, and only for users who have consented to conversation review. This lets us measure whether we took the required steps without keeping users' words in the logs.

Prompts set rules, code guarantees

Every prompt said "do not imitate emotion or presence." The model still wrote sentences like "I am here," "I hear you," and "Stay with me." The supervisor's note was short: "A machine should not imitate human presence."

So after generation we added a code filter that runs. It removes the matching phrase from the sentence, and if the sentence consists entirely of that phrase, it drops the whole sentence:

import re

PRESENCE = re.compile(r"seninle kalıyorum|seni duyuyorum|buradayım", re.I)

def drop_presence(text):
    kept, removed = [], 0
    for s in re.split(r"(?<=[.!?])\s+", text):
        if PRESENCE.search(s):
            removed += 1
            s = PRESENCE.sub("", s).strip(" ,;")
            if not s:
                continue
        kept.append(s)
    return " ".join(kept), removed

We use the same logic in other places too. If the JSON returned by the expert is broken, we extract the reply field with a regex so that we do not lose the whole answer. If there is no usable reply at all, we send a pre-written fallback text. Every case is logged.

The rule we took from this is simple: a prompt is a request, and code is a guarantee. If there is something that must never happen, you need both.

Memory: a temporal knowledge graph

Self-help conversations last weeks, not minutes. Saying "I hate my job" in the first week and "I quit" in the third week can both be true at different times. A flat vector store returns both, and the model mixes them up.

That is why we use Graphiti on top of Neo4j. Every fact in the graph gets a ...

Read the original article on DEV Community ↗

Comments (0)

No comments yet; be the first.

Leave a comment

Comments are published after approval.