|
| 1 | +--- |
| 2 | +title: "feat: Autoresearch Persona Optimizer Loop" |
| 3 | +type: feat |
| 4 | +status: active |
| 5 | +date: 2026-04-06 |
| 6 | +--- |
| 7 | + |
| 8 | +# Autoresearch Persona Optimizer Loop |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +Implement the core autoresearch iteration loop for persona prompt optimization. |
| 13 | +Following the Karpathy autoresearch pattern (`/Users/ataylor/code/tools/autoresearch/program.md`): |
| 14 | +run eval → read scores + feedback → modify persona → re-eval → keep/discard → repeat. |
| 15 | + |
| 16 | +The eval harness (`studyctl eval run`) already scores personas via Bedrock Sonnet 4.6. |
| 17 | +What's missing is the **optimizer** that automatically modifies persona files based on |
| 18 | +judge feedback, and the **loop** that iterates until success criteria are met or max |
| 19 | +iterations exhausted. |
| 20 | + |
| 21 | +## Current State (as of 2026-04-06) |
| 22 | + |
| 23 | +**Working:** |
| 24 | +- `studyctl eval run` — runs 7 scenarios via `claude -p` (print mode, no tmux) |
| 25 | +- Bedrock Sonnet 4.6 as LLM judge (us-west-2) |
| 26 | +- 7-dimension rubric scoring (clarity, socratic_quality, emotional_safety, etc.) |
| 27 | +- Judge returns actionable feedback (2-3 suggestions per scenario) |
| 28 | +- First passing scores: confused-student 75%, parking-lot 71.9% |
| 29 | + |
| 30 | +**Not working yet:** |
| 31 | +- No automatic persona modification based on feedback |
| 32 | +- No keep/discard loop (manual re-runs only) |
| 33 | +- No iteration tracking or convergence detection |
| 34 | + |
| 35 | +## Proposed Solution |
| 36 | + |
| 37 | +### New command: `studyctl eval optimize` |
| 38 | + |
| 39 | +```bash |
| 40 | +studyctl eval optimize --max-iterations 10 --agent claude |
| 41 | +``` |
| 42 | + |
| 43 | +### The Loop (modelled on autoresearch/program.md) |
| 44 | + |
| 45 | +``` |
| 46 | +LOOP (up to max_iterations): |
| 47 | + 1. Run eval (all 7 scenarios via claude -p + Bedrock judge) |
| 48 | + 2. If all scenarios pass (>= 70%) → DONE, commit persona |
| 49 | + 3. Collect feedback from failed scenarios |
| 50 | + 4. Call LLM optimizer: "Given these scores and feedback, modify the persona" |
| 51 | + 5. Apply modifications to persona files |
| 52 | + 6. Git commit the modified persona |
| 53 | + 7. Re-run eval |
| 54 | + 8. If avg score improved → KEEP (advance) |
| 55 | + 9. If avg score worsened → DISCARD (git reset to previous commit) |
| 56 | + 10. Log iteration to eval-results.tsv |
| 57 | +``` |
| 58 | + |
| 59 | +### The Optimizer (LLM-driven persona modification) |
| 60 | + |
| 61 | +The optimizer is itself an LLM call (Bedrock Sonnet/Opus) that: |
| 62 | +- Receives the current persona text |
| 63 | +- Receives the judge scores + feedback for each failed scenario |
| 64 | +- Returns a modified persona with specific changes |
| 65 | + |
| 66 | +```python |
| 67 | +def optimize_persona( |
| 68 | + current_persona: str, |
| 69 | + eval_results: list[JudgeResult], |
| 70 | + scenarios: list[Scenario], |
| 71 | +) -> str: |
| 72 | + """Use LLM to generate an improved persona based on judge feedback.""" |
| 73 | + # Build prompt with current persona + all scores + all feedback |
| 74 | + # Ask LLM to return the FULL modified persona text |
| 75 | + # Return the modified persona |
| 76 | +``` |
| 77 | + |
| 78 | +### Files to modify |
| 79 | + |
| 80 | +| File | Change | |
| 81 | +|------|--------| |
| 82 | +| `packages/studyctl/src/studyctl/cli/_eval.py` | Add `optimize` command | |
| 83 | +| `packages/studyctl/src/studyctl/eval/optimizer.py` | NEW — LLM-driven persona modifier | |
| 84 | +| `packages/studyctl/src/studyctl/eval/prompts/optimizer.md` | NEW — optimizer prompt template | |
| 85 | +| `packages/studyctl/src/studyctl/eval/orchestrator.py` | Add iteration loop with keep/discard | |
| 86 | + |
| 87 | +### Success criteria |
| 88 | + |
| 89 | +- [ ] `studyctl eval optimize --max-iterations 10` runs the full loop |
| 90 | +- [ ] Each iteration: eval → feedback → modify persona → re-eval → keep/discard |
| 91 | +- [ ] Git commit on keep, git reset on discard |
| 92 | +- [ ] Iteration history logged to eval-results.tsv |
| 93 | +- [ ] Loop stops when all 7 scenarios pass (>= 70%) or max iterations reached |
| 94 | +- [ ] Final optimised persona committed with iteration count in commit message |
| 95 | + |
| 96 | +### Key design decisions |
| 97 | + |
| 98 | +- **Optimizer model**: Same Bedrock model as the judge (Sonnet 4.6). Could use Opus for higher quality. |
| 99 | +- **Persona scope**: Modify `agents/shared/personas/study.md` (the main study persona). Other shared files (socratic-engine.md, break-science.md, etc.) are referenced but not modified by the optimizer — they're protocol docs, not persona instructions. |
| 100 | +- **Git branch**: Run on a dedicated branch (`autoresearch/persona-YYYYMMDD`), merge to main when optimised. |
| 101 | +- **Keep/discard threshold**: Keep if avg_score improves by any amount. Discard if equal or worse. |
| 102 | +- **Feedback aggregation**: Aggregate feedback from ALL failed scenarios into one optimizer call, not per-scenario. |
| 103 | + |
| 104 | +## References |
| 105 | + |
| 106 | +- Karpathy autoresearch pattern: `/Users/ataylor/code/tools/autoresearch/program.md` |
| 107 | +- Current eval harness: `packages/studyctl/src/studyctl/eval/` |
| 108 | +- Current persona: `agents/shared/personas/study.md` |
| 109 | +- Judge rubric: `packages/studyctl/src/studyctl/eval/prompts/judge-rubric.md` |
0 commit comments