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 --jsonimport { 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
}
}| Arg | Type | Required | Description |
|---|---|---|---|
sessions | number | No | Number of recent sessions (default: 10) |
hours | number | No | Time window in hours |
analyze | boolean | No | Enable LLM analysis (requires ANTHROPIC_API_KEY) |
GET /api/reflect?sessions=5&hours=2&analyze=trueExample:
curl http://localhost:3456/api/reflect?sessions=5Output
Signals
Machine-readable flags for orchestrator integration:
| Signal | Severity | Meaning |
|---|---|---|
HIGH_PROLIFERATION | critical | More tasks created than completed |
STUCK_TASKS | warning | Tasks with 3+ failed attempts |
DEPTH_WARNING | warning | Max depth exceeds guard limit |
PENDING_HIGH | info | Many 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
fiConfiguration
[reflect]
default_sessions = 10The --analyze flag requires ANTHROPIC_API_KEY to be set. Without it, only the data tier (structured metrics) is available.
Related Commands
tx guard— Set task creation limits (tune with reflect signals)tx verify— Attach machine-checkable done criteriatx label— Scope ready queue by phasetx compact— Archive completed tasks