# Train on traces

Upload recorded conversations, tool calls included, and train a model on them with SFT or On-Policy Distillation (OPD).

A traces dataset holds whole conversations in the OpenAI chat format, for example logs from a deployed assistant or agent, or answers from a stronger model you want a smaller one to learn from. It needs no column mapping, prompt template or reward function.

## File format

Each row is one conversation:

- `messages` (required): the conversation in order, as `system`, `developer`, `user`, `assistant` and `tool` messages. Every row needs at least one `assistant` message.
- `tools` (optional): the tools the model could call.

```json
{"messages": [{"role": "user", "content": "I can't sign in, MFA keeps failing."}, {"role": "assistant", "content": null, "tool_calls": [{"id": "c1", "type": "function", "function": {"name": "lookup_user", "arguments": "{\"email\": \"a@b.com\"}"}}]}, {"role": "tool", "tool_call_id": "c1", "content": "{\"locked\": true}"}, {"role": "assistant", "content": "Your account was locked. I've sent an unlock link."}], "tools": [{"type": "function", "function": {"name": "lookup_user", "parameters": {"type": "object", "properties": {"email": {"type": "string"}}}}}]}
```

The rules that matter most:

- Answer every tool call with a `tool` message carrying the same `tool_call_id` before the next `assistant` message. Only the last assistant message’s calls may go unanswered.
- Every `assistant` message trains unless it has `"weight": 0`, which makes it context only. Two trained assistant messages can’t sit next to each other.
- `assistant` messages may carry the model’s reasoning in `reasoning_content`.

Other columns stay with the row and training ignores them.

### Files Arena accepts

Upload one JSONL or Parquet file, upload a folder of Parquet files laid out like a Hugging Face dataset, or import a Hugging Face dataset. In Parquet, store `messages` and `tools` as JSON text. Arena reads each file in one of three layouts and converts it to `messages`:

| The file has                                                 | Arena reads it as                                                                                                                                       |
|--------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| `prompt` and `completion` columns                            | Pairs. Each becomes a conversation, and only the completion trains.                                                                                     |
| A `messages` column                                          | Conversations, as they are                                                                                                                              |
| A `conversations` column of ShareGPT turns (`from`, `value`) | ShareGPT. Turns become messages, and Hermes-style `<tool_call>`, `<tool_response>` and `<think>` blocks become tool calls, tool messages and reasoning. |

A `<tool_call>` or `<tool_response>` block converts when it is closed and its body is a JSON object, so prose that mentions the tags is left alone. In a tool turn made only of `<tool_response>` blocks, a block whose body isn’t JSON, such as a Python dict or cut-off JSON, becomes that tool result’s text with the tags removed.

Tool use written as text in any other way, such as `<function_call>` tags or tool results in a `user` turn, stays in the message text and trains as answer text, not as a tool call. Arena flags it: a note under the configuration on Hugging Face import, a **Tool calls are written as text** notice on the dataset’s **Data** tab, and a **Tool calls in text** badge on each such conversation.

A row whose `label` is false (`false`, the text `"false"` in any case, or `0`) is skipped, so only completions labelled true train. Any other `label` value stays as a column.

Per-call logs often repeat a conversation once per model call, each a longer prefix of the next. Arena keeps only the longest, so every turn trains once. When this happens, **Conversations** on the dataset’s **Data** tab shows how many pairs they came from, for example `Converted from 38 pairs`.

## Upload a traces dataset

### Web app

1. Open **Datasets** in the sidebar, click **New dataset** and pick **Type** **Traces**.
2. Enter a **Dataset name**.
3. Under **Select dataset**, do one of these:
   - Click **Upload a JSONL or Parquet** and pick your file.
   - Click **Upload a folder** and pick a folder of Parquet files named by split, such as `default/train-00000-of-00001.parquet`, one folder per configuration. Pick the configuration in **Select configuration** when it holds more than one. Every split of the configuration is imported into the dataset, and a folder with more than one split needs a `train` split.
   - Search Hugging Face and pick a configuration in **Select configuration**. Only configurations Arena can import as traces are listed; **Has labels** marks one with a `label` column. When it has more than one split, **Split** picks the one to import, `train` by default, and leaves the others out for evaluation. **All splits** imports every split instead, and runs train on `train`.
4. Click **Save**.

