bots-garden/mini-mepublic Fork
⑂ v1.0.3
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/mini-me.git
git clone ssh://git@rickub.com/bots-garden/mini-me.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP
🛟 Updated. 726802e · on v1.0.3 · k33g · Oct 18, 2026
README.en.md · 86 lines · 6.3 KBmarkdown
Blame HistoryOpen raw

mini-me demo: unloading models

Version française

A coordinator hands each programming question to an expert, and the two models take turns in the server's memory without ever being loaded together: a preAsk hook unloads the coordinator's model right before the expert starts, and a postAsk hook unloads the expert's model once it has answered, before the coordinator is reloaded to read the answer. The models are served by llmman.

What is here

File Role
agent.yaml The coordinator (Qwen3.5 9B): ask_agent to the expert, then the answer. The two hooks. /unload and the unload_model tool work here too. displayHooks: true shows the hook runs.
hooks/unload.js The hook (Node.js). unload.js self (preAsk): unloads the coordinator's own model right before mm starts the expert. unload.js asked (postAsk): unloads the expert's model once it has answered.
agent.expert.yaml The expert (Qwen3.5 4B): answers programming questions, no tools at all (unloadModels: false).

Run the demo

llmman pull hf.co/unsloth/Qwen3.5-9B-GGUF:Q4_K_M
llmman pull hf.co/unsloth/Qwen3.5-4B-GGUF:Q4_K_M
cd demos/unload-models
mm -tui agent.yaml

Ask a programming question, then look at what the server holds:

llmman ps        # or: curl -s http://127.0.0.1:17434/api/ps

After the answer, only the coordinator's Qwen3.5 9B is loaded. In the terminal the hand-off shows as:

🗣 ask_agent: expert (llmman/hf.co/unsloth/Qwen3.5-4B-GGUF:Q4_K_M) — Explain what a closure is in Ja…
  🪝 1. preAsk expert · node "$MM_CONFIG_DIR/hooks/unload.js" self → continue
  🪝 2. postAsk expert · node "$MM_CONFIG_DIR/hooks/unload.js" asked → continue

By hand: /unload unloads the coordinator's own model, /unload <model> any other one of the same server — in the terminal, the window and an editor. Asking the coordinator to free the expert's memory ("Unload the expert's model.", "Libère la mémoire de l'expert.") makes it call unload_model on the expert's model (4/4 measured): its name is written in the prompt, as the model cannot guess how the server names a model.

How it works

What the server holds during one question (measured with /api/ps twice a second):

Moment Loaded
the coordinator reads the question and calls ask_agent Qwen3.5 9B
the preAsk hook unloads the coordinator —
the expert works Qwen3.5 4B alone
the postAsk hook unloads the expert —
the coordinator reads the answer (the server reloads it) Qwen3.5 9B alone

Why hooks, and not the model. Both unloads must happen at a moment when the coordinator's model is not running:

  • Before the expert: the coordinator's model has just decided to call ask_agent, and it is needed again only to read the answer. The model cannot unload itself — unload_model on its own model lasts until its next step.
  • After the expert: if the coordinator called unload_model on the expert's model, it would already be running again — reloaded beside the 4B — when it does so. The two models would be loaded together for the whole step. (That is what the previous version of this demo did; see below.)

mm runs the preAsk hooks right before it starts the asked agent and the postAsk hooks right after its answer, before the asking agent reads it. hooks/unload.js reads the model to unload from its input — "model": "llmman/<model>" for self, "ask": {"agentModel": "llmman/<model>"} for asked — and sends keep_alive: 0 to the server. matcher: ^expert$ keeps both hooks to this hand-off. onError: warn: if an unload fails, the hand-off goes on.

The hooks are also certain: a model can skip an instruction, a hook always runs.

Measured results (2026-10-18, mm -p, llmman)

Coordinator Qwen3.5 9B, expert Qwen3.5 4B, both hooks on. "Never together" means /api/ps (sampled twice a second) never showed both models at once during the question: 9B → nothing → 4B → nothing → 9B.

