agentleFS
ChiefGyk3DChiefGyk3D/department-of-internal-arguments/.agents/skills/pack-local-llm-routing/SKILL.md

pack-local-llm-routing

Skill166 starsChanged 6 days agoApache-2.0View on GitHub

Load when routing text work to a local Ollama model, writing a client that calls Ollama, or sizing a model and context for one 16 GB GPU. Carries measured num_ctx, think=false, fit, task-fit and busy (exit 75) facts, outcome logging, and a per-model evaluation record. Not for cloud-model prompting.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Check shapes, cheapest first.

    line 20
  2. Distinctive:

    Identifiers in the prose: Every name and number in the output must appear in the source.

    line 24
  3. Distinctive:

    Never let it write rules, code or security judgments.

    line 35
  4. Very specific:

    Read from the client's --help and source, 2026-11-25.

    line 72

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md
<!-- Generated by scripts/generate.py (release 0.4.0) from packs/local-llm-routing/PACK.md, updated 2026-11-25. sha256:815350ca930ca6bc758eada162f022babd32060cae8ffad09def75f87639d88d. Do not edit; run the generator. -->

Pack: local LLM routing (Ollama)

Status: pilot pack, written 2026-10-08, refreshed 2026-11-25. VERIFIED = vendor page read on the stated date; MEASURED = one named setup; INFERRED = reasoned, not tested. Start small (one GPU, one model, a small context) and keep every setting configurable; never bake in one person's devices, ports or contexts. Example endpoint: http://localhost:11434. Use a local model for text-in, text-out drafts that a stronger model or a human checks; state changes, security risk and exact answers stay with code or a stronger model.

Local output is a draft: verify it against the source

Local output is a draft, never applied or quoted unverified: nothing it wrote goes into a commit, PR, comment, issue or decision until each name, number and claim is checked against its source.

Measured, one model only: gemma4:12b, 2026-10-26, 2 of 5 triage runs returned unrelated text. Two of five PR-triage runs summarized a different change; a reviewer reading the diff caught both. The model was not logged; gemma4:12b (12B parameters) was the default, so this is attributed to it by inference, and may not hold for another model, size or release. The cause is unknown (truncated or wrong prompt, or drift: INFERRED, untested); verification catches the symptom.

Rule out context first. Ollama's default is 4k tokens (4096) below 24 GiB of VRAM, 32k at 24 to 48 GiB, 256k above (VERIFIED, docs.ollama.com/context-length, read 2026-11-25), so a client that omits num_ctx on a 16 GB card runs at 4096. What an overlong prompt loses is INFERRED, untested on gemma4:12b: a long diff may lose most of its text while the instructions survive.

Check shapes, cheapest first; code compares, the model never grades itself.

  1. Echo and compare identifiers. The model echoes the PR number, title or file names as separate format JSON fields; code rejects any mismatch. Status: INFERRED, untested on gemma4:12b.
  2. Quote, then answer. Two or three short quotes first; code checks each appears verbatim in the source. Status: INFERRED, untested on gemma4:12b.
  3. Identifiers in the prose. Every name and number in the output must appear in the source. Status: INFERRED, untested on gemma4:12b.
  4. Keep roles apart. Instructions in system, the text under review in user inside delimiters. Status: INFERRED, untested on gemma4:12b.

On a failed check, reject the draft, retry once or write it yourself, and count the mismatch.

Report on the header's LOCAL-LLM: line: LOCAL-LLM: used - <exact model tag and size>; VERIFIED-AGAINST: <source>; DISCREPANCIES: <n>, or LOCAL-LLM: n/a - <reason>. Name the model that answered, read from the response; DISCREPANCIES: 0 counts only when VERIFIED-AGAINST: names a source actually compared.

Division of labor (the rule that matters most)

  • Code does the grouping, counting, sorting, deduplication and every statistic. The model never produces a number, count or category that anything depends on.
  • The model writes prose only, from facts code already computed, and someone verifies each claim. Drafts of grouped facts, technical prose, release notes and documentation were all rewritten by hand in the 2026-10-07 sessions (model not recorded; measured 2026-10-07; not a finding about local models in general).
  • Never let it write rules, code or security judgments.
  • Classification with free-text labels is unreliable: one model's role labels were right about 85% of the time and domain labels about 46% (model not recorded; measured 2026-10-07; not a finding about local models in general; it named projects instead of technical areas). Give it a closed label list and validate against it in code.
  • Latency: roughly 55 to 215 seconds for a long draft (model not recorded; measured 2026-10-07; not a finding about local models in general); run it in the background.