Arena opens the dataset on **Data**. A summary card counts the **Conversations**, the **Assistant turns** that train and those that are context only, the **Tools** (**Browse tools** lists them), and, when rows were skipped, how many are **Skipped**, with **Review** for each reason and how to fix it. A warning shows when 10% or more of the rows were skipped. Under it, **Conversations** previews the stored conversations, with a search over message text, reasoning and tool calls. Pick one to read its **Messages**, **Tools**, **Other fields** and **JSON**; assistant turns with `"weight": 0` show as context.

### CLI

```bash
arena datasets create helpdesk-traces --category traces --file ./conversations.jsonl
```

`--category traces` takes no column mapping. Arena checks the file on your machine before it uploads. Flags are in the [command reference](../cli/command-reference.md).

A row that breaks the rules is skipped and the rest are stored. The dataset says how many rows were skipped and why, and you can download the skipped rows as JSONL with **Download Rejected Rows** under **Skipped rows**, fix them and upload again. The upload fails only when no row passes, or when a JSONL line isn’t a JSON object.

## Choose SFT or OPD

| Method                          | What the model learns from                                                                  |
|---------------------------------|---------------------------------------------------------------------------------------------|
| **SFT**                         | The recorded assistant turns. The model learns to write them.                               |
| **OPD** with a separate teacher | A teacher model’s scores of the student’s own replies. The trace only supplies the prompts. |
| **OPD** with self-distillation  | The student itself, shown the recorded reply as a hint, scoring the student’s own replies.  |

OPD needs no reward function. Without one, the run learns from the teacher alone. From the CLI you can add one with `--reward-file`, and it is mixed in with the teacher’s signal.

## Worked example: Capybara

This imports `trl-lib/Capybara` (about 16,000 multi-turn chats) as a traces dataset, then trains `Qwen/Qwen3.5-0.8B` on it with SFT and with OPD in self-distillation mode. Both runs stop at 20 steps.

### Web app

1. **New dataset** → **Type** **Traces**. Name it `capybara-traces`, search `trl-lib/Capybara`, pick configuration `default`, keep **Split** on `train` and click **Save**. The `test` split is left out.
2. In your project, click **New experiment**. On **Environment**, select `capybara-traces` and click **Next**.
3. On **Agent**, pick **SFT** and the model `Qwen/Qwen3.5-0.8B`.
4. On **Training**, set **Maximum Number of Training Steps** to `20`. On **Summary**, click **Train**.

For the OPD run, start a second experiment and pick **OPD** on **Agent**. Under **Teacher**, leave **Teacher source** on **Same as student (self-distillation)**. To use another model as teacher, choose **Separate model** and pick a **Teacher model**. Arena only lists models that share the student’s vocabulary, and the teacher needs extra GPUs.

### CLI

```bash
arena datasets create capybara-traces --category traces \
  --hf-dataset trl-lib/Capybara --hf-config default --hf-split train
```

`--hf-split` is required. Unlike the web app, the CLI imports every split of the configuration, so this dataset holds the `train` and `test` conversations.

Save the SFT manifest as `sft.yaml`:

```yaml
algorithm:
  name: SFT
environment:
  name: capybara-traces
  env_type: dataset
  objective: sft
  dataset: capybara-traces
  dataset_format: traces
network:
  pretrained_model_name_or_path: Qwen/Qwen3.5-0.8B
  max_context_length: 2048
training:
  max_steps: 20
```

Save the OPD manifest as `opd.yaml`. `teacher: {}` means self-distillation. For a separate teacher, set `teacher.model.pretrained_model_name_or_path`. The lower `gpu_memory_utilization` leaves room for the rollout engine on L4 GPUs.

```yaml
algorithm:
  name: OPD
  batch_size: 4
  group_size: 2
  max_output_tokens: 256
  teacher: {}
  vllm_config:
    gpu_memory_utilization: 0.8
environment:
  name: capybara-traces
  env_type: rollout
  dataset: capybara-traces
  dataset_format: traces
network:
  pretrained_model_name_or_path: Qwen/Qwen3.5-0.8B
  max_context_length: 2048
training:
  max_steps: 20
```

Check both, then submit:

```bash
arena manifest validate sft.yaml
arena manifest validate opd.yaml
arena memory estimate opd.yaml --gpu "NVIDIA L4" --num-gpus 4
arena experiments submit sft.yaml --project my-project --experiment-name capybara-sft
arena experiments submit opd.yaml --project my-project --experiment-name capybara-opd
```

Follow the runs in [Monitor, halt and resume](monitor-halt-resume.md).
