Skip to content

local ​

Manage and run local models. A GGUF model downloads by curated short name or Hugging Face URI and runs inside the Agency process through smoltalk-llama-cpp. MLX models run in a separate server. Start that server with agency local serve, or start mlx_lm.server yourself.

Names and downloads also support diffusers: image-model targets. The chat registration helpers are intended for GGUF and MLX models.

ts
import { registerLocalModel } from "std::agency/local"

node main() {
  // download if needed, register the provider, and get the local path
  const model = registerLocalModel("smollm2-135m")
  print(model)
}

Types ​

DownloadedModel ​

A downloaded model. GGUF entries use the filename as name; served models use a repository ID and directory path. Check complete before trying to serve a model whose download may have been interrupted.

ts
/** A downloaded model. GGUF entries use the filename as `name`; served
    models use a repository ID and directory path. Check `complete` before
    trying to serve a model whose download may have been interrupted. */
export type DownloadedModel = {
  name: string;
  path: string;
  sizeBytes: number;
  backend: string;
  complete: boolean;
  kind?: string
}

(source)

ModelName ​

A usable short name, its backend and target, and available catalog metadata.

ts
/** A usable short name, its backend and target, and available catalog metadata. */
export type ModelName = {
  name: string;
  backend: string;
  target: string;
  source: string;
  params?: string;
  sizeBytes?: number;
  kind?: string;
  tags?: string[];
  description?: string;
  contextWindow?: number;
  license?: string
}

(source)

SkippedAlias ​

A remote catalog entry skipped because a user-owned alias keeps the same name.

ts
/** A remote catalog entry skipped because a user-owned alias keeps the same name. */
export type SkippedAlias = {
  name: string;
  keptUri: string;
  remoteUri: string
}

(source)

RefreshResult ​

Catalog refresh changes, including skipped aliases and the total catalog size.

ts
/** Catalog refresh changes, including skipped aliases and the total catalog size. */
export type RefreshResult = {
  url: string;
  file: string;
  added: string[];
  updated: string[];
  unchanged: string[];
  removed: string[];
  skipped: SkippedAlias[];
  modelCount: number
}

(source)

Functions ​

localModelsSupported ​

ts
localModelsSupported(): bool

Check whether the smoltalk-llama-cpp provider package can be found.

Checks local and global package locations. This is a GGUF-provider check; it does not probe MLX or image-model servers.

Returns: bool

(source)

resolveModelName ​

ts
resolveModelName(value: string): string

Resolve a local-model short name or alias to its URI or filesystem target.

Parameters:

NameTypeDefaultDescription
valuestringA catalog name, alias, model URI, GGUF path, or model directory.

Returns: string

(source)

downloadModel ​

ts
downloadModel(value: string, cacheDir: string = ""): string

Download a local model or find its existing cached copy.

Reuses cached files and resumes interrupted served-model downloads. Returns the local GGUF file path or served-model directory. The default cache comes from AGENCY_MODELS_DIR, then client.modelsDir, then ~/.agency-agent/models.

Parameters:

NameTypeDefaultDescription
valuestringA catalog name, alias, model URI, GGUF path, or model directory.
cacheDirstring""The models directory, or empty to use the configured per-user cache.

Returns: string

Needs: fileRead, fileWrite, network

(source)

listDownloadedModels ​

ts
listDownloadedModels(cacheDir: string = ""): DownloadedModel[]

List downloaded GGUF files and served-model directories.

Parameters:

NameTypeDefaultDescription
cacheDirstring""The models directory, or empty to use the configured per-user cache.

Returns: DownloadedModel[]

Needs: fileRead

(source)

listModelNames ​

ts
listModelNames(): ModelName[]

List curated model short names and configured aliases.

Returns: ModelName[]

Needs: fileRead

(source)

aliasModel ​

ts
aliasModel(name: string, uri: string): string

Save a short-name alias for a model target.

Writes the alias to the selected Agency configuration and returns that file's path. An alias with the same name as a curated entry takes precedence.

Parameters:

NameTypeDefaultDescription
namestring
uristringA model URI, GGUF path, or model directory to associate with the alias.

