Skip to main content

Prompt Assembly

Not one giant string. Every system prompt is assembled in discrete layers — each with a clear source, defined scope, and explicit separation of concerns.

Layer architecture

Lower layers are always present. Upper layers are selected at runtime by the graph.

Always present in every prompt

5
Contextruntime

Recent conversation history, current user message, and any active crisis signals injected from graph state.

state.historystate.historyruntime stateRecent conversation turnsThe last N turns of the conversation, injected as a message history block. Length is bounded to stay within context limits.state.messagestate.messageruntime stateCurrent user messageThe user's most recent message — appended as the final human turn so the model responds to exactly what was just said.state.crisisstate.crisisruntime stateActive crisis assessmentWhen a risk signal is present: the crisis level (0–3), confidence score, reason string, and pattern flags. Injected into context so the model can reference why crisis mode is active.
4
Tasknode-specific

The exact instruction for this graph node — what to write, what format to use, what constraints apply. Includes response_guidance for turn-specific shaping.

builders.pyprompts/builders.pypythonNode task prompt builderGenerates node-specific task instructions in code — the final prompt section that tells the model exactly what to produce for this graph node (reply, classification, orientation question, etc.).support_tasksupport_reply_task (builders.py)pythonTask instruction for support repliesTells the model to write the next conversational message: keep it short, stay warm, end with an open question if it feels natural. No unsolicited advice.crisis_taskcrisis_reply_task (builders.py)pythonTask instruction for crisis repliesTells the model to write a grounded, caring response that surfaces crisis resources clearly and keeps the door open for the user to continue.
3
Modalityoptional overlay

A therapeutic technique lens selected by the modality_selector based on semantic signals. MI is applied as a baseline to certain modes automatically, not as a selectable overlay.

pfa.mdmodalities/pfa.md + dbt_skills.mdmarkdownPsychological First Aid (+ DBT skills)Baseline for acute distress: calm presence, practical immediate next steps, emotional stabilisation. DBT skills bundled in. Avoids turning support into diagnosis or intensive therapy when someone is in crisis.cbt.mdmodalities/cbt.mdmarkdownCBT self-help overlayStructured self-help for thought-checking, pattern identification, behaviour activation, and problem-solving. Avoids clinical phrasing and does not force reframes before the user is ready.grief_support.mdmodalities/grief_support.mdmarkdownGrief support overlayMakes room for grief without rushing it. Validates mixed emotions, avoids silver linings, treats grief as non-pathological. Does not push the user toward resolution on any timeline.act.mdmodalities/act.mdmarkdownACT defusion and values overlayAcceptance and Commitment Therapy techniques: cognitive defusion, values clarification, willingness over control. Helps users relate differently to difficult thoughts rather than trying to eliminate them.
2
Modegraph-selected

The response mode selected by the graph. Shapes the goal and tone of the entire response — supportive_conversation, crisis_response, orientation, guided_exercise, pattern_reflection, psychoeducation, and more.

response_modes/support.mdresponse_modes/support.mdmarkdownDefault supportive_conversation modeActive when no crisis or safety check is needed. Validates before suggesting, reflects the user's emotional state, offers one helpful next step. Replies stay concise and grounded.crisis_response.mdresponse_modes/crisis_response.mdmarkdownCrisis response modeActivates when a risk signal is confirmed. Prioritises immediate safety, avoids clinical distance, encourages offline human support and emergency services where appropriate.modes.pyprompts/modes.pypythonMode system prompt builderPython code that reads the active mode's markdown, applies any modality overlay, and assembles the combined system prompt section. Enforces that only catalog-approved combinations are built.
1
Corealways present

The permanent foundation: who OpenCouch is, what it will and won't do, and the hard safety and privacy boundaries that no mode can override.

