The Inference Company

How to fine-tune an open-source LLM for your AI agent

Updated 2026-10-03

To fine-tune an open-source LLM for an AI agent, train it on your agent's own recorded sessions: the tool calls and edits from tasks that succeeded. Start with supervised fine-tuning on successful trajectories, then use your success signal, such as tests passing, as a reward. Judge the result by cost per successful task on held-out tasks, not by training loss.

When is fine-tuning worth it?

Fine-tune when an open model is close but not quite there on your tasks: it fails in repeatable ways, takes too many turns, or misuses your tools. Don't fine-tune to teach facts that change; give the agent a tool to look them up instead. And try a stronger base model or a better prompt first, because both are cheaper than training.

The payoff is usually one of two things: a large model that succeeds more often on your work, or a smaller, cheaper model that matches a large one on your narrow set of tasks.

What data do you need?

The best training data is your agent's own sessions. Every task already records the conversation, the tool calls and their results. Add the outcome, did the task succeed, and you have labelled trajectories.

  • Keep the successes. Trajectories that ended in a passing test or a resolved ticket show the model what to do.
  • Keep the failures too. They are the negative examples for preference training and reinforcement learning.
  • Hold some back. Set aside tasks the model never trains on, so you can measure it fairly.
  • Strip secrets. Remove keys, credentials and personal data before training.

A few hundred good trajectories are enough to change behaviour on a narrow task. A few thousand cover a broad agent.

LoRA or full fine-tuning?

LoRA trains a small set of extra weights on top of the frozen model. It needs far less GPU memory, trains quickly, and one base model can serve many LoRA adapters at once, which keeps serving cheap. Full fine-tuning updates every weight. It can learn more, but it needs much more memory and gives you a whole new model to host.

Start with LoRA. Move to full fine-tuning only if LoRA plateaus below where you need to be.

Train on the success signal

  1. Supervised fine-tuning. Train on successful trajectories so the model copies what worked: the right tools, in the right order, with the right edit format.
  2. Preference training. Pair a successful and a failed attempt at the same task, and train the model to prefer the one that worked (for example with DPO).
  3. Reinforcement learning. Let the model attempt tasks in a sandbox and reward it when your success signal fires, for example with GRPO. This is the most powerful step and the most expensive, so do it last.

How do you know it worked?

Run the held-out tasks on the base model and the tuned model, in the same harness, and compare cost per successful task. A tuned model that succeeds more often, or needs fewer turns, lowers it. Watch for regressions on tasks outside the training set; a model can get better at your common case and worse at everything else.

Serving the tuned model

A LoRA adapter can be served alongside the base model at almost no extra cost. A fully fine-tuned model needs its own deployment: on dedicated capacity, in your private cloud, or on-prem. Either way, the agent calls it like any other model, by name, through the same API.

Common questions

How much data do I need to fine-tune a model for my agent?

A few hundred good trajectories can change behaviour on a narrow task; a few thousand cover a broad agent. The best data is your agent's own recorded sessions, labelled with whether each task succeeded.

Should I use LoRA or full fine-tuning?

Start with LoRA. It trains quickly on far less GPU memory, and one base model can serve many adapters, which keeps serving cheap. Move to full fine-tuning only if LoRA plateaus.

Can you fine-tune a model for us?

Yes. We fine-tune open models on your agent's sessions and success signal, and deploy the result on dedicated GPUs, in your cloud account or on-prem. Book a call to scope it.

More guides

Fine-tune a model for your agent.

Book a call. We'll look at your agent's sessions and success signal, and scope a fine-tune and where to deploy it.