Returns: string

Needs: fileRead, fileWrite

(source)

unaliasModel ​

ts
unaliasModel(name: string): string

Remove a configured model alias.

Removes the alias from its configuration file and returns that file's path. Downloaded model files remain on disk.

Parameters:

NameTypeDefault
namestring

Returns: string

Needs: fileRead, fileWrite

(source)

removeModel ​

ts
removeModel(name: string, cacheDir: string = ""): bool

Delete a downloaded model file from the models cache.

Deletes a cached file without removing its aliases. Returns false if the target is missing or is a directory. Use unaliasModel when you only want to remove the short name.

Parameters:

NameTypeDefaultDescription
namestringThe model filename within the cache, rather than an alias or model directory.
cacheDirstring""The models directory, or empty to use the configured per-user cache.

Returns: bool

Needs: fileRead, fileWrite

(source)

localModelBackend ​

ts
localModelBackend(value: string): string

Identify a model's backend: llama-cpp, mlx, or diffusers.

Parameters:

NameTypeDefaultDescription
valuestringA catalog name, alias, model URI, GGUF path, or model directory.

Returns: string

(source)

mlxServedName ​

ts
mlxServedName(value: string): string

Resolve the model name to send to an MLX server.

For an MLX URI, returns the repository ID. For a model directory, returns its absolute path. Configure the server with the same model name.

Parameters:

NameTypeDefaultDescription
valuestringAn MLX model name, alias, URI, or model directory.

Returns: string

(source)

registerLocalProvider ​

ts
registerLocalProvider()

Register the llama-cpp provider so local models can be used for LLM calls.

(source)

registerLocalModel ​

ts
registerLocalModel(value: string, cacheDir: string = ""): string

Prepare a GGUF model for local inference, or resolve an MLX server model name.

For GGUF, registers llama-cpp and downloads the model if needed, then returns its local path. For MLX, returns the server model name without downloading or starting a server. Start the server before calling the model through the mlx provider.

Parameters:

NameTypeDefaultDescription
valuestringA GGUF or MLX catalog name, alias, URI, file path, or model directory.
cacheDirstring""The GGUF download directory, or empty to use the configured per-user cache.

Returns: string

Needs: fileRead, fileWrite, network

(source)

printLocalCatalog ​

ts
printLocalCatalog()

Print curated model names and aliases as an aligned terminal table.

Displays the same catalog as agency local alias list.

Needs: fileRead, terminal

(source)

mlxServerModels ​

ts
mlxServerModels(baseUrl: string = ""): string[] | null

List the model IDs an MLX server reports, or null when the probe fails.

Use this to check the server before selecting a model. Null also covers an unsuccessful or unreadable response, so it does not prove the server process is absent. URL precedence is the explicit argument, client.baseUrl.mlx, MLX_BASE_URL, then http://127.0.0.1:8080/v1.

Parameters:

NameTypeDefaultDescription
baseUrlstring""The server's OpenAI-compatible base URL, or empty for the configured mlx endpoint.

Returns: string[] | null

Needs: network

(source)

mlxServerRunning ​

ts
mlxServerRunning(baseUrl: string = ""): boolean

Check whether the configured MLX endpoint answers the model-list probe.

Parameters:

NameTypeDefaultDescription
baseUrlstring""The server's OpenAI-compatible base URL, or empty for the configured mlx endpoint.

Returns: boolean

Needs: network

(source)

refreshCatalog ​

ts
refreshCatalog(url: string = ""): RefreshResult

Refresh remote-managed model aliases from the model catalog, preserving user-owned aliases.

Performs the same refresh as agency local refresh. It updates aliases marked source: "remote", adds new catalog entries, and removes entries the remote catalog dropped. User-owned aliases win name collisions. A fetch, parse, or validation failure throws and leaves the configuration untouched.

Parameters:

NameTypeDefaultDescription
urlstring""Leave empty to use AGENCY_MODEL_CATALOG_URL, then client.modelCatalogUrl, then the built-in catalog URL.

Returns: RefreshResult

Needs: fileRead, fileWrite, network

(source)