Measured 2026-11-25: where each model is good enough

Synthetic prompts (median about 900 tokens) scored by code (labels, JSON validity, key facts, invented numbers), two repetitions, Ollama 0.33.2, one 16 GB GPU, think off. Score is the mean per call; the percentage is the share fully right.

Shapegemma4:12bqwen3.5:4bqwen3:14b
classification (20 items)1.001.001.00
triage (20)1.000.95 (90%)0.975 (95%)
summary, 7 facts (12)1.000.976 (83%)1.00
issue first draft (12)0.994 (96%)0.979 (96%, one invented number)0.976 (83%)
CI/log digest (12)1.000.958 (83%)0.979 (92%)
decode tokens/s, cold load53, 4.4 s112, 3.9 s48, 13 s
  • gemma4:12b is the default for faithfulness-critical work (summary, issue draft, CI digest, triage). qwen3.5:4b is about 2.2 times faster and right for closed-list classification and short summaries, not for triage, CI digests or where a wrong fact is costly. Route by task label.
  • qwen3:14b is not adopted: no better, no faster, 1.1 GB larger, and its 13 s load evicted both residents. qwen3.5:9b was not on disk, untested.
  • Limits (confidence medium): short invented prompts near the ceiling show no regression, not subtle fact errors; nothing over 6k tokens; tone not scored.
  • Real use, 2026-10-07 to 2026-11-25: gemma4:12b prompts p95 5,782 tokens, none above 32768 in 703 calls; qwen3.5:4b had 2 above 6,000 against its 8192 window.

What fits one 16 GB card (MEASURED 2026-11-25, server-reported sizes)

  • gemma4:12b at context 131072 reports 8.19 GB and qwen3.5:4b at 8192 reports 3.34 GB, both 100% on the GPU, keep_alive -1. A 2026-10-07 reading was 9.8 GB with KV cache; the gap is INFERRED to be the size estimate, so check nvidia-smi on the host.
  • Lowering gemma4:12b from 131072 showed no saving: 8.42 GB at 32768, 8.39 GB at 16384, 50 tokens/s in all three, and the switch evicted qwen3.5:4b. GPU memory itself was not measured; keep the loaded context.

Checklist: calling Ollama

  1. Always send num_ctx, exactly the value the model is loaded with. A different value reloads the model and can evict a neighbor on the same GPU (measured repeatedly, last 2026-11-25; keep_alive -1 does not protect a resident). Read it from ollama ps or GET /api/ps.
  2. think: false for cheap tasks. A thinking model spends hundreds of tokens before a one-sentence answer (436 evaluation tokens for one sentence on a 12B-parameter model; about 15 times fewer with thinking off on a 4B-parameter model; model not recorded; measured 2026-10-07; not a finding about local models in general). VERIFIED, docs.ollama.com/capabilities/thinking, read 2026-11-25: think: false requests no thinking output; a model that cannot turn it off uses its lowest level. Opt in only for judgments.
  3. Structured output. format accepts a JSON schema; validate in code. All responses in the 2026-11-25 run were valid JSON; schema-valid is still not correct.
  4. Models that cannot co-reside evict each other; check VRAM fit with ollama ps after a warm-up. A 12B-parameter model plus a second one fit together at a context of 8192 but not 16384 (model not recorded; measured 2026-10-07; not a finding about local models in general). Testing a candidate on a shared box evicts the residents: use an approved window, restore the same models and contexts, read ollama ps before and after.
  5. Configurable, not hard-coded. Host, model, context and timeouts come from environment or config (names below).

Reference client: a local-model CLI (flags, exit codes, logs)

