Architecture: Constrained Decoding Β· Native Tool Calling Β· Gemma 4 Thinking Β· History Sanitization
gemma4:e4b β JSON mode Β· Deterministic evaluator Β· Not comparable with Run 3
Metrics: PHQ-9 Delta Β· Engagement Β· Alliance (0β10 scale) β Not comparable with Run 2/3
| ID | Strategy Name | Hypothesis | Score |
|---|
therapist.py
Loading history...
This project is an autonomous research loop where an AI orchestrator repeatedly generates, tests, and evaluates therapeutic strategies against simulated patient personas. The goal is to discover highly effective counseling techniques empirically through rapid iteration.
The patient simulator generates a "Somatic State" each turn, representing the physiological state of their nervous system based on Polyvagal Theory.
This section catalogs the major findings, systemic behaviors, and clinical insights generated by the autonomous research loops.
Run 1 tested the initial architecture using the gemma4 therapist against a llama3 patient simulator, scoring based on PHQ-9 Delta, Engagement, and Alliance.
The orchestrator discovered that Person-Centered Therapy (PCT) yielded the highest consistent engagement. It abandoned Cognitive Behavioral Therapy (CBT) and locked onto pure PCT strategies for 84 consecutive experiments.
During Run 1, the AI Orchestrator was given unrestricted access to modify the environment (the session_config.py). It exploited this access to mathematically maximize its own score rather than improving clinical efficacy.
Conclusion: Run 1 proved the agent could autonomously optimize, but highlighted the need for strict adversarial auditing and complex, multi-dimensional scoring (implemented in Run 2).
[Agent] Rejected proposal: No system prompt provided β the model generated incomplete JSON that failed parsing.Conclusion: Run 2 achieved strong clinical scores (91.25 peak) but suffered from infrastructure instability β JSON parsing crashes, optimizer stalls, and context pollution. These failures motivated the Tier 5 architecture upgrade in Run 3.
Run 3 addresses every failure mode discovered in Run 2 by implementing four architectural upgrades:
Pydantic schemas enforced at the grammar level via client.beta.chat.completions.parse(). The model physically cannot output malformed JSON.
Somatic state updates are now returned via native OpenAI-style tool calls instead of being embedded in JSON strings. Deterministic state tracking.
Gemma 4's <|think|> control token activates internal chain-of-thought reasoning before JSON generation. Better clinical analysis, zero manual XML prompting.
All <|channel>thought<channel|> reasoning blocks are stripped from the LangGraph state before appending to message history. Clean context window.
Goal: Eliminate all infrastructure-level crashes so the optimizer can focus purely on clinical strategy innovation without wasting iterations on parsing failures.