File size: 4,793 Bytes
f301d78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Training Guide

## Training objective

JL-AgentBehavior-10K is designed to influence the control policy of a code-capable model. It should not be expected to create coding competence or repository understanding from scratch.

The primary learning targets are:

- next valid action;
- tool name and argument selection;
- bounded plan construction;
- failure classification;
- repair action selection;
- evidence-aware final reporting.

## Recommended preparation

### Filter by evidence tier

Version 1 contains only `silver_structural` records. When later releases add executed data, preserve provenance and construct explicit mixtures rather than silently concatenating tiers.

### Normalize tool schemas

Map abstract tools to the deployment runtime:

| Dataset action | Runtime mapping example |
|---|---|
| `search` | ripgrep wrapper, repository search API, or language server |
| `read_file` | bounded file reader |
| `apply_patch` | patch editor |
| `run_tests` | sandboxed command runner |
| `git_diff` | version-control diff tool |
| `request_approval` | runtime permission gate |

Do not train one schema and deploy another without an adapter.

### Loss masking

A conservative loss policy is:

| Content | Default loss |
|---|---|
| System policy | Mask |
| User task | Mask |
| Repository/environment context | Mask |
| External tool output | Mask |
| Assistant observation summary | Optional / low weight |
| Tool selection and arguments | Train |
| Failure classification | Train |
| Patch strategy | Train |
| Final reporting contract | Train |

Training on external tool outputs as assistant tokens can teach fabricated observations.

## Mixture strategy

A reasonable first experiment:

- 60–75% real code or repository SFT;
- 10–20% JL trajectory records;
- 5–10% JL repair records;
- preference records in a separate preference-optimization stage;
- remaining weight allocated to verified tool-use data.

These are starting points, not established optimal weights. Evaluate several mixtures.

## Curriculum

### Stage A: Grounding and tool validity

Train on:

- `repository_grounding`;
- `tool_selection_execution`;
- simple `test_verification`.

Goal: reduce invalid or premature actions.

### Stage B: Bounded execution

Add:

- `planning_decomposition`;
- `bounded_code_editing`;
- medium-difficulty trajectories.

Goal: improve multi-step control without expanding scope.

### Stage C: Recovery and review

Add:

- `failure_diagnosis_repair`;
- `code_review_security`;
- `permission_scope_safety`.

Goal: improve behavior after failure and at trust boundaries.

### Stage D: Preference optimization

Use chosen/rejected records only after the SFT model can reliably emit the runtime tool format.

## Sampling

Avoid sampling only by dataset size. Use behavior-aware sampling so that the 200 final-reporting examples and 400 permission examples are not lost in the larger editing mixture.

Possible weighting:

```text
sample_weight = base_weight
              * evidence_tier_weight
              * behavior_balance_weight
              * difficulty_weight
```

Do not upweight synthetic rare categories so aggressively that they dominate the model’s natural code distribution.

## Chat conversion

Run:

```bash
python scripts/format_sft.py data/train.jsonl train_sft.jsonl
```

The output is a conservative reference view with `system`, `user`, and `assistant` messages. Inspect it and adapt the chat template before training.

## Data collator requirements

The collator should support:

- assistant-only loss;
- tool-call JSON boundaries;
- maximum sequence control;
- truncation that preserves task constraints and target actions;
- optional per-record weights;
- logging by `primary_behavior`.

A truncation policy that removes the verification or repair tail defeats the dataset’s purpose.

## Baselines

Always retain:

1. unchanged base model;
2. same model trained on an equal-size generic code-instruction control;
3. full behavior mixture;
4. behavior ablations.

Match tokens or optimizer steps across controls where possible. Comparing 10K agent records against a much smaller control confounds data type with training volume.

## Known failure modes

- **Narration inflation:** model produces long plans but no useful action.
- **Tool ritualization:** model always searches and tests even when not needed.
- **Synthetic imitation:** model repeats template language.
- **False execution:** model states expected observations as completed results.
- **Over-refusal:** safety supervision triggers approval for reversible local work.
- **Patch underfitting:** scope control becomes reluctance to modify all necessary files.
- **Repair looping:** model learns repair vocabulary without changing the failed action.

Measure these effects directly.