Read from the client's --help and source, 2026-11-25; a test checks the flags, outcomes, exit 75, log fields and settings below against them.

  • Call. <client> --task LABEL "prompt" < material (the label is required). Thinking is off unless --think; --json asks for JSON; --envelope prints the call id, model and response as JSON; --stats prints counts.
  • Exit codes. 0 answered. 75: admission control had no slot. Exit 75 means busy, not an outage: retry, or pass --wait SECONDS to poll for a slot; do not report the server as unreachable. 2 failed, cause in the log reason (unreachable and timeout are the outage signals; a missing --task also gives 2). 130, or 128 plus a signal number: interrupted.
  • Context. --num-ctx declares the context, but the loaded one from config is sent; --allow-reload sends the declared value and can evict a neighbor. --est-mb declares the call's VRAM.
  • Outcome. Each call prints its call id on stderr. Afterwards record what was done: <client> --outcome ID accepted|rewritten|discarded|fact-error; this makes an accept or rewrite rate computable per model and task (none existed before).
  • Call log (calls.jsonl, rotated at 8 MiB; no prompt or answer is stored). Call rows: kind ("call"), id, ts, model, task, status (ok, failed or busy). ok adds prompt_tokens, eval_tokens, seconds, load_duration_s and load_fresh (a load over the threshold, counted as an eviction; a cold load counts). failed and busy add exit_code, reason and seconds. Reason classes: busy, unreachable, timeout, over-budget, bad-response, bad-config, bad-input, interrupted, internal. Outcome rows: kind ("outcome"), id, outcome, ts.
  • Settings. Environment: LLM_LOCAL_URL, LLM_LOCAL_MODEL (default model), LLM_LOCAL_CTX, LLM_LOCAL_CONFIG (config file). Config keys, all optional: vram_budget_mb, max_concurrent, default_est_mb, reload_threshold_s, and per model [models."name"] with num_ctx (the loaded context) and est_mb. Set your own values, equal to what the server keeps loaded.

Evaluation record for a local model

Before assigning a task class to a model, record these fields and re-measure when one changes; "not recorded" is a defect, not a pass. Fields: artifact (tag, digest), quantization, loaded and maximum context, runtime version, license, hardware class (accelerator, VRAM), result per task class (check, runs, sanitized inputs), prompt fit. Rows (2026-11-25, Ollama 0.33.2, one 16 GB GPU, digests not recorded, no long-prompt test):

  • gemma4:12b: Q4_K_M; loaded 131072, maximum 256K (library page, read 2026-11-25); Apache 2.0 (model card); 8.19 GB; all five shapes 0.99 or better.
  • qwen3.5:4b: Q4_K_M (INFERRED); loaded 8192, maximum 256K (library page); Apache 2.0 (INFERRED); 3.34 GB; classification and short summaries only.
  • qwen3:14b: Q4_K_M; 8192, maximum 40K (INFERRED); Apache 2.0 (INFERRED); 9.28 GB file; no gain; its 13 s load evicts both residents.

Multi-GPU and reachability

  • On a multi-GPU NVIDIA host Ollama 0.33.2 also enumerated devices through Vulkan, which ignores CUDA_VISIBLE_DEVICES, so a split put models on the wrong devices; OLLAMA_VULKAN=0 in each service unit fixed it (UNVERIFIED on newer releases). Verify with journalctl -u <unit> | grep "using device" and ollama ps.
  • Probe before promising it to an agent; a recorded probe goes stale in hours. If the server is unreachable (exit 2, reason unreachable, not exit 75), write local model: n/a - <reason> in the brief and use another route.
  • A brief that names the local step does not make an agent use it (about 5 of 14 did, 2026-10); verify from the call log. Subagents without network access cannot call it.

How to verify (commands)

  • Up and loaded: curl -s "$OLLAMA_HOST/api/ps" (default http://localhost:11434); ollama ps. Compare context_length with the num_ctx the client sends.
  • Reload: compare load_duration across two identical calls, or read load_fresh in the log.
  • Busy versus down: exit 75 means wait; reason unreachable means no answer.
  • Prose: diff every name, number and claim against the source. The response's model field names the model for the LOCAL-LLM: line.
  • Truncation: a prompt_eval_count near num_ctx, or far below the input size, means text was dropped (INFERRED, untested on gemma4:12b).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.