agentleFS
badgidsbadgids/Story-Film-Skills/skills/llm-model-lifecycle/SKILL.md

llm-model-lifecycle

Skill4 starsChanged 3 months agoApache-2.0View on GitHub

Deterministically snapshot, unload, verify, and restore models on a local llama.cpp llama-server router or Ollama server during resource-safe ComfyUI generation without asking the LLM to invent lifecycle scripts.

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 5 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when Story-Film must release local LLM memory for ComfyUI and later restore the model state that existed before the handoff.

    line 11
  2. Distinctive:

    Use the endpoint already reported by Pi, the project resource policy, or a trusted runtime source.

    line 19
  3. Very specific:

    Use scripts/llm_model_lifecycle.py.

    line 21
  4. Very specific:

    Prefer the auto adapter when the endpoint may be either a llama.cpp router or Ollama.

    line 22
  5. Very specific:

    Before unloading, snapshot the exact set of resident models to 00_project/llm_model_snapshot.json.

    line 23
  6. Distinctive:

    Verify the restored model set before returning control to normal Story-Film work.

    line 26
  7. Distinctive:

    Do not kill or restart the whole model server merely to free model memory when its native model lifecycle API is available.

    line 27
  8. Very specific:

    Keep the legacy command resource-handoff adapter only for installations whose server does not expose a supported native model lifecycle API.

    line 28
  9. Distinctive:

    Use the router model API:

    line 32

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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

LLM Model Lifecycle

Use this skill when Story-Film must release local LLM memory for ComfyUI and later restore the model state that existed before the handoff.

Read

Read ../../references/RESOURCE_SAFE_GENERATION.md.

Required behavior

  1. Use the endpoint already reported by Pi, the project resource policy, or a trusted runtime source.
  2. Prove that the endpoint is local with scripts/llm_runtime.py or the lifecycle helper's local-only guard.
  3. Use scripts/llm_model_lifecycle.py. Never author an ad hoc curl, jq, shell loop, or one-off Python lifecycle script.
  4. Prefer the auto adapter when the endpoint may be either a llama.cpp router or Ollama. Explicit llama-server and ollama adapters are also supported.
  5. Before unloading, snapshot the exact set of resident models to 00_project/llm_model_snapshot.json.
  6. Unload through the server's native model API and verify that the models are actually absent from memory.
  7. During restore, remove untracked temporary models that appeared while ComfyUI was running, then restore the original snapshot exactly.
  8. Verify the restored model set before returning control to normal Story-Film work.
  9. Do not kill or restart the whole model server merely to free model memory when its native model lifecycle API is available.
  10. Keep the legacy command resource-handoff adapter only for installations whose server does not expose a supported native model lifecycle API.

llama.cpp router mode

Use the router model API:

GET  /models
POST /models/unload   {"model": "<id>"}
POST /models/load     {"model": "<id>"}

Poll the model list and status after every load or unload. Do not assume that a successful HTTP response means memory has already reached the requested state.

Ollama

Use:

GET  /api/ps
POST /api/generate

For unload, send an empty generation request with keep_alive set to 0. For restore, send an empty generation request with the configured restore keep-alive value. Verify both operations through /api/ps.

Commands

Inspect the currently resident model set:

python scripts/llm_model_lifecycle.py list --runtime auto --endpoint <local-endpoint>

Snapshot and unload:

python scripts/llm_model_lifecycle.py snapshot-unload --runtime auto --endpoint <local-endpoint> --state 00_project/llm_model_snapshot.json

Restore the snapshot:

python scripts/llm_model_lifecycle.py restore --state 00_project/llm_model_snapshot.json

The resource-safe handoff calls these operations directly. The agent must not replace them with generated scripts.

Done

Done when the original local model set is restored and verified, or when a deterministic lifecycle error is recorded for the next model turn.

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.