Question ask_agent preAsk unloads the 9B postAsk unloads the 4B never together Time
How do I reverse a string in Go? ✓ ✓ ✓ ✓ 62 s
What is a closure in JavaScript? ✓ ✓ ✓ ✓ 65 s
How do I read a file line by line in Python? ✓ ✓ ✓ ✓ 49 s
Explain Rust ownership briefly. ✓ ✓ ✓ ✓ 82 s
Comment trier un tableau en Java ? ✓ ✓ ✓ ✓ 119 s
How do I make an HTTP GET request in Go? ✓ ✓ ✓ ✓ 106 s
What does the yield keyword do in Python? (×3) ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ 57 s, 60 s, 85 s

9 out of 9. The French question is answered in French. A greeting ("Hello, who are you?") is answered in 2 s without any tool. The times include the loads: each question loads the 9B twice and the 4B once, and vary a lot from one run to the next.

The prompt. Without the unload_model step, a short prompt ("1. Call ask_agent… 2. Then give the expert's answer") let the coordinator answer the yield question by itself, without the expert (1 time out of 7). Saying that ask_agent is ALWAYS the first action, "even for a question you know the answer to", gave the table above.

Earlier versions. With the coordinator freeing the expert through unload_model (no postAsk hook), the 9B and the 4B were loaded together for ~18 s per question while the coordinator read the answer — 7/7 questions otherwise clean. Before that, with a MiniCPM5 2B coordinator and a Qwen3.5 9B expert, the coordinator skipped unload_model once in five.

Good to know

  • postAsk runs after every hand-off to the expert, answered, failed or cancelled: the expert's model is unloaded even when its turn failed.
  • The next question reloads the 4B: a hand-off costs one load of each model, plus a reload of the coordinator. Keeping both loaded is faster, when the memory allows it.
  • llmman also unloads by itself a model idle for five minutes (keep_alive); the hooks free the memory at once, which matters when the next model needs it right away.
  • Turn off /unload and unload_model with unloadModels: false, as the expert does: an agent that only answers does not need one more tool. The hooks do not depend on that key.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# mini-me demo: unloading models

*[Version française](README.fr.md)*

A coordinator hands each programming question to an expert, and the two models take turns in the server's memory without ever being loaded together: a `preAsk` hook unloads the coordinator's model right before the expert starts, and a `postAsk` hook unloads the expert's model once it has answered, before the coordinator is reloaded to read the answer. The models are served by [llmman](https://github.com/llmmanorg/llmman).

## What is here

| File | Role |
|---|---|
| `agent.yaml` | The **coordinator** (Qwen3.5 9B): `ask_agent` to the expert, then the answer. The two hooks. `/unload` and the `unload_model` tool work here too. `displayHooks: true` shows the hook runs. |
| `hooks/unload.js` | The hook (Node.js). `unload.js self` (`preAsk`): unloads the coordinator's own model right before mm starts the expert. `unload.js asked` (`postAsk`): unloads the expert's model once it has answered. |
| `agent.expert.yaml` | The **expert** (Qwen3.5 4B): answers programming questions, no tools at all (`unloadModels: false`). |

## Run the demo

```bash
llmman pull hf.co/unsloth/Qwen3.5-9B-GGUF:Q4_K_M
llmman pull hf.co/unsloth/Qwen3.5-4B-GGUF:Q4_K_M
cd demos/unload-models
mm -tui agent.yaml
```

Ask a programming question, then look at what the server holds:

```bash
llmman ps        # or: curl -s http://127.0.0.1:17434/api/ps
```

After the answer, only the coordinator's Qwen3.5 9B is loaded. In the terminal the hand-off shows as:

```text
🗣 ask_agent: expert (llmman/hf.co/unsloth/Qwen3.5-4B-GGUF:Q4_K_M) — Explain what a closure is in Ja…
  🪝 1. preAsk expert · node "$MM_CONFIG_DIR/hooks/unload.js" self → continue
  🪝 2. postAsk expert · node "$MM_CONFIG_DIR/hooks/unload.js" asked → continue
```

By hand: `/unload` unloads the coordinator's own model, `/unload <model>` any other one of the same server — in the terminal, the window and an editor. Asking the coordinator to free the expert's memory ("Unload the expert's model.", "Libère la mémoire de l'expert.") makes it call `unload_model` on the expert's model (4/4 measured): its name is written in the prompt, as the model cannot guess how the server names a model.

