Fine-Tuning a Model on Your Agent Traces: A Practical Guide A practical guide for ML engineers and CTOs argues that fine-tuning a smaller model on successful agent traces — a form of distillation — can cut the cost of routine agent traffic, citing a May 2026 step-rejection fine-tuning paper that added 2.4 points on SWE-bench Verified from training on successful runs and 3.7 points, reaching 32.2%, when individual steps were filtered with a critic model. A December 2025 study on on-policy expert corrections reported a relative 14% gain at 7B parameters and 13% at 32B over plain imitation on SWE-bench Verified, while a 2025 study on distilling LLM agents found 0.5B to 3B parameter agent-distilled models performed competitively with 1.5B to 7B chain-of-thought distilled models across eight tasks. The guide distinguishes supervised fine-tuning, distillation and reinforcement fine-tuning, and warns that long tasks are where student models break, citing an October 2026 progress-aware distillation paper. On this page 14 Your agent runs on a frontier model, and most of what it does is routine. Look up the order, call the refund tool, write a two-line reply. You pay frontier prices for every one of those steps. Meanwhile your trace logs hold thousands of runs where the agent did the job right, each one a worked example of the task. Fine-tuning on agent traces turns those runs into training data for a smaller model that can take the routine traffic. This guide is for ML engineers and CTOs running agents in production. It explains how distillation and fine-tuning relate, what recent research says about training on agent runs, and the pipeline from raw traces to a student model you can trust, with Python you can run and the tools worth using in late 2026. Distillation vs fine-tuning: the same training step, different data The two terms get used as if they were rivals. They are not. Most of the time, distillation is fine-tuning with a particular kind of data. Supervised fine-tuning SFT trains a model on examples of correct responses. Hugging Face’s TRL documentation https://huggingface.co/docs/trl/sft trainer calls it the simplest and most common way to adapt a language model to a dataset: the model learns to predict each token of the target response. Distillation transfers knowledge from a larger model, the teacher, to a smaller, cheaper one, the student. That is how Amazon Bedrock defines it https://docs.aws.amazon.com/bedrock/latest/userguide/model-distillation.html , and the idea goes back to Hinton and colleagues’ 2015 paper on compressing large models into small ones. OpenAI’s distillation guide https://developers.openai.com/api/docs/guides/distillation shows how the two meet in practice. You capture a large model’s responses, filter them, then fine-tune a smaller model on what is left. So when your traces come from a frontier model doing the work, fine-tuning a small model on them is distillation. Reinforcement fine-tuning is the different one. The model is not shown the right answer. It tries the task, a grader or the environment scores the attempt, and the model learns from the score. | Method | Training data | You need | Use it when | |---|---|---|---| | SFT on human-written examples | Responses written or corrected by people | Labeling time | No good model output exists yet | | Distillation SFT on teacher traces | Successful runs by a larger model | A trace store and an outcome signal | A frontier agent already does the job and you want it cheaper | | Reinforcement fine-tuning | Scores from a grader or environment | A reliable reward and an environment to run tasks in | You can check answers automatically and want to beat the teacher | This guide covers the middle row, because it is where most production teams start. Your agent is already generating the data. What research says about training on agent runs The results are real, but modest. Read the numbers before you promise anyone a frontier model at a tenth of the price. - Filtering for success helps, and finer filtering helps more. A May 2026 paper on step rejection fine-tuning https://arxiv.org/abs/2605.10674 found that training on successful runs added 2.4 points on SWE-bench Verified. Filtering individual steps with a critic model added 3.7, reaching 32.2%. - Correcting the student’s own mistakes beats pure copying. A December 2025 study on on-policy expert corrections https://arxiv.org/abs/2512.14895 reports a relative 14% gain at 7B and 13% at 32B over plain imitation on SWE-bench Verified. - Small agents can match bigger non-agent models. A 2025 study on distilling LLM agents https://arxiv.org/abs/2505.17612 found agent-distilled models of 0.5B to 3B parameters performed competitively with chain-of-thought distilled models of 1.5B to 7B across eight tasks. - Long tasks are where students break. An October 2026 paper on progress-aware distillation https://arxiv.org/abs/2610.19439 found that SFT-distilled small agents tend to stall and loop on long trajectories, across eight small models from 0.6B to 8B. The pattern for production: a fine-tuned student can take short, well-defined tasks. Keep long, open-ended runs on the teacher, at least until your own evaluation says otherwise. The pipeline from production traces to a deployable student Six steps, with a hard boundary in the middle. Personal data must be removed before traces leave your production environment for training. Production agent teacher: frontier model | traces: OpenTelemetry GenAI spans, Langfuse, LangSmith or Phoenix v Trace store <--- outcome labels from your systems | ticket resolved, tests passed, human approved v 1. Filter: complete runs with a successful outcome only v 2. Scrub personal data ===== trust boundary: production data ends here ===== v 3. Convert to chat JSONL with tools and tool calls v 4. Split by task: train set and held-out evaluation set v 5. LoRA fine-tune the student TRL, Unsloth or Axolotl v 6. Evaluate against the teacher -> shadow traffic -> router sends routine tasks to the student Step 1: Capture traces you can train on A useful trace holds the whole conversation: the system prompt, the tool definitions, every tool call with its arguments, every tool result and the final answer. Many tracing setups drop some of these by default. The OpenTelemetry GenAI agent conventions https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/gen-ai-agent-spans.md are still marked as in development. Message content gen ai.input.messages is opt-in and, in the spec’s own words, likely to contain sensitive data, so check that your setup records it at all. Observability tools differ in export formats. LangSmith exports datasets as JSONL or in OpenAI’s fine-tuning format, Phoenix exports OpenAI fine-tuning JSONL, and Langfuse exports CSV or JSON that you convert yourself. Whichever you use, check that tool calls survive the export before you build on it. Step 2: Keep only the runs that succeeded Filter on an outcome your business records, not on the model’s own claim that it finished. A support ticket that stayed closed, a pull request whose tests passed, a draft a human approved without edits. That is rejection sampling: keep the runs that passed, discard the rest. Also drop exact duplicates, which over-weight your most common request, and check the balance of task types. A dataset that is 90% password resets trains a password-reset model. Step 3: Scrub personal data before training Models can memorize training data and repeat it. A customer’s email address in a tool result can come back out of the student months later, in someone else’s conversation. Remove personal data before the traces leave production, and keep the scrubbed copy as the only training input. Step 4: Convert traces to a tool-calling dataset TRL’s SFTTrainer supports tool calling. Each row holds a messages list, with tool calls on assistant turns and tool messages for results, plus a tools column with the JSON schemas the agent had. Together AI’s fine-tuning service accepts the same conversational shape. The script below does steps 2 to 4. It expects one JSON object per line, with task id , outcome , tools and messages in the OpenAI chat format, which most tracing exports can be mapped to: prepare traces.py: turn exported agent traces into a TRL tool-calling dataset. Python 3.10+, standard library only. Usage: python prepare traces.py traces.jsonl import hashlib import json import re import sys Outcomes your system records when a run did the job not the model's own claim SUCCESS = {"resolved", "approved", "tests passed"} EVAL SHARE = 10 percent of tasks held out for evaluation A minimum, not a PII solution: emails, phone numbers and card-like numbers PATTERNS = re.compile r" \w.+- +@ \w- +\. \w.- +" , "