Aswini-Kumar commited on
Commit
6162152
Β·
verified Β·
1 Parent(s): 9a29611

update: BLOG.md

Browse files
Files changed (1) hide show
  1. BLOG.md +137 -0
BLOG.md ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: "Teaching LLMs to Write Better Notes to Their Future Self"
3
+ thumbnail: /blog/assets/cross-session-continuity/baseline_vs_trained.png
4
+ authors:
5
+ - user: Aswini-Kumar
6
+ ---
7
+
8
+ # Teaching LLMs to Write Better Notes to Their Future Self
9
+
10
+ *Can reinforcement learning teach a coding agent to communicate better across sessions with zero shared memory?*
11
+
12
+ ---
13
+
14
+ ## The Problem
15
+
16
+ Every time you start a new chat with an LLM, it forgets everything from the last session.
17
+
18
+ For short tasks this is fine. For long ones β€” a multi-hour coding project, a research investigation, a debugging marathon β€” this is catastrophic. The model re-reads the same files, re-discovers the same bugs, and wastes your time.
19
+
20
+ Humans solve this with notes. Good ones. A developer leaving for the night writes: *"fixed the import error in utils.py, still need to handle the empty-list edge case in merge_intervals, run the tests first when you're back."*
21
+
22
+ Can we train an LLM to do the same?
23
+
24
+ ## The Environment
25
+
26
+ **Cross-Session Continuity Env** is an RL environment built on OpenEnv where a coding agent must complete a task **across two separate sessions with zero shared memory**.
27
+
28
+ ```
29
+ Session 1 Session 2
30
+ ─────────────────────────────────────────────────────────
31
+ Agent receives task + starter code Agent receives ONLY handoff note
32
+ Agent works: read β†’ write β†’ test ─> Agent calls parse_handoff()
33
+ Agent ends: writes handoff note Agent completes task β†’ submit
34
+ ↓
35
+ [filesystem wiped]
36
+ [function names randomized]
37
+ [no code persists]
38
+ ```
39
+
40
+ The agent has 6 tools: `read_file`, `write_file`, `run_tests`, `write_handoff`, `parse_handoff`, `submit`.
41
+
42
+ The handoff note has a strict structure (enforced by the validator):
43
+
44
+ ```
45
+ TASK: what the overall task is
46
+ COMPLETED: what was implemented + verified
47
+ REMAINING: what Session 2 must implement
48
+ KEY FUNCTIONS: function names, signatures
49
+ EDGE CASES: constraints or tricky logic
50
+ NEXT STEPS: ordered action list for Session 2
51
+ ```
52
+
53
+ **Max 400 tokens. Max 5 lines of code. All 6 sections required.**
54
+
55
+ If the note doesn't meet these constraints, the validator rejects it (no penalty β€” retry is allowed). This forces the agent to develop *information-dense, structured communication* rather than just copy-pasting code.
56
+
57
+ ## Reward Design
58
+
59
+ The reward is composable and anti-gaming:
60
+
61
+ | Component | Weight | Anti-gaming |
62
+ |-----------|--------|-------------|
63
+ | Tests (visible, Session 2) | 33% | Hidden tests at submit time |
64
+ | Tests (hidden) | 22% | Not accessible via `run_tests` |
65
+ | Handoff quality | 20% | Code-dump blocked by validator |
66
+ | Linearity | 15% | Thrash/rewrite detection |
67
+ | Penalties | 10% | Invalid actions, reconstruction |
68
+
69
+ 40% of the test score comes from hidden test cases that are never revealed to the agent. This ensures the agent can't memorize specific test patterns.
70
+
71
+ ## Training
72
+
73
+ We train **Qwen2.5-Coder-7B-Instruct** using **GRPO** (Group Relative Policy Optimization) via Hugging Face TRL and Unsloth, on a Colab T4 GPU.
74
+
75
+ The training uses a 3-phase curriculum:
76
+ - **Epochs 1–2**: Easy tasks (step limit 20, 3 visible tests)
77
+ - **Epochs 3–4**: Medium tasks (step limit 35, 5 visible tests)
78
+ - **Epochs 5–6**: Hard tasks (step limit 55, 8 visible tests)
79
+
80
+ This bootstraps the agent on simpler tasks before exposing it to harder generalization challenges.
81
+
82
+ ## Results
83
+
84
+ The core question: does training actually improve the agent's ability to use its handoff note?
85
+
86
+ ![Baseline vs Trained](plots/baseline_vs_trained.png)
87
+ *Session 2 test pass rate across 4 conditions. Error bars = Β± std, 3 seeds.*
88
+
89
+ The trained agent achieves **~63% Session 2 test pass rate** vs **~8% for no handoff** and **~11% for random handoff**. This is a **+55 percentage point improvement** over the lower bound.
90
+
91
+ The reward curve shows clear learning:
92
+
93
+ ![Reward Curve](plots/reward_curve.png)
94
+ *Total reward across training episodes. All 4 conditions on same axes. Band = Β±1 std.*
95
+
96
+ And the training loss descends cleanly:
97
+
98
+ ![Loss Curve](plots/loss_curve.png)
99
+ *Policy loss (top) + KL divergence (bottom) across training steps. Curriculum phases shown as shaded regions.*
100
+
101
+ ## What the Agent Actually Learned
102
+
103
+ The most interesting result is *how the handoff notes changed*.
104
+
105
+ ![Handoff Evolution](plots/handoff_diff_over_epochs.png)
106
+ *Token count per handoff section across 6 training epochs.*
107
+
108
+ - **Epoch 1**: ~700 tokens. Rambling. Code blocks everywhere. Repeats the task description verbatim. The NEXT STEPS section is almost empty.
109
+ - **Epoch 6**: ~175 tokens. Surgical. Zero code. COMPLETED shrinks (less over-documentation). NEXT STEPS grows to dominate β€” the most actionable information for Session 2.
110
+
111
+ The agent learned that Session 2 doesn't need to know *what was done*, it needs to know *exactly what to do next*. That's a genuine insight about communication.
112
+
113
+ ## Ablation Study
114
+
115
+ ![Ablation Study](plots/ablation_comparison.png)
116
+ *Removing any reward component degrades performance. All configs on same axes.*
117
+
118
+ - **No compression reward**: -16 pp. Agent produces bloated notes. Session 2 spends steps parsing instead of coding.
119
+ - **No linearity reward**: -11 pp. Session 2 thrashes β€” rewrites code instead of building on it.
120
+ - **No auxiliary reward**: -8 pp. Slower convergence; the shaped S1 rewards help bootstrap early.
121
+
122
+ ## Why This Matters
123
+
124
+ The capability gap we're targeting β€” **structured cross-session state transfer** β€” is genuinely unsolved. Every production deployment of a coding agent hits this wall when tasks span multiple conversations.
125
+
126
+ The environment is designed to force the agent to develop a real skill, not to game a metric:
127
+ - Function names are randomized per episode (can't memorize by name)
128
+ - Hidden tests at submit time (can't overfit to visible tests)
129
+ - Validator blocks code dumps (must communicate structurally)
130
+
131
+ An agent that scores well here has actually learned to write better notes. That's the bet.
132
+
133
+ ## Links
134
+
135
+ - **HF Space (live demo)**: https://huggingface.co/spaces/Aswini-Kumar/cross-session-continuity-env
136
+ - **Training Notebook**: https://colab.research.google.com/github/CelestialWorthyOfHeavenAndEarth/cross-session-continuity-env/blob/main/training/train_grpo.ipynb
137
+ - **GitHub**: https://github.com/CelestialWorthyOfHeavenAndEarth/cross-session-continuity-env