TL;DR
- You almost certainly do not need to fine-tune yet. Tools, context and a written persona fix more problems, faster, and cheaper.
- Fine-tune when you have a repeated, measurable failure and real examples of the correct behaviour — not because the topic sounds advanced.
- LoRA trains small adapters over a frozen base model: a fraction of the GPU memory and cost, a versionable file, one base model serving many adapters.
- Three objectives, one machine: SFT teaches what to say, DPO teaches what to prefer, RLHF optimises against a learned reward model.
- Data quantity matters less than data coverage: every real failure mode should appear in the training set with the right answer.
- Cost is a one-off training bill plus a smaller per-token bill — it beats a bigger model only at volume, and only if you already have a pipeline.
- Legally, keep provenance and PII scrubbing in place before the first run, not after.
- For agents, fine-tuning is the last step: persona and skill first, tool schemas next, measurement always, tuning only for the one thing that keeps breaking.
What fine-tuning actually changes
Three things can change a model's behaviour: the prompt (what you ask, at inference), the context (what you retrieve and put in front of it), or the weights (what the model has learned). Fine-tuning is the third one. It bakes a behaviour into the model so you no longer have to describe it — or describe it badly, which is what happens when every prompt is 2,000 tokens of instructions and examples.
That framing matters because each lever has a different cost curve. Prompts cost tokens on every single call and change instantly. Retrieval costs a search per call and needs a corpus you maintain. A fine-tune costs training time once, needs data you keep collecting, and is baked in until you retrain. People reach for the most expensive lever first when the cheapest one was enough.
The decision in one table
Try these first, in this order:
| If the problem is… | Use | Why |
|---|---|---|
| The model does not know your domain facts | Retrieval (RAG) | Facts change weekly; weights do not |
| The model ignores your format or persona | Prompt + a tool schema + a written persona | Free to change, instant to test |
| The model keeps calling one tool wrong | Tool description repair first, then SFT on real calls | Most "model mistakes" are schema mistakes |
| The model is too slow or too expensive per call | Distillation, caching, a smaller model, batching | Latency and cost are architecture, not training |
| The model reliably fails one specific behaviour, and you have examples | Fine-tuning (SFT, maybe DPO) | This is the case fine-tuning is actually for |
| You need genuinely new capability the base model lacks | Full fine-tuning, or a different model | LoRA cannot teach what the base does not represent |
Four kinds of training data
Fine-tuning is one pipeline with four input shapes. Confusing them is the most common source of wasted compute, because people collect the wrong data and then blame the trainer.
| Type | Input shape | Teaches | Typical use |
|---|---|---|---|
| Supervised fine-tuning (SFT) | (instruction, ideal answer) | What to say | Output format, tone, a specific task, tool-call format |
| Preference optimisation (DPO and relatives) | (instruction, chosen, rejected) | What to prefer | Style, tone, refusal behaviour, tie-breaking between valid answers |
| Reward modelling + RLHF | (instruction, human ranking) | What scores well | Highest quality ceiling, highest operational cost |
| Continued pretraining | Raw documents | What the world looks like | Domain language, terminology, a very large corpus |
For an agent, SFT on real trajectories is the workhorse: the instruction the agent received, the tools it had, the actions it took, and the outcome. That is a different dataset from "questions and answers", and it is the one that fixes tool-calling behaviour.
How much data is enough? A worked example
Everything below is an assumption you replace with your own. The point is the shape of the calculation, not the constants.
| Input | Assumed value | Why it matters |
|---|---|---|
| Distinct observed failure modes | 12 | The real requirement is one clean example per failure mode — not a corpus size |
| Examples per failure mode | 20 | Variations: different phrasings, different tools, edge cases |
| Minimum training set | 240 examples | 12 × 20. A realistic floor for a narrow behaviour change |
| Validation split | 10% (24) | Held out, never trained on, used for every checkpoint comparison |
| Test (golden) set | 50 cases | Real production failures, frozen, versioned with every run |
| Training epochs | 2–3 | More epochs on a small set is how you overfit |
Now the cost side, with assumptions stated:
| Assumption | Value | Note |
|---|---|---|
| Base model size | 7–8B parameters | The sweet spot for a single consumer GPU with LoRA |
| LoRA rank | 16–64 | Higher rank = more capacity = more memory; start low |
| Quantisation | 4-bit base weights | The single biggest memory saving; the usual default |
| Training examples | 240 (above) | Small run, minutes to hours on a single GPU |
| Training time | 30–90 minutes | Assumption for a dataset this size; grows roughly linearly with examples × epochs |
| Cost per training run | a few dollars on a rented GPU | Do not quote this as a price — rental rates move; the shape (small, one-off) does not |
| Adapter size on disk | tens to a few hundred MB | The point of LoRA: the deliverable is small and versionable |
The important conclusion is not the dollar figure — it is that a narrow behaviour change is a small, cheap, repeatable job. The expensive part is not the training run. It is collecting examples, keeping them clean, and evaluating honestly. Budget your effort accordingly.
LoRA vs full fine-tuning
| Dimension | LoRA (adapter) | Full fine-tuning |
|---|---|---|
| Weights updated | Small low-rank adapters; base frozen | All weights |
| GPU memory | Fraction of full training | Substantially higher; needs multi-GPU at scale |
| Cost per run | Low | High |
| Artifact | A small adapter file you can diff, tag and roll back | A new full checkpoint (tens of GB) |
| Serving many variants | One base model + many adapters | One model per variant |
| Can it teach new knowledge? | Weakly — it mostly reshapes behaviour | Yes, given enough data and compute |
| Risk | Lower blast radius; the base model stays intact | Catastrophic forgetting of general capability is possible |
| Best first use | Format, style, tool-call convention, a narrow agent behaviour | Domain adaptation at scale, a new capability |
Rule of thumb
If you cannot describe the behaviour you want in one sentence, you cannot fine-tune for it — and you probably should not. If you can, and you have 200+ examples, LoRA is the answer.
The pipeline, end to end
- Collect. Log real interactions: the instruction, the context, the tool calls, the outcome, and the human correction when there was one. The corrections are the gold: a failed trajectory plus the correct one is a training pair for free.
- Filter. Drop examples with secrets, personal data, or a broken tool schema. This is also where you enforce the legal constraints: if an example is not lawfully usable, it does not enter the dataset, regardless of how much it would help.
- Format. Convert to one consistent schema — the same one the model sees at inference. A mismatch between training format and serving format is the most common cause of "it worked in the lab and fails in production".
- Split. Hold out a validation set for checkpoint selection and a frozen golden set for the final judgement. If either set leaks into training, every number you report afterwards is fiction.
- Train. LoRA first. Small rank, low learning rate, 2–3 epochs, checkpoint often. Log the loss but decide on the validation metric, never on the training loss.
- Evaluate. Run the golden set. Compare against the untuned base model on the same cases. Keep the run only if it wins on the metric you care about — and check it did not quietly lose the general capability you rely on elsewhere.
- Ship behind a flag. Serve the tuned model for a slice of traffic, keep the base model as the fallback, and log both. A fine-tune that regresses on 2% of cases will find those 2% if you can roll back.
- Monitor and retrain. The world moves: tools change their schemas, users phrase things differently. A fine-tune is a snapshot with an expiry date.
Seven ways fine-tuning goes wrong
- Training on data you cannot use. Customer content, scraped pages, or a competitor's outputs. The dataset is the liability, not the model. Provenance must exist before the run, not after a complaint.
- Format mismatch. The trainer sees a slightly different schema than production. The model learns a format that never occurs in anger.
- Leaky evaluation. The golden set ends up in training. Every metric looks excellent and nothing improves in production.
- Catastrophic forgetting. The tuned model loses the general ability you relied on elsewhere because you fine-tuned on a narrow slice and never measured the rest.
- Overfitting to a small set. 240 examples trained for 12 epochs produces a model that recites them. The symptom is a model that is perfect on your test set and brittle on anything new.
- Optimising the wrong metric. Loss went down, user-visible behaviour did not change. If the metric is not the behaviour, the run is decoration.
- Silent capability regression. The model gets better at the tuned task and worse at the thing your agent depends on elsewhere. Without a general-capability check you find out from a customer, not from a dashboard.
Evaluating a fine-tune honestly
| Metric | What it answers | Trap |
|---|---|---|
| Task success rate | Does it do the job? | Aggregates across task types and hides the one that broke |
| Format validity | Is the output parsable? | Measure with a parser, not with eyeballs |
| General-capability check | Did it forget anything? | Skipping this is how a tuned model quietly becomes worse |
| Refusal / escalation rate | Does it hand back when it should? | A model that never escalates is usually a model that guesses |
| Cost per successful task | Is the new model actually cheaper end to end? | Compare against the base model, including retries |
| p90 latency | Does it fit the product? | Mean latency hides the tail entirely |
An LLM-as-judge is a reasonable way to score open-ended outputs, but it inherits the judge model's biases and is easy to fool with formatting. Use it as one signal among several, calibrate it against human labels on a sample, and never let it be the only thing that decides.
Serving a tuned model
- Quantise for inference. 4-bit weights cut memory and latency roughly in half relative to 16-bit, with a small quality cost you must measure — not assume — against your golden set.
- Serve the adapter, not a copy. With LoRA, the base model is loaded once and the adapter is swapped. This is what makes dozens of specialised agents affordable on one machine.
- Keep the interface identical. The tuned model must accept the same prompt format, the same tool schema and the same context window as before, or every caller needs changing. This is the single biggest reason a fine-tune gets rolled back.
- Watch the memory wall. Quantised weights plus KV cache plus a long context is where a "7B model" quietly needs 24 GB of RAM. If you run agents headless on a VPS, size the box for the context, not for the parameters. Our best VPS comparison for OpenClaw covers the specs and real monthly prices for that.
Where this fits in an agent stack
Fine-tuning is the bottom layer of the stack, and the layer you should reach for last. The order that works:
- Persona and skill. A written persona (a SOUL.md) states the role, the success criteria and the stop conditions. It is free to change and it fixes a surprising share of "the agent does not behave" complaints. The 5 free SOUL.md templates are a working starting point.
- Tool schemas. A precise tool description is worth more than a thousand training examples, because it removes the ambiguity the model has to guess at. The MCP Server Development Kit is about making that boundary clean and enforceable.
- Context discipline. What to keep between steps, what to summarise, what to drop — the Context Engineering Field Kit covers it. Most "the model is dumb" complaints are context problems.
- Measurement. Before any training run you need the eval rig, or the training run is a shot in the dark. The Agent Eval & Observability Kit is that layer — and it is what tells you whether a fine-tune is even the right move.
- Then, and only then, the fine-tune. One behaviour, a few hundred examples, a held-out golden set, LoRA, measured, shipped behind a flag.
When to stop
If after a measured, documented fine-tune the success rate has not moved, stop. Every further hour of data collection is a bet that the problem is the weights when it was never the weights.
Everything above, packaged
The Complete Bundle ($29) ships all 10 tools — including the MCP Server Development Kit, the Context Engineering Field Kit and the Agent Eval & Observability Kit — at 71% off the individual prices. Start smaller if you prefer: the 5 free SOUL.md templates cost nothing.
Frequently asked questions
Do I need to fine-tune an LLM to build an AI agent?
Almost never, at first. Agents work because of tools, context and instructions, and all three are cheaper to change than a checkpoint. Fine-tuning becomes worth it when you have a specific, repeated, measurable failure — the model keeps calling a tool with the wrong arguments, or ignoring a format, or answering in a voice your users reject — and you have a few hundred to a few thousand real examples of the correct behaviour. Until then, prompting plus a tool schema plus a clear persona gets you further, faster, and cheaper.
What is LoRA and when should I use it instead of full fine-tuning?
LoRA (Low-Rank Adaptation) trains small low-rank matrices that are attached to the weights of a frozen base model, instead of updating all the weights. That means far less GPU memory, a fraction of the training cost, a small adapter file you can version like code, and the ability to serve many adapters over one base model. Use LoRA when your task is a behaviour or style change on a model you cannot re-host cheaply. Use full fine-tuning only when you need to add genuinely new knowledge or capabilities, you have serious GPU budget, and you own the serving stack.
How much data do I need to fine-tune?
Enough to cover the cases that actually fail, and not much more. For a behaviour change — a specific output format, a tool-call convention, a tone — a few hundred high-quality examples often move the metric more than ten thousand noisy ones. For broad new capability you need orders of magnitude more. The number that matters is not the count but the coverage: every distinct failure mode you have seen should appear in the training set with the correct answer. A worked example with explicit assumptions appears below.
Is fine-tuning cheaper than using a bigger model?
Often, at volume; rarely, at the start. A fine-tune costs you a one-off training bill plus serving infrastructure plus the ongoing work of data collection and evaluation. A bigger model costs you nothing to set up and more per token, forever. The break-even usually shows up when the task is high-volume and the per-token gap is multiplied by every request. The honest framing: fine-tuning is an optimisation of an existing pipeline, not a replacement for having a pipeline.
What is the difference between SFT, DPO and RLHF?
They are three different training objectives on the same machinery. SFT (supervised fine-tuning) trains on (prompt, ideal answer) pairs — it teaches the model what to say. DPO (Direct Preference Optimization) trains on (prompt, chosen, rejected) triples and teaches it what to prefer between two answers without an explicit reward model. RLHF trains a reward model from preferences and then optimises the policy against it — more moving parts, more compute, historically the best quality. In practice: start with SFT for format and style, add DPO when you have preference pairs, and reach for RLHF only when you have the data pipeline and the evaluation rig to support it.
How do I know if my fine-tune actually helped?
You need a held-out evaluation set that you never trained on, and a metric that reflects the task rather than the vibes. Build a golden set from real production cases, keep a version of it with every training run, and measure: task success rate, format validity, refusal rate, cost per successful task, and p90 latency. If you cannot describe the metric before you train, you are not fine-tuning, you are gambling.
What are the legal and privacy risks of fine-tuning on my own data?
They are real and they are not solved by a terms-of-service click. You need to know where every training example came from and whether you are allowed to train on it: customer data usually has contractual and regulatory constraints (PII, GDPR-style erasure rights, sector rules), third-party content usually carries licences that do not permit training, and your own past model outputs are not automatically yours to train on. Keep provenance for every example, scrub PII before it reaches the trainer, and write down the retention and deletion path before the first run.
Where does fine-tuning fit in an agent stack like OpenClaw?
At the bottom, as an interchangeable model behind a tool-using loop — not as a substitute for the loop. The order that works in practice: write the persona and the skill (SOUL.md) and the tool schemas first, measure what actually breaks, and only then consider training a model to do the one thing that keeps breaking. The MCP Server Development Kit covers the tool side of that stack and the Context Engineering Field Kit covers the context side; a tuned model is the last step, not the first.