bots-garden/mini-mepublic Fork
⑂ feature/improve-init
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 feature/improve-init · k33g · 4d ago
unload-a-model.md · 58 lines · 3.6 KBmarkdown
Blame HistoryOpen raw

How to free a model's memory

This guide shows how to unload a model from the model server's memory without stopping the server: by hand with /unload, or by the agent itself with its unload_model tool — typically to free the memory of another agent's model once its answer is in. It assumes mm runs on llmman, Ollama, or llama-server in router mode. The model reloads by itself the next time something uses it.

Unload by hand

Type, in the terminal, the window or an editor:

/unload

The agent's own model is unloaded:

🧹 unloaded hf.co/unsloth/Qwen3.5-9B-GGUF:Q4_K_M

Name another model served by the same server to unload that one instead:

/unload hf.co/unsloth/Qwen3.5-9B-GGUF:Q4_K_M

A model that is not loaded gives 🧹 <model> was not loaded: nothing to unload; nothing is sent to the server, so nothing is loaded either. Check what is loaded with llmman ps, ollama ps, or curl <server>/api/ps.

Let the agent unload a model

The unload_model tool is declared by default. Tell the model when to use it, in its system prompt. The case it serves best is another agent's model, once that agent has answered:

mmConfigs:
  expert:
    path: agent.expert.yaml
    description: Programming expert.

system: |
  For every question about programming, do these three steps, in order:
  1. Call ask_agent with agent "expert" and the user's question.
  2. Call unload_model with model "hf.co/unsloth/Qwen3.5-9B-GGUF:Q4_K_M".
     It is ALWAYS your next action after ask_agent: never answer the user
     before you have called unload_model.
  3. Then give the expert's answer to the user.

Write the model's name exactly as the server lists it: the model cannot guess it. demos/unload-models/ does the expert's unload with a postAsk hook instead (see the variants below); its coordinator still calls unload_model when the user asks it to free the expert's memory.

Variants

  • The agent's own model. unload_model with an empty model unloads it, but only until the agent's next step: the agent needs its model to read the tool's result, and the server reloads it. Use /unload between two questions instead — or, to free it while another agent works, a preAsk hook that unloads the model named in its input ("model": "<provider>/<model>") right before the asked agent starts: demos/unload-models/hooks/unload.js self.
  • A guarantee instead of an instruction. A small model may skip the step (measured: 4 times out of 5 with MiniCPM5 2B in the first version of demos/unload-models), and the agent's own model is already reloaded beside the other one when it calls the tool. For a certain unload, with the two models never loaded together, have a postAsk hook call the server itself — curl -s <server>/api/generate -d '{"model":"…","keep_alive":0}' — once the asked agent has answered and before the asking agent reads the answer: demos/unload-models/hooks/unload.js asked reads the asked agent's model from ask.agentModel. See Control the hand-offs with hooks.
  • llama-server. Only router mode (started without -m) can unload a model. A single-model server answers with the alternatives: --sleep-idle-seconds N frees the memory after N idle seconds, or stop the server.
  • Turn it off. unloadModels: false removes both /unload and the tool — for an agent that must not have one more tool, such as a guard or a narrow specialist.

See also

 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
# How to free a model's memory

This guide shows how to unload a model from the model server's memory without stopping the server: by hand with `/unload`, or by the agent itself with its `unload_model` tool — typically to free the memory of another agent's model once its answer is in. It assumes mm runs on llmman, Ollama, or llama-server in router mode. The model reloads by itself the next time something uses it.

## Unload by hand

Type, in the terminal, the window or an editor:

```text
/unload
```

The agent's own model is unloaded:

```text
🧹 unloaded hf.co/unsloth/Qwen3.5-9B-GGUF:Q4_K_M
```

Name another model served by the same server to unload that one instead:

```text
/unload hf.co/unsloth/Qwen3.5-9B-GGUF:Q4_K_M
```

A model that is not loaded gives `🧹 <model> was not loaded: nothing to unload`; nothing is sent to the server, so nothing is loaded either. Check what is loaded with `llmman ps`, `ollama ps`, or `curl <server>/api/ps`.

## Let the agent unload a model

The `unload_model` tool is declared by default. Tell the model when to use it, in its `system` prompt. The case it serves best is another agent's model, once that agent has answered:

```yaml
mmConfigs:
  expert:
    path: agent.expert.yaml
    description: Programming expert.

system: |
  For every question about programming, do these three steps, in order:
  1. Call ask_agent with agent "expert" and the user's question.
  2. Call unload_model with model "hf.co/unsloth/Qwen3.5-9B-GGUF:Q4_K_M".
     It is ALWAYS your next action after ask_agent: never answer the user
     before you have called unload_model.
  3. Then give the expert's answer to the user.
```

Write the model's name exactly as the server lists it: the model cannot guess it. `demos/unload-models/` does the expert's unload with a `postAsk` hook instead (see the variants below); its coordinator still calls `unload_model` when the user asks it to free the expert's memory.

## Variants

- **The agent's own model.** `unload_model` with an empty `model` unloads it, but only until the agent's next step: the agent needs its model to read the tool's result, and the server reloads it. Use `/unload` between two questions instead — or, to free it while another agent works, a `preAsk` hook that unloads the model named in its input (`"model": "<provider>/<model>"`) right before the asked agent starts: `demos/unload-models/hooks/unload.js self`.
- **A guarantee instead of an instruction.** A small model may skip the step (measured: 4 times out of 5 with MiniCPM5 2B in the first version of `demos/unload-models`), and the agent's own model is already reloaded beside the other one when it calls the tool. For a certain unload, with the two models never loaded together, have a `postAsk` hook call the server itself — `curl -s <server>/api/generate -d '{"model":"…","keep_alive":0}'` — once the asked agent has answered and before the asking agent reads the answer: `demos/unload-models/hooks/unload.js asked` reads the asked agent's model from `ask.agentModel`. See [Control the hand-offs with hooks](control-agent-calls-with-hooks.md).
- **llama-server.** Only router mode (started without `-m`) can unload a model. A single-model server answers with the alternatives: `--sleep-idle-seconds N` frees the memory after N idle seconds, or stop the server.
- **Turn it off.** `unloadModels: false` removes both `/unload` and the tool — for an agent that must not have one more tool, such as a guard or a narrow specialist.

## See also

- [`unload_model` reference](../reference/tools.md#unload_model) and [`/unload`](../reference/slash-commands.md#commands)
- [`unloadModels`](../reference/configuration.md)