tx

tx reflect

Run session retrospective to analyze agent behavior and tune approach

Purpose

tx reflect aggregates data across recent agent sessions to produce a structured retrospective. It surfaces metrics on throughput, proliferation, stuck tasks, and actionable signals.

Two tiers:

  • Data tier (default): SQL queries produce structured metrics. No LLM required.
  • Analysis tier (--analyze): Feeds metrics to an LLM for synthesis and recommendations.

Usage

tx reflect [options]
# Last 10 sessions (default)
tx reflect

# Last 5 sessions
tx reflect --sessions 5

# Last hour's activity
tx reflect --hours 1

# JSON output for scripting
tx reflect --json

# With LLM analysis
tx reflect --analyze

# Combine options
tx reflect --sessions 5 --hours 2 --analyze --json
import { TxClient } from '@jamesaphoenix/tx-agent-sdk'

const tx = new TxClient({ dbPath: '.tx/tasks.db' })

const result = await tx.reflect.run({ sessions: 5 })
// {
//   sessions: { total: 5, completed: 3, failed: 1, timeout: 1, avgDurationMinutes: 12.5 },
//   throughput: { created: 20, completed: 8, net: 12, completionRate: 0.4 },
//   proliferation: { avgCreatedPerSession: 4, maxCreatedPerSession: 10, maxDepth: 3, orphanChains: 1 },
//   stuckTasks: [...],
//   signals: [...],
//   analysis: null
// }

Tool name: tx_reflect

{
  "name": "tx_reflect",
  "arguments": {
    "sessions": 5,
    "hours": 2,
    "analyze": true
  }
}
ArgTypeRequiredDescription
sessionsnumberNoNumber of recent sessions (default: 10)
hoursnumberNoTime window in hours
analyzebooleanNoEnable LLM analysis (requires ANTHROPIC_API_KEY)
GET /api/reflect?sessions=5&hours=2&analyze=true

Example:

curl http://localhost:3456/api/reflect?sessions=5

Output

Signals

Machine-readable flags for orchestrator integration:

SignalSeverityMeaning
HIGH_PROLIFERATIONcriticalMore tasks created than completed
STUCK_TASKSwarningTasks with 3+ failed attempts
DEPTH_WARNINGwarningMax depth exceeds guard limit
PENDING_HIGHinfoMany pending tasks

Orchestrator Integration

#!/bin/bash
# Auto-tune based on reflect signals
SIGNALS=$(tx reflect --hours 1 --json | jq -r '.signals[].type')

if echo "$SIGNALS" | grep -q "HIGH_PROLIFERATION"; then
  tx guard set --max-pending 20 --enforce
  tx compact
fi

if echo "$SIGNALS" | grep -q "STUCK_TASKS"; then
  STUCK=$(tx reflect --json | jq -r '.stuckTasks[].id')
  for id in $STUCK; do
    tx update "$id" --status blocked
  done
fi

Configuration

[reflect]
default_sessions = 10

The --analyze flag requires ANTHROPIC_API_KEY to be set. Without it, only the data tier (structured metrics) is available.

  • tx guard — Set task creation limits (tune with reflect signals)
  • tx verify — Attach machine-checkable done criteria
  • tx label — Scope ready queue by phase
  • tx compact — Archive completed tasks

On this page