A/B testing infrastructure for validating Claude agent integration in RL training...
| Item | Details |
|---|---|
| Date | 2026-02-18 |
| Goal | Determine if Claude agent integration improves model predictive power |
| Status | v2.4 showed agents HURT performance (fitness -38.2%, PF -6.3%). v3.0 implements guardrails: phase gates, cumulative entropy bounds, fitness-gated checkpoints, rollback, institutional knowledge, agent memory persistence. Awaiting re-run. |
| Files | scripts/agent_validation_experiment.py, notebooks/agent_validation_analysis.ipynb, alpaca_trading/training/multi_agent.py, alpaca_trading/training/agent_memory.py, alpaca_trading/gpu/vectorized_env.py, tests/test_multi_agent.py |
Does integrating Claude agents during RL training provide measurable improvement to model quality?
The codebase has ~4,744 lines of agent integration code. Before relying on it:
| Metric | Baseline | Treatment | Change |
|---|---|---|---|
| Profit Factor | 1.191 | 1.115 | -6.3% |
| Fitness Score | 0.110 | 0.068 | -38.2% |
| Reward-to-Risk | 0.075 | 0.047 | -37.1% |
| Final Equity | 1.014 | 1.009 | -0.5% |
AAPL hit hardest (-12.9% PF, -51.6% fitness); GOOGL roughly neutral (+1.3% PF). Cohen's d > 0.9 (large effect) but p-values > 0.12 (underpowered with n=6).
lr_scheduler.step() (line 986) overwrites agent LR changes on the very next PPO update. current_entropy_coef has NO scheduler, so entropy changes persist and compound._cumulative_entropy_multiplier across all adjustments[0.5x, 1.5x] of initial value (configurable)_apply_action() callcurrent_fitness > self._best_fitness_best_checkpoint_path for rollbackrollback (aliases: restore_best, revert, load_checkpoint)trainer.load(path)adjust_lr always returns rejection message: "LR managed by cosine schedule"AgentMemory class in agent_memory.py stores RunSummary per symbolmemory_dir| Group | Description | Agent Integration |
|---|---|---|
| Baseline (Control) | Standard NativePPOTrainer | None |
| Treatment | MultiAgentTrainer with agents | Hyperparameter Tuner, Risk Analyst, Reward Engineer |
equal_var=False): More appropriate for small samples with potentially unequal variances| Metric | Minimum Improvement | Statistical Significance |
|---|---|---|
| Profit Factor | +0.2 (e.g., 1.5 β 1.7) | p < 0.0083 (Bonferroni) |
| Sharpe/Reward-to-Risk | +0.1 | p < 0.0083 |
| Max Drawdown | -2% (e.g., 12% β 10%) | p < 0.10 |
| Consistency | +3% (e.g., 62% β 65%) | p < 0.0083 |
| Result | Action |
|---|---|
| 2+ metrics significantly improved | Activate agents in production |
| 1 metric improved, others neutral | Use agents in advisory mode only |
| No significant improvement | Disable agents, save ~$350/year |
| Performance degraded | Do NOT use agents |
data/agent_memory/ with action outcome trackingANTHROPIC_API_KEY environment variable setagent_config = MultiAgentConfig(
enable_hyperparameter_tuner=True,
enable_risk_analyst=True,
enable_reward_engineer=True,
enable_data_monitor=False,
enable_backtest_validator=False,
max_consultations_per_run=50,
log_agent_responses=True,
# v3.0: Reduced intervals
hyperparam_interval=8,
risk_interval=5,
reward_interval=15,
# v3.0: Phase gates
no_intervention_before_pct=30.0,
entropy_decrease_only_after_pct=50.0,
# v3.0: Cumulative entropy bounds
max_cumulative_entropy_multiplier=1.5,
min_cumulative_entropy_multiplier=0.5,
# v3.0: Agent memory
memory_dir='data/agent_memory',
symbol=symbol,
)
| Resource | Estimate |
|---|---|
| Training runs | 12 (6 baseline + 6 treatment) |
| Compute time | ~3-4 hours on A100 (~53-83 CU) with pre-computed obs |
| API costs | ~$15 (6 treatment runs x ~$2.50/run with reduced consultations) |
| Storage | ~200 MB (models + logs + memory) |
| Attempt | Date | What Happened | Root Cause | Fix |
|---|---|---|---|---|
| v1.0 | 2026-02-01 | Zero agent consultations across all 10 treatment runs. | validation_interval mismatch: With 50M timesteps, only 4-5 validation cycles happened. Agent intervals rarely aligned. | train_with_guidance() auto-adjusts validation_interval to ensure β₯15 cycles. |
| v1.1 | 2026-02-04 | "Parent directory checkpoints does not exist" error. | Missing directory creation in _apply_action(). |
Added os.makedirs(parent, exist_ok=True) before save. |
| v1.2 | 2026-02-05 | All HP tuner recommendations identical. Risk Analyst fixated on KL. Wrong weights in RE prompt. | 7 systemic problems: No per-run context, fixed DD threshold, no component breakdown, KL over-emphasized. | v2.0: Rewritten prompts, per-component metrics, adaptive drawdown. |
| v2.0 | 2026-02-07 | +11.6% PF (p=0.009) but 5 bugs: ~50% RA parse failures, invalid grace period type, unknown action types. | 5 code bugs: max_tokens too low, grace periodβinvalid type, no validation. | v2.1: 5-strategy parser, VALID_ACTION_TYPES, max_tokensβ1500. |
| v2.1 | 2026-02-10 | Notebook 401 errors, quick validation >10 min. | API key parsing: Naive line reading sent "Key:" as API key ID. | Use _read_keys_from_file(). Quick val: 2M steps, val_interval=5. |
| v2.2 | 2026-02-16 | 200M production mode = ~29 CU/model, 580 CU total. Exceeded budget. | Compute cost too high. | 50M standard mode, 3 seeds, incremental save/resume. ~70-95 CU. |
| v2.3 | 2026-02-17 | 50M standard still ~162 CU. 116 min/model (7,200 FPS). | GPU env bottleneck: .item() calls, Python loops, 50+ tensor ops. |
v2.4: Pre-computed obs via unfold(). 15K-25K FPS, ~53-83 CU. |
| v2.4 | 2026-02-18 | Agents HURT performance: Fitness -38.2%, PF -6.3%. Entropy increases compounded, agents misdiagnosed normal dynamics, LR changes are no-ops. | 5 root causes: Compounding entropy, misdiagnosis, wrong timing, checkpoint spam, LR no-ops. | v3.0: Phase gates, cumulative bounds [0.5, 1.5], fitness-gated checkpoints, rollback, LR disabled, institutional knowledge, agent memory, RE read-only. |
Entropy increases at 63% progress undo 30M+ steps of learned policy. The model has developed trading strategies by this point; increasing exploration forces it to "forget" them.
Profit factor naturally oscillates during training. A single validation with PF < 1.0 is not a crisis. Only 3+ consecutive declining validations are meaningful.
The cosine LR scheduler calls lr_scheduler.step() every PPO update, overwriting any agent modification to param_group['lr']. Only current_entropy_coef persists because it has no scheduler.
v2.4 saved 4-5 checkpoints per model, none were ever loaded. Checkpoints only have value if paired with a rollback mechanism triggered by fitness decline.
The v2.4 experiment proved that intervention is destructive. 80%+ of consultations should result in "continue". Active intervention should be rare (<20%).
_get_observations() achieved only 7,200 FPS on A100 due to:
.item() calls (3 per step): Forces CUDA sync_precompute_observation_windows() at init pre-computes all features via unfold() (~30 MB). Rewritten _get_observations(): ~120 lines (was ~350), zero .item(), zero Python loops, ~10 gather ops.
Old code used env_ids[0].item() for ALL envs β wrong observations for recently-reset envs. New code uses per-env index tensors.
scripts/agent_validation_experiment.py - Experiment runnernotebooks/agent_validation_analysis.ipynb - Statistical analysis (Welch's t-test + Bonferroni)alpaca_trading/training/multi_agent.py - Agent integration (v3.0: guardrails, phase gates, rollback)alpaca_trading/training/agent_memory.py - Persistent cross-run learning (v3.0)alpaca_trading/gpu/vectorized_env.py - Component metrics + adaptive drawdown + pre-computed obsalpaca_trading/gpu/ppo_trainer_native.py - Metrics pipeline, LR schedulertests/test_multi_agent.py - 62 tests: prompt correctness, metrics flow, phase gates, cumulative tracking, fitness-gated checkpoints, rollback, LR disabled, agent memory, institutional knowledge.skills/plugins/trading/multi-agent-integration/ - Integration documentation