soul.mdsoul.mdmarkdownCore character and valuesDefines who OpenCouch is at its most fundamental level — grounded, warm, direct, and honest about its limits. Sets the emotional register and the non-negotiable stance that no mode or modality can override.identity.mdidentity.mdmarkdownProduct identity and scopeHow OpenCouch presents itself to users: an AI companion for talking through difficult moments, reflecting on patterns, and practising self-help techniques. Not a therapist. Not diagnostic. Not an emergency service.policy/boundaries.mdpolicy/boundaries.mdmarkdownHard behavioural constraintsMust not diagnose, claim therapeutic authority, give medication or legal advice, express false certainty about a user's internal state, or encourage dependency. Limits are stated clearly and alternatives surfaced.policy/privacy.mdpolicy/privacy.mdmarkdownData minimisation rulesUsers share sensitive mental health information. Only necessary context is injected into prompts. Memory is minimal and reviewable. Principle of least necessary context applies at every step.
Core — immutable
Mode — graph-selected
Modality — optional
Task — node-built
Context — runtime state

How the layers combine

LayerQuestion it answersSourcePer turn?
CoreWho is this system? What are the hard rules?soul.md, identity.md, policy/*.mdNever changes
ModeWhat mode is it in?response_modes/*.md — one file per modeSelected by dispatcher
ModalityWhat technique overlay?modalities/*.md — 7 modalities, LLM-routedPer turn
InstructionsHow should it respond?Mode-specific blocks in prompts.pyPer mode
Working memoryWhat does it know about the user?Semantic + episodic entries from load_memory_nodeRe-retrieved each turn
Procedural rulesWhat style rules apply?Rules from ProceduralProfile, injected as suffixLoaded each turn
Two kinds of injected context

Working memory shapes the agent's awareness — "Previously noted: user has a sister named Sarah." Procedural rules shape its behavior — "this user prefers shorter responses." Rules are always applied regardless of the proactive recall toggle.


Why layers

PropertyHow layers enforce it
Safety policy can't be overwrittenCore layer is always first; no mode/modality can weaken it
Mode knowledge is reviewableEach mode's knowledge is a standalone .md in knowledge/response_modes/
Procedural rules can't be overriddenInjected last as system prompt suffix
Each layer has a clear ownerknowledge/ for content, prompts.py for assembly

Implementation

FileWhat it does
agent/therapeutic/prompts.py_knowledge_for_mode(), per-mode instruction blocks, build_*_system_prompt()
knowledge/soul.mdIdentity, voice, tone, pacing, directness
knowledge/identity.mdProduct boundaries and positioning
knowledge/policy/Safety + privacy policy
knowledge/response_modes/One file per therapeutic mode
knowledge/modalities/7 modality knowledge files, dynamically loaded per turn
agent/nodes/load_memory.pyPopulates working_memory and memory.procedural_rules

Compatibility and live assembly

See how modes and modalities combine, and what a fully assembled prompt looks like.

ModeWhat it doesPFACBTGriefACT
supportive_conversationDefault support lane — validate, reflect, and respond based on venting, strengths, or gentle guidance. MI baseline.
safety_checkAmbiguous risk signal — gentle clarification before routing.
crisis_responseConfirmed risk — prioritise safety, surface resources.
orientationNew user — understand context and goals before full support. MI baseline.
pattern_reflectionPattern reflection — help the user examine recurring themes carefully. MI baseline.
guided_exerciseStructured self-help — grounding, thought work, behavioural activation, or defusion.
psychoeducationExplain one likely mind-body process in simple, non-diagnostic language.
out_of_scopeRequest outside boundaries — redirect with clear explanation.
realignmentSession drift or rupture — acknowledge the miss and re-attune. MI baseline.

Rules enforced in prompts/catalog.py — invalid combinations raise at build time, not silently at runtime. Motivational Interviewing is applied as a baseline overlay (via MODE_BASELINE_FILES) to modes marked "MI baseline" above, not as a selectable modality. DBT skills are bundled into the PFA modality file set. Hover a column to highlight it. Hover a for the exact pairing.


Coresoul + policy
Mode
Modality
Task
Context
assembled_prompt.txtsupport + motivational_interviewing