## How it works

What the server holds during one question (measured with `/api/ps` twice a second):

| Moment | Loaded |
|---|---|
| the coordinator reads the question and calls `ask_agent` | Qwen3.5 9B |
| the `preAsk` hook unloads the coordinator | — |
| the expert works | Qwen3.5 4B alone |
| the `postAsk` hook unloads the expert | — |
| the coordinator reads the answer (the server reloads it) | Qwen3.5 9B alone |

**Why hooks, and not the model.** Both unloads must happen at a moment when the coordinator's model is not running:

- *Before the expert*: the coordinator's model has just decided to call `ask_agent`, and it is needed again only to read the answer. The model cannot unload itself — `unload_model` on its own model lasts until its next step.
- *After the expert*: if the coordinator called `unload_model` on the expert's model, it would already be running again — reloaded beside the 4B — when it does so. The two models would be loaded together for the whole step. (That is what the previous version of this demo did; see below.)

mm runs the `preAsk` hooks right before it starts the asked agent and the `postAsk` hooks right after its answer, before the asking agent reads it. `hooks/unload.js` reads the model to unload from its input — `"model": "llmman/<model>"` for `self`, `"ask": {"agentModel": "llmman/<model>"}` for `asked` — and sends `keep_alive: 0` to the server. `matcher: ^expert$` keeps both hooks to this hand-off. `onError: warn`: if an unload fails, the hand-off goes on.

The hooks are also certain: a model can skip an instruction, a hook always runs.

## Measured results (2026-10-18, `mm -p`, llmman)

Coordinator Qwen3.5 9B, expert Qwen3.5 4B, both hooks on. "Never together" means `/api/ps` (sampled twice a second) never showed both models at once during the question: 9B → nothing → 4B → nothing → 9B.

| Question | `ask_agent` | `preAsk` unloads the 9B | `postAsk` unloads the 4B | never together | Time |
|---|---|---|---|---|---|
| How do I reverse a string in Go? | ✓ | ✓ | ✓ | ✓ | 62 s |
| What is a closure in JavaScript? | ✓ | ✓ | ✓ | ✓ | 65 s |
| How do I read a file line by line in Python? | ✓ | ✓ | ✓ | ✓ | 49 s |
| Explain Rust ownership briefly. | ✓ | ✓ | ✓ | ✓ | 82 s |
| Comment trier un tableau en Java ? | ✓ | ✓ | ✓ | ✓ | 119 s |
| How do I make an HTTP GET request in Go? | ✓ | ✓ | ✓ | ✓ | 106 s |
| What does the yield keyword do in Python? (×3) | ✓ ✓ ✓ | ✓ ✓ ✓ | ✓ ✓ ✓ | ✓ ✓ ✓ | 57 s, 60 s, 85 s |

9 out of 9. The French question is answered in French. A greeting ("Hello, who are you?") is answered in 2 s without any tool. The times include the loads: each question loads the 9B twice and the 4B once, and vary a lot from one run to the next.

**The prompt.** Without the `unload_model` step, a short prompt ("1. Call ask_agent… 2. Then give the expert's answer") let the coordinator answer the `yield` question by itself, without the expert (1 time out of 7). Saying that `ask_agent` is ALWAYS the first action, "even for a question you know the answer to", gave the table above.

**Earlier versions.** With the coordinator freeing the expert through `unload_model` (no `postAsk` hook), the 9B and the 4B were loaded together for ~18 s per question while the coordinator read the answer — 7/7 questions otherwise clean. Before that, with a MiniCPM5 2B coordinator and a Qwen3.5 9B expert, the coordinator skipped `unload_model` once in five.

## Good to know

- **`postAsk` runs after every hand-off to the expert**, answered, failed or cancelled: the expert's model is unloaded even when its turn failed.
- **The next question reloads the 4B**: a hand-off costs one load of each model, plus a reload of the coordinator. Keeping both loaded is faster, when the memory allows it.
- **llmman also unloads by itself** a model idle for five minutes (`keep_alive`); the hooks free the memory at once, which matters when the next model needs it right away.
- **Turn off `/unload` and `unload_model`** with `unloadModels: false`, as the expert does: an agent that only answers does not need one more tool. The hooks do not depend on that key.