bots-garden/mini-mepublic Fork
⑂ 49ca17f
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

Revert "♻️ Quality: one unload.js for unload-models, coding-helpers and dev.team (3 duplicate findings → 0)"

This reverts commit a318e930a237583549b6dbec5c22e1c06fca7d24.
agent committed 2026-11-28T13:16:47+01:00 Browse files
49ca17f parent: a467179
modified demos/coding-helpers-unload-option/README.en.md +1 -1
@@ -77,6 +77,6 @@ The two models were never listed together.
7777
7878 ## Hooks or option?
7979
80-`demos/coding-helpers` gets the same result with a `preAsk` and a `postAsk` hook (`unload.js`). The option needs no script, no Node.js, and works for any provider mm can unload with (llmman, Ollama, llama-server in router mode); each model is unloaded on its own agent's server. Hooks remain for what the option does not do: unloading another model, or only under a condition.
80+`demos/coding-helpers` gets the same result with a `preAsk` and a `postAsk` hook (`hooks/unload.js`). The option needs no script, no Node.js, and works for any provider mm can unload with (llmman, Ollama, llama-server in router mode); each model is unloaded on its own agent's server. Hooks remain for what the option does not do: unloading another model, or only under a condition.
8181
8282 See [How to free a model's memory](../../docs/en/how-to/unload-a-model.md) and the [`mmConfigs` reference](../../docs/en/reference/configuration.md).
@@ -77,6 +77,6 @@ The two models were never listed together.
77 77
78 ## Hooks or option?78 ## Hooks or option?
79 79
80-`demos/coding-helpers` gets the same result with a `preAsk` and a `postAsk` hook (`unload.js`). The option needs no script, no Node.js, and works for any provider mm can unload with (llmman, Ollama, llama-server in router mode); each model is unloaded on its own agent's server. Hooks remain for what the option does not do: unloading another model, or only under a condition.80+`demos/coding-helpers` gets the same result with a `preAsk` and a `postAsk` hook (`hooks/unload.js`). The option needs no script, no Node.js, and works for any provider mm can unload with (llmman, Ollama, llama-server in router mode); each model is unloaded on its own agent's server. Hooks remain for what the option does not do: unloading another model, or only under a condition.
81 81
82 See [How to free a model's memory](../../docs/en/how-to/unload-a-model.md) and the [`mmConfigs` reference](../../docs/en/reference/configuration.md).82 See [How to free a model's memory](../../docs/en/how-to/unload-a-model.md) and the [`mmConfigs` reference](../../docs/en/reference/configuration.md).
modified demos/coding-helpers-unload-option/README.fr.md +1 -1
@@ -77,6 +77,6 @@ Les deux modèles n'ont jamais été listés ensemble.
7777
7878 ## Hooks ou option ?
7979
80-`demos/coding-helpers` obtient le même résultat avec un hook `preAsk` et un hook `postAsk` (`unload.js`). L'option ne demande ni script ni Node.js, et marche avec tout fournisseur que mm sait décharger (llmman, Ollama, llama-server en mode router) ; chaque modèle est déchargé sur le serveur de son agent. Les hooks restent pour ce que l'option ne fait pas : décharger un autre modèle, ou seulement sous condition.
80+`demos/coding-helpers` obtient le même résultat avec un hook `preAsk` et un hook `postAsk` (`hooks/unload.js`). L'option ne demande ni script ni Node.js, et marche avec tout fournisseur que mm sait décharger (llmman, Ollama, llama-server en mode router) ; chaque modèle est déchargé sur le serveur de son agent. Les hooks restent pour ce que l'option ne fait pas : décharger un autre modèle, ou seulement sous condition.
8181
8282 Voir [Libérer la mémoire d'un modèle](../../docs/fr/how-to/unload-a-model.md) et la [référence de `mmConfigs`](../../docs/fr/reference/configuration.md).
@@ -77,6 +77,6 @@ Les deux modèles n'ont jamais été listés ensemble.
77 77
78 ## Hooks ou option ?78 ## Hooks ou option ?
79 79
80-`demos/coding-helpers` obtient le même résultat avec un hook `preAsk` et un hook `postAsk` (`unload.js`). L'option ne demande ni script ni Node.js, et marche avec tout fournisseur que mm sait décharger (llmman, Ollama, llama-server en mode router) ; chaque modèle est déchargé sur le serveur de son agent. Les hooks restent pour ce que l'option ne fait pas : décharger un autre modèle, ou seulement sous condition.80+`demos/coding-helpers` obtient le même résultat avec un hook `preAsk` et un hook `postAsk` (`hooks/unload.js`). L'option ne demande ni script ni Node.js, et marche avec tout fournisseur que mm sait décharger (llmman, Ollama, llama-server en mode router) ; chaque modèle est déchargé sur le serveur de son agent. Les hooks restent pour ce que l'option ne fait pas : décharger un autre modèle, ou seulement sous condition.
81 81
82 Voir [Libérer la mémoire d'un modèle](../../docs/fr/how-to/unload-a-model.md) et la [référence de `mmConfigs`](../../docs/fr/reference/configuration.md).82 Voir [Libérer la mémoire d'un modèle](../../docs/fr/how-to/unload-a-model.md) et la [référence de `mmConfigs`](../../docs/fr/reference/configuration.md).
modified demos/coding-helpers-unload-option/agent.yaml +1 -1
@@ -23,7 +23,7 @@
2323 # the COORDINATOR's model right before a specialist starts, and the
2424 # SPECIALIST's model once it has answered, before the coordinator is
2525 # reloaded to read the answer. No hook: demos/coding-helpers does the
26-# same with the unload.js hook.
26+# same with hooks/unload.js.
2727 #
2828 # llmman pull hf.co/openbmb/MiniCPM5-2B-GGUF:Q4_K_M
2929 # llmman pull huggingface.co/jetbrains/mellum2-12b-a2.5b-thinking-gguf-q4_k_m:Q4_K_M
@@ -23,7 +23,7 @@
23 # the COORDINATOR's model right before a specialist starts, and the23 # the COORDINATOR's model right before a specialist starts, and the
24 # SPECIALIST's model once it has answered, before the coordinator is24 # SPECIALIST's model once it has answered, before the coordinator is
25 # reloaded to read the answer. No hook: demos/coding-helpers does the25 # reloaded to read the answer. No hook: demos/coding-helpers does the
26-# same with the unload.js hook.26+# same with hooks/unload.js.
27 #27 #
28 # llmman pull hf.co/openbmb/MiniCPM5-2B-GGUF:Q4_K_M28 # llmman pull hf.co/openbmb/MiniCPM5-2B-GGUF:Q4_K_M
29 # llmman pull huggingface.co/jetbrains/mellum2-12b-a2.5b-thinking-gguf-q4_k_m:Q4_K_M29 # llmman pull huggingface.co/jetbrains/mellum2-12b-a2.5b-thinking-gguf-q4_k_m:Q4_K_M
modified demos/coding-helpers/README.en.md +3 -3
@@ -64,7 +64,7 @@ An earlier version (asked to write runnable programs) produced a Go struct-to-JS
6464
6565 ## Memory: the models take turns
6666
67-`agent.yaml` runs `../dev.team/team/hooks/unload.js` (the script of [`demos/unload-models`](../unload-models/), one copy kept in dev.team) on every hand-off to `go` or `rust`:
67+`agent.yaml` runs `hooks/unload.js` (the same script as [`demos/unload-models`](../unload-models/)) on every hand-off to `go` or `rust`:
6868
6969 | Hook | When | Unloads |
7070 |---|---|---|
@@ -74,8 +74,8 @@ An earlier version (asked to write runnable programs) produced a Go struct-to-JS
7474 `displayHooks: true` lists both runs under each answer:
7575
7676 ```
77- 🪝 1. preAsk rust · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" self → continue
78- 🪝 2. postAsk rust · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" asked → continue
77+ 🪝 1. preAsk rust · node "$MM_CONFIG_DIR/hooks/unload.js" self → continue
78+ 🪝 2. postAsk rust · node "$MM_CONFIG_DIR/hooks/unload.js" asked → continue
7979 ```
8080
8181 Measured on 2026-10-25 (llmman on the host, `mm -config agent.yaml -p "explique-moi ce qu'est le pattern matching en Rust, avec un exemple"`, `/api/ps` sampled twice a second): MiniCPM5 → nothing → Mellum2 → nothing → MiniCPM5, never both; 37 s for the question.
@@ -64,7 +64,7 @@ An earlier version (asked to write runnable programs) produced a Go struct-to-JS
64 64
65 ## Memory: the models take turns65 ## Memory: the models take turns
66 66
67-`agent.yaml` runs `../dev.team/team/hooks/unload.js` (the script of [`demos/unload-models`](../unload-models/), one copy kept in dev.team) on every hand-off to `go` or `rust`:67+`agent.yaml` runs `hooks/unload.js` (the same script as [`demos/unload-models`](../unload-models/)) on every hand-off to `go` or `rust`:
68 68
69 | Hook | When | Unloads |69 | Hook | When | Unloads |
70 |---|---|---|70 |---|---|---|
@@ -74,8 +74,8 @@ An earlier version (asked to write runnable programs) produced a Go struct-to-JS
74 `displayHooks: true` lists both runs under each answer:74 `displayHooks: true` lists both runs under each answer:
75 75
76 ```76 ```
77- 🪝 1. preAsk rust · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" self → continue77+ 🪝 1. preAsk rust · node "$MM_CONFIG_DIR/hooks/unload.js" self → continue
78- 🪝 2. postAsk rust · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" asked → continue78+ 🪝 2. postAsk rust · node "$MM_CONFIG_DIR/hooks/unload.js" asked → continue
79 ```79 ```
80 80
81 Measured on 2026-10-25 (llmman on the host, `mm -config agent.yaml -p "explique-moi ce qu'est le pattern matching en Rust, avec un exemple"`, `/api/ps` sampled twice a second): MiniCPM5 → nothing → Mellum2 → nothing → MiniCPM5, never both; 37 s for the question.81 Measured on 2026-10-25 (llmman on the host, `mm -config agent.yaml -p "explique-moi ce qu'est le pattern matching en Rust, avec un exemple"`, `/api/ps` sampled twice a second): MiniCPM5 → nothing → Mellum2 → nothing → MiniCPM5, never both; 37 s for the question.
modified demos/coding-helpers/README.fr.md +3 -3
@@ -64,7 +64,7 @@ Une version précédente (à qui l'on demandait des programmes exécutables) a p
6464
6565 ## Mémoire : les modèles se relaient
6666
67-`agent.yaml` lance `../dev.team/team/hooks/unload.js` (le script de [`demos/unload-models`](../unload-models/), une seule copie, gardée dans dev.team) à chaque passage de main à `go` ou `rust` :
67+`agent.yaml` lance `hooks/unload.js` (le même script que [`demos/unload-models`](../unload-models/)) à chaque passage de main à `go` ou `rust` :
6868
6969 | Hook | Quand | Décharge |
7070 |---|---|---|
@@ -74,8 +74,8 @@ Une version précédente (à qui l'on demandait des programmes exécutables) a p
7474 `displayHooks: true` affiche les deux exécutions sous chaque réponse :
7575
7676 ```
77- 🪝 1. preAsk rust · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" self → continue
78- 🪝 2. postAsk rust · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" asked → continue
77+ 🪝 1. preAsk rust · node "$MM_CONFIG_DIR/hooks/unload.js" self → continue
78+ 🪝 2. postAsk rust · node "$MM_CONFIG_DIR/hooks/unload.js" asked → continue
7979 ```
8080
8181 Mesuré le 2026-10-25 (llmman sur l'hôte, `mm -config agent.yaml -p "explique-moi ce qu'est le pattern matching en Rust, avec un exemple"`, `/api/ps` interrogé deux fois par seconde) : MiniCPM5 → rien → Mellum2 → rien → MiniCPM5, jamais les deux ; 37 s pour la question.
@@ -64,7 +64,7 @@ Une version précédente (à qui l'on demandait des programmes exécutables) a p
64 64
65 ## Mémoire : les modèles se relaient65 ## Mémoire : les modèles se relaient
66 66
67-`agent.yaml` lance `../dev.team/team/hooks/unload.js` (le script de [`demos/unload-models`](../unload-models/), une seule copie, gardée dans dev.team) à chaque passage de main à `go` ou `rust` :67+`agent.yaml` lance `hooks/unload.js` (le même script que [`demos/unload-models`](../unload-models/)) à chaque passage de main à `go` ou `rust` :
68 68
69 | Hook | Quand | Décharge |69 | Hook | Quand | Décharge |
70 |---|---|---|70 |---|---|---|
@@ -74,8 +74,8 @@ Une version précédente (à qui l'on demandait des programmes exécutables) a p
74 `displayHooks: true` affiche les deux exécutions sous chaque réponse :74 `displayHooks: true` affiche les deux exécutions sous chaque réponse :
75 75
76 ```76 ```
77- 🪝 1. preAsk rust · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" self → continue77+ 🪝 1. preAsk rust · node "$MM_CONFIG_DIR/hooks/unload.js" self → continue
78- 🪝 2. postAsk rust · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" asked → continue78+ 🪝 2. postAsk rust · node "$MM_CONFIG_DIR/hooks/unload.js" asked → continue
79 ```79 ```
80 80
81 Mesuré le 2026-10-25 (llmman sur l'hôte, `mm -config agent.yaml -p "explique-moi ce qu'est le pattern matching en Rust, avec un exemple"`, `/api/ps` interrogé deux fois par seconde) : MiniCPM5 → rien → Mellum2 → rien → MiniCPM5, jamais les deux ; 37 s pour la question.81 Mesuré le 2026-10-25 (llmman sur l'hôte, `mm -config agent.yaml -p "explique-moi ce qu'est le pattern matching en Rust, avec un exemple"`, `/api/ps` interrogé deux fois par seconde) : MiniCPM5 → rien → Mellum2 → rien → MiniCPM5, jamais les deux ; 37 s pour la question.
modified demos/coding-helpers/agent.yaml +4 -7
@@ -19,15 +19,12 @@
1919 # coordinator MiniCPM5 2B hf.co/openbmb/MiniCPM5-2B-GGUF:Q4_K_M 1.6 GB
2020 # go, rust Mellum2 12B thinking huggingface.co/jetbrains/mellum2-12b-a2.5b-thinking-gguf-q4_k_m:Q4_K_M 8.1 GB (one model for both)
2121 #
22-# unload.js self preAsk unloads the COORDINATOR's model right
22+# hooks/unload.js self preAsk unloads the COORDINATOR's model right
2323 # before the specialist starts
24-# unload.js asked postAsk unloads the SPECIALIST's model once it
24+# hooks/unload.js asked postAsk unloads the SPECIALIST's model once it
2525 # has answered, before the coordinator is
2626 # reloaded to read the answer
2727 #
28-# unload.js is ../dev.team/team/hooks/unload.js: one copy for the three demos
29-# that use it, kept in dev.team because its sandbox mounts only team/.
30-#
3128 # llmman pull hf.co/openbmb/MiniCPM5-2B-GGUF:Q4_K_M
3229 # llmman pull huggingface.co/jetbrains/mellum2-12b-a2.5b-thinking-gguf-q4_k_m:Q4_K_M
3330 # LLMMAN_CONTEXT_LENGTH=32768 llmman serve
@@ -74,12 +71,12 @@ sampling:
7471 hooks:
7572 preAsk:
7673 - matcher: ^(go|rust)$
77- command: node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" self
74+ command: node "$MM_CONFIG_DIR/hooks/unload.js" self
7875 timeout: 30s
7976 onError: warn
8077 postAsk:
8178 - matcher: ^(go|rust)$
82- command: node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" asked
79+ command: node "$MM_CONFIG_DIR/hooks/unload.js" asked
8380 timeout: 30s
8481 onError: warn
8582
@@ -19,15 +19,12 @@
19 # coordinator MiniCPM5 2B hf.co/openbmb/MiniCPM5-2B-GGUF:Q4_K_M 1.6 GB19 # coordinator MiniCPM5 2B hf.co/openbmb/MiniCPM5-2B-GGUF:Q4_K_M 1.6 GB
20 # go, rust Mellum2 12B thinking huggingface.co/jetbrains/mellum2-12b-a2.5b-thinking-gguf-q4_k_m:Q4_K_M 8.1 GB (one model for both)20 # go, rust Mellum2 12B thinking huggingface.co/jetbrains/mellum2-12b-a2.5b-thinking-gguf-q4_k_m:Q4_K_M 8.1 GB (one model for both)
21 #21 #
22-# unload.js self preAsk unloads the COORDINATOR's model right22+# hooks/unload.js self preAsk unloads the COORDINATOR's model right
23 # before the specialist starts23 # before the specialist starts
24-# unload.js asked postAsk unloads the SPECIALIST's model once it24+# hooks/unload.js asked postAsk unloads the SPECIALIST's model once it
25 # has answered, before the coordinator is25 # has answered, before the coordinator is
26 # reloaded to read the answer26 # reloaded to read the answer
27 #27 #
28-# unload.js is ../dev.team/team/hooks/unload.js: one copy for the three demos
29-# that use it, kept in dev.team because its sandbox mounts only team/.
30-#
31 # llmman pull hf.co/openbmb/MiniCPM5-2B-GGUF:Q4_K_M28 # llmman pull hf.co/openbmb/MiniCPM5-2B-GGUF:Q4_K_M
32 # llmman pull huggingface.co/jetbrains/mellum2-12b-a2.5b-thinking-gguf-q4_k_m:Q4_K_M29 # llmman pull huggingface.co/jetbrains/mellum2-12b-a2.5b-thinking-gguf-q4_k_m:Q4_K_M
33 # LLMMAN_CONTEXT_LENGTH=32768 llmman serve30 # LLMMAN_CONTEXT_LENGTH=32768 llmman serve
@@ -74,12 +71,12 @@ sampling:
74 hooks:71 hooks:
75 preAsk:72 preAsk:
76 - matcher: ^(go|rust)$73 - matcher: ^(go|rust)$
77- command: node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" self74+ command: node "$MM_CONFIG_DIR/hooks/unload.js" self
78 timeout: 30s75 timeout: 30s
79 onError: warn76 onError: warn
80 postAsk:77 postAsk:
81 - matcher: ^(go|rust)$78 - matcher: ^(go|rust)$
82- command: node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" asked79+ command: node "$MM_CONFIG_DIR/hooks/unload.js" asked
83 timeout: 30s80 timeout: 30s
84 onError: warn81 onError: warn
85 82
added demos/coding-helpers/hooks/unload.js +58 -0
new file mode 100644
@@ -0,0 +1,58 @@
1+#!/usr/bin/env node
2+// preAsk / postAsk hook: unloads one model so that two models are never in
3+// memory together during a hand-off.
4+//
5+// node unload.js self preAsk: the ASKING agent's own model, right before
6+// mm starts the asked agent. Only mm can do it at
7+// that moment: the model has just decided to call
8+// ask_agent, and it is needed again only to read the
9+// answer — the server reloads it then by itself. The
10+// model cannot do it (unload_model on its own model
11+// lasts until its next step).
12+// node unload.js asked postAsk: the ASKED agent's model, once it has
13+// answered and before the asking agent reads the
14+// answer — so the asker's model reloads alone.
15+//
16+// Input: {"model": "llmman/<model>", "ask": {"agentModel": "llmman/<model>"},
17+// ...}. Server: $LLMMAN_URL, else llmman's default address, else the one a
18+// Docker sandbox reaches the host by. Prints nothing: the hand-off goes on
19+// whatever happens (onError: warn in agent.yaml), an unload is a saving, not
20+// a check.
21+
22+const fs = require("fs");
23+
24+const input = JSON.parse(fs.readFileSync(0, "utf8"));
25+const which = process.argv[2];
26+const ref = which === "asked" ? input.ask && input.ask.agentModel : input.model;
27+if (!ref) {
28+ console.error(`unload.js ${which}: no model in the input`);
29+ process.exit(1);
30+}
31+const model = ref.replace(/^[^/]+\//, ""); // drop the "llmman/" provider prefix
32+
33+const servers = process.env.LLMMAN_URL
34+ ? [process.env.LLMMAN_URL]
35+ : ["http://127.0.0.1:17434", "http://host.docker.internal:17434"];
36+
37+async function unload() {
38+ for (const server of servers) {
39+ try {
40+ const resp = await fetch(server + "/api/generate", {
41+ method: "POST",
42+ headers: { "Content-Type": "application/json" },
43+ body: JSON.stringify({ model, keep_alive: 0 }),
44+ signal: AbortSignal.timeout(20_000),
45+ });
46+ const reply = await resp.json();
47+ if (reply.done_reason === "unload") return;
48+ throw new Error(`${server}: not confirmed: ${JSON.stringify(reply)}`);
49+ } catch (err) {
50+ if (server === servers[servers.length - 1]) throw err;
51+ }
52+ }
53+}
54+
55+unload().catch((err) => {
56+ console.error(`could not unload ${model}: ${err.message}`);
57+ process.exit(1);
58+});
new file mode 100644
@@ -0,0 +1,58 @@
1+#!/usr/bin/env node
2+// preAsk / postAsk hook: unloads one model so that two models are never in
3+// memory together during a hand-off.
4+//
5+// node unload.js self preAsk: the ASKING agent's own model, right before
6+// mm starts the asked agent. Only mm can do it at
7+// that moment: the model has just decided to call
8+// ask_agent, and it is needed again only to read the
9+// answer — the server reloads it then by itself. The
10+// model cannot do it (unload_model on its own model
11+// lasts until its next step).
12+// node unload.js asked postAsk: the ASKED agent's model, once it has
13+// answered and before the asking agent reads the
14+// answer — so the asker's model reloads alone.
15+//
16+// Input: {"model": "llmman/<model>", "ask": {"agentModel": "llmman/<model>"},
17+// ...}. Server: $LLMMAN_URL, else llmman's default address, else the one a
18+// Docker sandbox reaches the host by. Prints nothing: the hand-off goes on
19+// whatever happens (onError: warn in agent.yaml), an unload is a saving, not
20+// a check.
21+
22+const fs = require("fs");
23+
24+const input = JSON.parse(fs.readFileSync(0, "utf8"));
25+const which = process.argv[2];
26+const ref = which === "asked" ? input.ask && input.ask.agentModel : input.model;
27+if (!ref) {
28+ console.error(`unload.js ${which}: no model in the input`);
29+ process.exit(1);
30+}
31+const model = ref.replace(/^[^/]+\//, ""); // drop the "llmman/" provider prefix
32+
33+const servers = process.env.LLMMAN_URL
34+ ? [process.env.LLMMAN_URL]
35+ : ["http://127.0.0.1:17434", "http://host.docker.internal:17434"];
36+
37+async function unload() {
38+ for (const server of servers) {
39+ try {
40+ const resp = await fetch(server + "/api/generate", {
41+ method: "POST",
42+ headers: { "Content-Type": "application/json" },
43+ body: JSON.stringify({ model, keep_alive: 0 }),
44+ signal: AbortSignal.timeout(20_000),
45+ });
46+ const reply = await resp.json();
47+ if (reply.done_reason === "unload") return;
48+ throw new Error(`${server}: not confirmed: ${JSON.stringify(reply)}`);
49+ } catch (err) {
50+ if (server === servers[servers.length - 1]) throw err;
51+ }
52+ }
53+}
54+
55+unload().catch((err) => {
56+ console.error(`could not unload ${model}: ${err.message}`);
57+ process.exit(1);
58+});
modified demos/dev.team/team/hooks/unload.js +0 -4
@@ -1,8 +1,4 @@
11 #!/usr/bin/env node
2-// One copy for three demos: dev.team (here, inside the read-only team/ its
3-// sandbox mounts), and demos/unload-models and demos/coding-helpers, which run
4-// it as ../dev.team/team/hooks/unload.js.
5-//
62 // preAsk / postAsk hook: unloads one model so that two models are never in
73 // memory together during a hand-off.
84 //
@@ -1,8 +1,4 @@
1 #!/usr/bin/env node1 #!/usr/bin/env node
2-// One copy for three demos: dev.team (here, inside the read-only team/ its
3-// sandbox mounts), and demos/unload-models and demos/coding-helpers, which run
4-// it as ../dev.team/team/hooks/unload.js.
5-//
6 // preAsk / postAsk hook: unloads one model so that two models are never in2 // preAsk / postAsk hook: unloads one model so that two models are never in
7 // memory together during a hand-off.3 // memory together during a hand-off.
8 //4 //
modified demos/unload-models/README.en.md +4 -4
@@ -9,7 +9,7 @@ A coordinator hands each programming question to an expert, and the two models t
99 | File | Role |
1010 |---|---|
1111 | `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. |
12-| `../dev.team/team/hooks/unload.js` | The hook (Node.js), shared with coding-helpers and dev.team — it lives in dev.team, whose sandbox mounts only `team/`. `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. |
12+| `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. |
1313 | `agent.expert.yaml` | The **expert** (Qwen3.5 4B): answers programming questions, no tools at all (`unloadModels: false`). |
1414
1515 ## Run the demo
@@ -31,8 +31,8 @@ After the answer, only the coordinator's Qwen3.5 9B is loaded. In the terminal t
3131
3232 ```text
3333 🗣 ask_agent: expert (llmman/hf.co/unsloth/Qwen3.5-4B-GGUF:Q4_K_M) — Explain what a closure is in Ja…
34- 🪝 1. preAsk expert · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" self → continue
35- 🪝 2. postAsk expert · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" asked → continue
34+ 🪝 1. preAsk expert · node "$MM_CONFIG_DIR/hooks/unload.js" self → continue
35+ 🪝 2. postAsk expert · node "$MM_CONFIG_DIR/hooks/unload.js" asked → continue
3636 ```
3737
3838 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.
@@ -54,7 +54,7 @@ What the server holds during one question (measured with `/api/ps` twice a secon
5454 - *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.
5555 - *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.)
5656
57-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. `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.
57+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.
5858
5959 The hooks are also certain: a model can skip an instruction, a hook always runs.
6060
@@ -9,7 +9,7 @@ A coordinator hands each programming question to an expert, and the two models t
9 | File | Role |9 | File | Role |
10 |---|---|10 |---|---|
11 | `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. |11 | `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. |
12-| `../dev.team/team/hooks/unload.js` | The hook (Node.js), shared with coding-helpers and dev.team — it lives in dev.team, whose sandbox mounts only `team/`. `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. |12+| `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. |
13 | `agent.expert.yaml` | The **expert** (Qwen3.5 4B): answers programming questions, no tools at all (`unloadModels: false`). |13 | `agent.expert.yaml` | The **expert** (Qwen3.5 4B): answers programming questions, no tools at all (`unloadModels: false`). |
14 14
15 ## Run the demo15 ## Run the demo
@@ -31,8 +31,8 @@ After the answer, only the coordinator's Qwen3.5 9B is loaded. In the terminal t
31 31
32 ```text32 ```text
33 🗣 ask_agent: expert (llmman/hf.co/unsloth/Qwen3.5-4B-GGUF:Q4_K_M) — Explain what a closure is in Ja…33 🗣 ask_agent: expert (llmman/hf.co/unsloth/Qwen3.5-4B-GGUF:Q4_K_M) — Explain what a closure is in Ja…
34- 🪝 1. preAsk expert · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" self → continue34+ 🪝 1. preAsk expert · node "$MM_CONFIG_DIR/hooks/unload.js" self → continue
35- 🪝 2. postAsk expert · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" asked → continue35+ 🪝 2. postAsk expert · node "$MM_CONFIG_DIR/hooks/unload.js" asked → continue
36 ```36 ```
37 37
38 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.38 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.
@@ -54,7 +54,7 @@ What the server holds during one question (measured with `/api/ps` twice a secon
54 - *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.54 - *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.
55 - *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.)55 - *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.)
56 56
57-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. `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.57+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.
58 58
59 The hooks are also certain: a model can skip an instruction, a hook always runs.59 The hooks are also certain: a model can skip an instruction, a hook always runs.
60 60
modified demos/unload-models/README.fr.md +4 -4
@@ -9,7 +9,7 @@ Un coordinateur confie chaque question de programmation à un expert, et les deu
99 | Fichier | Rôle |
1010 |---|---|
1111 | `agent.yaml` | Le **coordinateur** (Qwen3.5 9B) : `ask_agent` vers l'expert, puis la réponse. Les deux hooks. `/unload` et l'outil `unload_model` fonctionnent aussi ici. `displayHooks: true` affiche l'exécution des hooks. |
12-| `../dev.team/team/hooks/unload.js` | Le hook (Node.js), commun avec coding-helpers et dev.team — il vit dans dev.team, dont le sandbox ne monte que `team/`. `unload.js self` (`preAsk`) : décharge le modèle du coordinateur juste avant que mm lance l'expert. `unload.js asked` (`postAsk`) : décharge le modèle de l'expert une fois sa réponse donnée. |
12+| `hooks/unload.js` | Le hook (Node.js). `unload.js self` (`preAsk`) : décharge le modèle du coordinateur juste avant que mm lance l'expert. `unload.js asked` (`postAsk`) : décharge le modèle de l'expert une fois sa réponse donnée. |
1313 | `agent.expert.yaml` | L'**expert** (Qwen3.5 4B) : répond aux questions de programmation, sans aucun outil (`unloadModels: false`). |
1414
1515 ## Lancer la démo
@@ -31,8 +31,8 @@ Après la réponse, seul le Qwen3.5 9B du coordinateur est chargé. Dans le term
3131
3232 ```text
3333 🗣 ask_agent: expert (llmman/hf.co/unsloth/Qwen3.5-4B-GGUF:Q4_K_M) — Explain what a closure is in Ja…
34- 🪝 1. preAsk expert · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" self → continue
35- 🪝 2. postAsk expert · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" asked → continue
34+ 🪝 1. preAsk expert · node "$MM_CONFIG_DIR/hooks/unload.js" self → continue
35+ 🪝 2. postAsk expert · node "$MM_CONFIG_DIR/hooks/unload.js" asked → continue
3636 ```
3737
3838 À la main : `/unload` décharge le modèle du coordinateur, `/unload <modèle>` n'importe quel autre modèle du même serveur — dans le terminal, la fenêtre et un éditeur. Demander au coordinateur de libérer la mémoire de l'expert (« Unload the expert's model. », « Libère la mémoire de l'expert. ») lui fait appeler `unload_model` sur le modèle de l'expert (4 sur 4 mesurés) : son nom est écrit dans le prompt, car le modèle ne peut pas deviner comment le serveur nomme un modèle.
@@ -54,7 +54,7 @@ Ce que le serveur garde en mémoire pendant une question (mesuré avec `/api/ps`
5454 - *Avant l'expert* : le modèle du coordinateur vient de décider d'appeler `ask_agent`, et il n'en a de nouveau besoin que pour lire la réponse. Le modèle ne peut pas se décharger lui-même — `unload_model` sur son propre modèle ne dure que jusqu'à son étape suivante.
5555 - *Après l'expert* : si le coordinateur appelait `unload_model` sur le modèle de l'expert, il tournerait déjà de nouveau — rechargé à côté du 4B — au moment de le faire. Les deux modèles seraient chargés ensemble pendant toute cette étape. (C'est ce que faisait la version précédente de cette démo ; voir plus bas.)
5656
57-mm exécute les hooks `preAsk` juste avant de lancer l'agent interrogé et les hooks `postAsk` juste après sa réponse, avant que l'agent qui l'a interrogé la lise. `unload.js` lit dans son entrée le modèle à décharger — `"model": "llmman/<modèle>"` pour `self`, `"ask": {"agentModel": "llmman/<modèle>"}` pour `asked` — et envoie `keep_alive: 0` au serveur. `matcher: ^expert$` limite les deux hooks à ce relais. `onError: warn` : si un déchargement échoue, le relais continue.
57+mm exécute les hooks `preAsk` juste avant de lancer l'agent interrogé et les hooks `postAsk` juste après sa réponse, avant que l'agent qui l'a interrogé la lise. `hooks/unload.js` lit dans son entrée le modèle à décharger — `"model": "llmman/<modèle>"` pour `self`, `"ask": {"agentModel": "llmman/<modèle>"}` pour `asked` — et envoie `keep_alive: 0` au serveur. `matcher: ^expert$` limite les deux hooks à ce relais. `onError: warn` : si un déchargement échoue, le relais continue.
5858
5959 Les hooks sont en plus certains : un modèle peut sauter une consigne, un hook s'exécute toujours.
6060
@@ -9,7 +9,7 @@ Un coordinateur confie chaque question de programmation à un expert, et les deu
9 | Fichier | Rôle |9 | Fichier | Rôle |
10 |---|---|10 |---|---|
11 | `agent.yaml` | Le **coordinateur** (Qwen3.5 9B) : `ask_agent` vers l'expert, puis la réponse. Les deux hooks. `/unload` et l'outil `unload_model` fonctionnent aussi ici. `displayHooks: true` affiche l'exécution des hooks. |11 | `agent.yaml` | Le **coordinateur** (Qwen3.5 9B) : `ask_agent` vers l'expert, puis la réponse. Les deux hooks. `/unload` et l'outil `unload_model` fonctionnent aussi ici. `displayHooks: true` affiche l'exécution des hooks. |
12-| `../dev.team/team/hooks/unload.js` | Le hook (Node.js), commun avec coding-helpers et dev.team — il vit dans dev.team, dont le sandbox ne monte que `team/`. `unload.js self` (`preAsk`) : décharge le modèle du coordinateur juste avant que mm lance l'expert. `unload.js asked` (`postAsk`) : décharge le modèle de l'expert une fois sa réponse donnée. |12+| `hooks/unload.js` | Le hook (Node.js). `unload.js self` (`preAsk`) : décharge le modèle du coordinateur juste avant que mm lance l'expert. `unload.js asked` (`postAsk`) : décharge le modèle de l'expert une fois sa réponse donnée. |
13 | `agent.expert.yaml` | L'**expert** (Qwen3.5 4B) : répond aux questions de programmation, sans aucun outil (`unloadModels: false`). |13 | `agent.expert.yaml` | L'**expert** (Qwen3.5 4B) : répond aux questions de programmation, sans aucun outil (`unloadModels: false`). |
14 14
15 ## Lancer la démo15 ## Lancer la démo
@@ -31,8 +31,8 @@ Après la réponse, seul le Qwen3.5 9B du coordinateur est chargé. Dans le term
31 31
32 ```text32 ```text
33 🗣 ask_agent: expert (llmman/hf.co/unsloth/Qwen3.5-4B-GGUF:Q4_K_M) — Explain what a closure is in Ja…33 🗣 ask_agent: expert (llmman/hf.co/unsloth/Qwen3.5-4B-GGUF:Q4_K_M) — Explain what a closure is in Ja…
34- 🪝 1. preAsk expert · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" self → continue34+ 🪝 1. preAsk expert · node "$MM_CONFIG_DIR/hooks/unload.js" self → continue
35- 🪝 2. postAsk expert · node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" asked → continue35+ 🪝 2. postAsk expert · node "$MM_CONFIG_DIR/hooks/unload.js" asked → continue
36 ```36 ```
37 37
38 À la main : `/unload` décharge le modèle du coordinateur, `/unload <modèle>` n'importe quel autre modèle du même serveur — dans le terminal, la fenêtre et un éditeur. Demander au coordinateur de libérer la mémoire de l'expert (« Unload the expert's model. », « Libère la mémoire de l'expert. ») lui fait appeler `unload_model` sur le modèle de l'expert (4 sur 4 mesurés) : son nom est écrit dans le prompt, car le modèle ne peut pas deviner comment le serveur nomme un modèle.38 À la main : `/unload` décharge le modèle du coordinateur, `/unload <modèle>` n'importe quel autre modèle du même serveur — dans le terminal, la fenêtre et un éditeur. Demander au coordinateur de libérer la mémoire de l'expert (« Unload the expert's model. », « Libère la mémoire de l'expert. ») lui fait appeler `unload_model` sur le modèle de l'expert (4 sur 4 mesurés) : son nom est écrit dans le prompt, car le modèle ne peut pas deviner comment le serveur nomme un modèle.
@@ -54,7 +54,7 @@ Ce que le serveur garde en mémoire pendant une question (mesuré avec `/api/ps`
54 - *Avant l'expert* : le modèle du coordinateur vient de décider d'appeler `ask_agent`, et il n'en a de nouveau besoin que pour lire la réponse. Le modèle ne peut pas se décharger lui-même — `unload_model` sur son propre modèle ne dure que jusqu'à son étape suivante.54 - *Avant l'expert* : le modèle du coordinateur vient de décider d'appeler `ask_agent`, et il n'en a de nouveau besoin que pour lire la réponse. Le modèle ne peut pas se décharger lui-même — `unload_model` sur son propre modèle ne dure que jusqu'à son étape suivante.
55 - *Après l'expert* : si le coordinateur appelait `unload_model` sur le modèle de l'expert, il tournerait déjà de nouveau — rechargé à côté du 4B — au moment de le faire. Les deux modèles seraient chargés ensemble pendant toute cette étape. (C'est ce que faisait la version précédente de cette démo ; voir plus bas.)55 - *Après l'expert* : si le coordinateur appelait `unload_model` sur le modèle de l'expert, il tournerait déjà de nouveau — rechargé à côté du 4B — au moment de le faire. Les deux modèles seraient chargés ensemble pendant toute cette étape. (C'est ce que faisait la version précédente de cette démo ; voir plus bas.)
56 56
57-mm exécute les hooks `preAsk` juste avant de lancer l'agent interrogé et les hooks `postAsk` juste après sa réponse, avant que l'agent qui l'a interrogé la lise. `unload.js` lit dans son entrée le modèle à décharger — `"model": "llmman/<modèle>"` pour `self`, `"ask": {"agentModel": "llmman/<modèle>"}` pour `asked` — et envoie `keep_alive: 0` au serveur. `matcher: ^expert$` limite les deux hooks à ce relais. `onError: warn` : si un déchargement échoue, le relais continue.57+mm exécute les hooks `preAsk` juste avant de lancer l'agent interrogé et les hooks `postAsk` juste après sa réponse, avant que l'agent qui l'a interrogé la lise. `hooks/unload.js` lit dans son entrée le modèle à décharger — `"model": "llmman/<modèle>"` pour `self`, `"ask": {"agentModel": "llmman/<modèle>"}` pour `asked` — et envoie `keep_alive: 0` au serveur. `matcher: ^expert$` limite les deux hooks à ce relais. `onError: warn` : si un déchargement échoue, le relais continue.
58 58
59 Les hooks sont en plus certains : un modèle peut sauter une consigne, un hook s'exécute toujours.59 Les hooks sont en plus certains : un modèle peut sauter une consigne, un hook s'exécute toujours.
60 60
modified demos/unload-models/agent.yaml +4 -7
@@ -1,16 +1,13 @@
11 # Unload models — a coordinator hands each programming question to an expert,
22 # and the two models take turns in memory, never loaded together:
33 #
4-# unload.js self preAsk unloads the COORDINATOR's model right
4+# hooks/unload.js self preAsk unloads the COORDINATOR's model right
55 # before the expert starts (only mm can do
66 # it at that moment)
7-# unload.js asked postAsk unloads the EXPERT's model once it has
7+# hooks/unload.js asked postAsk unloads the EXPERT's model once it has
88 # answered, before the coordinator is
99 # reloaded to read the answer
1010 #
11-# unload.js is ../dev.team/team/hooks/unload.js: one copy for the three demos
12-# that use it, kept in dev.team because its sandbox mounts only team/.
13-#
1411 # coordinator Qwen3.5 9B hf.co/unsloth/Qwen3.5-9B-GGUF:Q4_K_M (this file)
1512 # expert Qwen3.5 4B hf.co/unsloth/Qwen3.5-4B-GGUF:Q4_K_M (agent.expert.yaml)
1613 #
@@ -70,12 +67,12 @@ hooks:
7067 # onError: warn — an unload is a saving, not a check: the hand-off goes on.
7168 preAsk:
7269 - matcher: ^expert$
73- command: node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" self
70+ command: node "$MM_CONFIG_DIR/hooks/unload.js" self
7471 timeout: 30s
7572 onError: warn
7673 postAsk:
7774 - matcher: ^expert$
78- command: node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" asked
75+ command: node "$MM_CONFIG_DIR/hooks/unload.js" asked
7976 timeout: 30s
8077 onError: warn
8178
@@ -1,16 +1,13 @@
1 # Unload models — a coordinator hands each programming question to an expert,1 # Unload models — a coordinator hands each programming question to an expert,
2 # and the two models take turns in memory, never loaded together:2 # and the two models take turns in memory, never loaded together:
3 #3 #
4-# unload.js self preAsk unloads the COORDINATOR's model right4+# hooks/unload.js self preAsk unloads the COORDINATOR's model right
5 # before the expert starts (only mm can do5 # before the expert starts (only mm can do
6 # it at that moment)6 # it at that moment)
7-# unload.js asked postAsk unloads the EXPERT's model once it has7+# hooks/unload.js asked postAsk unloads the EXPERT's model once it has
8 # answered, before the coordinator is8 # answered, before the coordinator is
9 # reloaded to read the answer9 # reloaded to read the answer
10 #10 #
11-# unload.js is ../dev.team/team/hooks/unload.js: one copy for the three demos
12-# that use it, kept in dev.team because its sandbox mounts only team/.
13-#
14 # coordinator Qwen3.5 9B hf.co/unsloth/Qwen3.5-9B-GGUF:Q4_K_M (this file)11 # coordinator Qwen3.5 9B hf.co/unsloth/Qwen3.5-9B-GGUF:Q4_K_M (this file)
15 # expert Qwen3.5 4B hf.co/unsloth/Qwen3.5-4B-GGUF:Q4_K_M (agent.expert.yaml)12 # expert Qwen3.5 4B hf.co/unsloth/Qwen3.5-4B-GGUF:Q4_K_M (agent.expert.yaml)
16 #13 #
@@ -70,12 +67,12 @@ hooks:
70 # onError: warn — an unload is a saving, not a check: the hand-off goes on.67 # onError: warn — an unload is a saving, not a check: the hand-off goes on.
71 preAsk:68 preAsk:
72 - matcher: ^expert$69 - matcher: ^expert$
73- command: node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" self70+ command: node "$MM_CONFIG_DIR/hooks/unload.js" self
74 timeout: 30s71 timeout: 30s
75 onError: warn72 onError: warn
76 postAsk:73 postAsk:
77 - matcher: ^expert$74 - matcher: ^expert$
78- command: node "$MM_CONFIG_DIR/../dev.team/team/hooks/unload.js" asked75+ command: node "$MM_CONFIG_DIR/hooks/unload.js" asked
79 timeout: 30s76 timeout: 30s
80 onError: warn77 onError: warn
81 78
added demos/unload-models/hooks/unload.js +58 -0
new file mode 100644
@@ -0,0 +1,58 @@
1+#!/usr/bin/env node
2+// preAsk / postAsk hook: unloads one model so that two models are never in
3+// memory together during a hand-off.
4+//
5+// node unload.js self preAsk: the ASKING agent's own model, right before
6+// mm starts the asked agent. Only mm can do it at
7+// that moment: the model has just decided to call
8+// ask_agent, and it is needed again only to read the
9+// answer — the server reloads it then by itself. The
10+// model cannot do it (unload_model on its own model
11+// lasts until its next step).
12+// node unload.js asked postAsk: the ASKED agent's model, once it has
13+// answered and before the asking agent reads the
14+// answer — so the asker's model reloads alone.
15+//
16+// Input: {"model": "llmman/<model>", "ask": {"agentModel": "llmman/<model>"},
17+// ...}. Server: $LLMMAN_URL, else llmman's default address, else the one a
18+// Docker sandbox reaches the host by. Prints nothing: the hand-off goes on
19+// whatever happens (onError: warn in agent.yaml), an unload is a saving, not
20+// a check.
21+
22+const fs = require("fs");
23+
24+const input = JSON.parse(fs.readFileSync(0, "utf8"));
25+const which = process.argv[2];
26+const ref = which === "asked" ? input.ask && input.ask.agentModel : input.model;
27+if (!ref) {
28+ console.error(`unload.js ${which}: no model in the input`);
29+ process.exit(1);
30+}
31+const model = ref.replace(/^[^/]+\//, ""); // drop the "llmman/" provider prefix
32+
33+const servers = process.env.LLMMAN_URL
34+ ? [process.env.LLMMAN_URL]
35+ : ["http://127.0.0.1:17434", "http://host.docker.internal:17434"];
36+
37+async function unload() {
38+ for (const server of servers) {
39+ try {
40+ const resp = await fetch(server + "/api/generate", {
41+ method: "POST",
42+ headers: { "Content-Type": "application/json" },
43+ body: JSON.stringify({ model, keep_alive: 0 }),
44+ signal: AbortSignal.timeout(20_000),
45+ });
46+ const reply = await resp.json();
47+ if (reply.done_reason === "unload") return;
48+ throw new Error(`${server}: not confirmed: ${JSON.stringify(reply)}`);
49+ } catch (err) {
50+ if (server === servers[servers.length - 1]) throw err;
51+ }
52+ }
53+}
54+
55+unload().catch((err) => {
56+ console.error(`could not unload ${model}: ${err.message}`);
57+ process.exit(1);
58+});
new file mode 100644
@@ -0,0 +1,58 @@
1+#!/usr/bin/env node
2+// preAsk / postAsk hook: unloads one model so that two models are never in
3+// memory together during a hand-off.
4+//
5+// node unload.js self preAsk: the ASKING agent's own model, right before
6+// mm starts the asked agent. Only mm can do it at
7+// that moment: the model has just decided to call
8+// ask_agent, and it is needed again only to read the
9+// answer — the server reloads it then by itself. The
10+// model cannot do it (unload_model on its own model
11+// lasts until its next step).
12+// node unload.js asked postAsk: the ASKED agent's model, once it has
13+// answered and before the asking agent reads the
14+// answer — so the asker's model reloads alone.
15+//
16+// Input: {"model": "llmman/<model>", "ask": {"agentModel": "llmman/<model>"},
17+// ...}. Server: $LLMMAN_URL, else llmman's default address, else the one a
18+// Docker sandbox reaches the host by. Prints nothing: the hand-off goes on
19+// whatever happens (onError: warn in agent.yaml), an unload is a saving, not
20+// a check.
21+
22+const fs = require("fs");
23+
24+const input = JSON.parse(fs.readFileSync(0, "utf8"));
25+const which = process.argv[2];
26+const ref = which === "asked" ? input.ask && input.ask.agentModel : input.model;
27+if (!ref) {
28+ console.error(`unload.js ${which}: no model in the input`);
29+ process.exit(1);
30+}
31+const model = ref.replace(/^[^/]+\//, ""); // drop the "llmman/" provider prefix
32+
33+const servers = process.env.LLMMAN_URL
34+ ? [process.env.LLMMAN_URL]
35+ : ["http://127.0.0.1:17434", "http://host.docker.internal:17434"];
36+
37+async function unload() {
38+ for (const server of servers) {
39+ try {
40+ const resp = await fetch(server + "/api/generate", {
41+ method: "POST",
42+ headers: { "Content-Type": "application/json" },
43+ body: JSON.stringify({ model, keep_alive: 0 }),
44+ signal: AbortSignal.timeout(20_000),
45+ });
46+ const reply = await resp.json();
47+ if (reply.done_reason === "unload") return;
48+ throw new Error(`${server}: not confirmed: ${JSON.stringify(reply)}`);
49+ } catch (err) {
50+ if (server === servers[servers.length - 1]) throw err;
51+ }
52+ }
53+}
54+
55+unload().catch((err) => {
56+ console.error(`could not unload ${model}: ${err.message}`);
57+ process.exit(1);
58+});