Ask your agent
What it does
It builds a test from your real task, scores the model, and iteratively improves its prompt, examples, and settings. It validates changes on held-out cases, then ships a new Ollama model with before-and-after scores without altering the original.
SKILL.md
---
name: local-model-tuner
description: Make a local Ollama model measurably better at ONE of your tasks without retraining it. Builds a test from your real task, scores the model, then loops - reads its failures, rewrites its system prompt, adds few-shot examples from its own best answers, tunes settings - keeps only changes that raise the score, checks on held-out cases, and ships it as a new Ollama model with a before/after number. Use when someone wants their local model (Ollama, Qwen, Gemma, Llama...) to "get better", "learn my style", "self-improve", or be tuned for a job.
---
# Local Model Tuner
You (the agent) are the coach and the judge. The local model is the player. The script `scripts/lmt.py` only runs the model and counts; every judgement and every rewrite is yours.
Ideas this combines: eval-driven loops with hard checks + a rubric judge (promptfoo), reflection on failure traces to rewrite the prompt (GEPA), few-shot examples bootstrapped from the model's own best answers (DSPy), "keep a change only if the score goes up" (prompt-loop), and a held-out gate so you never ship an overfit prompt.
## Ground rules
- Never modify, overwrite or delete the user's existing models. Ship under a NEW name (`<base>-tuned`).
- Ask before installing anything or pulling a model. Never ask for API keys or passwords.
- Never invent numbers. Every score in your report comes from `lmt.py score` / `compare` output.
- Stay on the user's machine: Ollama on 127.0.0.1. Nothing is uploaded. If OLLAMA_HOST points to another machine, `doctor` says so: tell the user prompts go there.
- Needs a coding agent with shell access on the user's computer (e.g. Claude Code). In a web chat without a shell, say so and stop.
## Step 0 - Preflight
Work from the user's project folder, NOT inside the skill folder. Call the script by its absolute path (below, `LMT` = absolute path to this skill's `scripts/lmt.py`; use `python3` or `py` if `python` is missing). Set `LMT_WORK` to an absolute folder, e.g. `<project>/lmt-work`; all paths below are inside it.
Run `python LMT doctor`. If Ollama isn't reachable, tell the user how to start it and stop. Ask which installed model to tune (suggest the one they actually use), then `python LMT doctor <model>` to confirm it exists.
## Step 1 - Intake (one message, then wait)
Ask max 5 questions: what the task is; 3-5 real examples of a GREAT answer (paste or file); what a bad answer looks like (things it must never do); hard limits (length, format, language, tone); what matters most if trade-offs. If they give no examples, propose 3 and get a yes.
## Step 2 - Build the test suite (`$LMT_WORK/suite.json`)
```json
{"task": "one line", "rubric": "what a 10/10 answer has, what loses points; 4-8 bullet lines",
"cases": [{"id": "c01", "split": "train", "input": "...", "checks": [{"max_chars": 280}, {"not_contains": ["as an AI"]}]}]}
```
- 20-30 realistic, varied inputs from the user's world. 60% `train`, 40% `holdout`. Cover easy, typical and nasty cases.
- Hard checks are objective and cheap: `contains`, `contains_any`, `not_contains`, `regex`, `not_regex`, `max_chars`, `min_chars`, `max_words`, `min_words`, `max_lines`, `json_keys`, `no_emoji`. A failed hard check makes that case score 0.
- The rubric covers what code can't check (quality, style, usefulness). Keep it fixed for the whole run.
- Show the user the rubric + 3 sample cases. Get a yes before running.
## Step 3 - Baseline
Write `$LMT_WORK/configs/v0.json` with the model as it is today:
```json
{"base": "qwen3:8b", "system": "", "options": {"temperature": 0.7, "num_ctx": 8192, "seed": 42}, "examples": [], "think": false}
```
If the user already uses a system prompt, put it in v0. Then:
```
python LMT run $LMT_WORK/configs/v0.json train v0
python LMT run $LMT_WORK/configs/v0.json holdout v0h
python LMT judge-sheet v0
python LMT judge-sheet v0h
```
Read each `runs/<tag>.judge-sheet.md` (it lists only answers that passed the hard checks; the rest already score 0) and judge blind: write `runs/<tag>.judge.json` (`{"c01": {"score": 7, "why": "..."}}`), honest and consistent with the rubric. Then `python LMT score v0` and `python LMT score v0h`. Report the baseline in one line.
## Step 4 - Improve (train split only, max 5 rounds)
Each round:
1. **Reflect.** Read the lowest-scoring train answers and the "why" lines. Name the 2-3 root causes (e.g. "too long", "generic opener", "ignores format", "hallucinates numbers").
2. **Change ONE thing set**, aimed at those causes, in a new config `v{n}.json`:
- rewrite the system prompt: explicit rules, the format, what to never do, the output only;
- and/or add 1-3 few-shot examples: take the best real answers (the user's examples or the model's own top-scored outputs), never holdout inputs;
- and/or settings: temperature (0.2-0.9), `num_predict` cap, `num_ctx`, `top_p`, `repeat_penalty`.
3. `python LMT run $LMT_WORK/configs/v{n}.json train v{n}`, `judge-sheet v{n}`, judge blind, `score v{n}`, `compare <best> v{n}` (compare uses only the cases both runs share).
4. **Keep it only if the train score rises.** Otherwise revert to the previous best and try a different fix next round.
Stop early when two rounds in a row don't help, or train score ≥ 90.
## Step 5 - Holdout gate (the honesty check)
Run the best config on `holdout` (`python LMT run <best config> holdout best_h`), judge blind, then `compare v0h best_h`. Ship only if:
- the holdout total is at least +5 points over v0h, and
- `compare` prints no "newly failing hard checks" line.
If the gate fails: say so plainly, keep v0, and show what you learned. Don't ship a prompt that only memorized the train cases.
## Step 6 - Ship
`python LMT ship $LMT_WORK/configs/<best>.json <base>-tuned` creates a new Ollama model (system prompt, settings, seed and few-shot examples baked in). It refuses to overwrite the base or any model that already exists. If the `ollama` command isn't on PATH, it prints the exact command for the user to run. Tell the user:
- before → after on holdout (and train), with the exact numbers from `compare`;
- what changed, in 3 short lines (prompt rules added, examples added, settings);
- how to use it: `ollama run <base>-tuned`; how to undo: `ollama rm <base>-tuned`.
## Step 7 - Optional: real fine-tuning later
`python LMT export-dataset <tag> $LMT_WORK/dataset.jsonl 8` saves the answers scored ≥ 8/10 as a chat dataset. With 200+ such examples it can feed a LoRA fine-tune (e.g. Unsloth). Only suggest it; don't start training without a clear yes and enough GPU memory.
## Report format (end of run)
One block, plain words:
`<model> on "<task>": holdout X → Y (+Z), train A → B. Changed: ... Use: ollama run ... Undo: ollama rm ...`
5 files
- README.md0.8 KB
- SKILL.md6.7 KB
- examples/config.x-hooks.tuned.json2.0 KB
- examples/suite.x-hooks.json14.8 KB
- scripts/lmt.py15.7 KB