Agents

Agent Therapy

Agent Therapy is a self-reflection system that logs mood signals, failure patterns, and performance notes for each agent. Over time it surfaces systematic issues and suggests prompt improvements.

How it works

  1. Journal entries after each session — At the end of every completed session, the therapy system writes a journal entry capturing the outcome signals: tool errors, user correction events, task completion status, and response latency
  2. Mood scoring — A composite mood score (0.0–1.0) is computed from the session signals. High task completion, low error rate, and positive user feedback push the score up; tool failures, user rephrasing, and abandoned sessions push it down
  3. Pattern analysis — Periodically (configured by analysisWindowDays), the therapy system runs a pattern analysis pass over the journal. It clusters failure types, identifies recurring triggers, and generates a plain-language suggested_fix — typically a targeted prompt amendment or a skill configuration change

Journal entry structure

FieldTypeDescription
timestampISO 8601UTC time the session ended
mood_scoreFloat 0.0–1.0Composite mood score for the session; lower is worse
failure_typeString or nullCategorical label for the primary failure mode (e.g., tool_loop, context_overflow, user_abandon)
noteStringFree-text summary of what went wrong or what went well
suggested_fixString or nullActionable prompt or config change generated during analysis; null until first analysis pass

Viewing therapy logs

bash
# Retrieve raw journal entries for an agent
GET /agents/:id/therapy/journal

# Query with filters
GET /agents/:id/therapy/journal?mood_max=0.4&limit=50

# Retrieve pattern analysis results
GET /agents/:id/therapy/patterns

# Retrieve the most recent suggested fixes
GET /agents/:id/therapy/patterns?type=suggested_fixes

Configuration

yaml
therapy:
  enabled: true
  moodThreshold: 0.4         # Alert when rolling average mood drops below this value
  analysisWindowDays: 14     # Number of days of journal data included in each analysis pass
Therapy data feeds directly into persona evolution. When the rolling mood score falls below moodThreshold, the evolution system is signaled to generate and test new prompt variants, using the therapy journal's suggested_fix entries as seed material for variant generation.