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.
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.
/** 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.
/** 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.
/** 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.
/** 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
localModelsSupported(): boolCheck 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
resolveModelName(value: string): stringResolve a local-model short name or alias to its URI or filesystem target.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| value | string | A catalog name, alias, model URI, GGUF path, or model directory. |
Returns: string
(source)
downloadModel
downloadModel(value: string, cacheDir: string = ""): stringDownload 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:
| Name | Type | Default | Description |
|---|---|---|---|
| value | string | A catalog name, alias, model URI, GGUF path, or model directory. | |
| cacheDir | string | "" | The models directory, or empty to use the configured per-user cache. |
Returns: string
Needs: fileRead, fileWrite, network
(source)
listDownloadedModels
listDownloadedModels(cacheDir: string = ""): DownloadedModel[]List downloaded GGUF files and served-model directories.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| cacheDir | string | "" | The models directory, or empty to use the configured per-user cache. |
Returns: DownloadedModel[]
Needs: fileRead
(source)
listModelNames
listModelNames(): ModelName[]List curated model short names and configured aliases.
Returns: ModelName[]
Needs: fileRead
(source)
aliasModel
aliasModel(name: string, uri: string): stringSave 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:
| Name | Type | Default | Description |
|---|---|---|---|
| name | string | ||
| uri | string | A model URI, GGUF path, or model directory to associate with the alias. |
Returns: string
Needs: fileRead, fileWrite
(source)
unaliasModel
unaliasModel(name: string): stringRemove a configured model alias.
Removes the alias from its configuration file and returns that file's path. Downloaded model files remain on disk.
Parameters:
| Name | Type | Default |
|---|---|---|
| name | string |
Returns: string
Needs: fileRead, fileWrite
(source)
removeModel
removeModel(name: string, cacheDir: string = ""): boolDelete 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:
| Name | Type | Default | Description |
|---|---|---|---|
| name | string | The model filename within the cache, rather than an alias or model directory. | |
| cacheDir | string | "" | The models directory, or empty to use the configured per-user cache. |
Returns: bool
Needs: fileRead, fileWrite
(source)
localModelBackend
localModelBackend(value: string): stringIdentify a model's backend: llama-cpp, mlx, or diffusers.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| value | string | A catalog name, alias, model URI, GGUF path, or model directory. |
Returns: string
(source)
mlxServedName
mlxServedName(value: string): stringResolve 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:
| Name | Type | Default | Description |
|---|---|---|---|
| value | string | An MLX model name, alias, URI, or model directory. |
Returns: string
(source)
registerLocalProvider
registerLocalProvider()Register the llama-cpp provider so local models can be used for LLM calls.
(source)
registerLocalModel
registerLocalModel(value: string, cacheDir: string = ""): stringPrepare 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:
| Name | Type | Default | Description |
|---|---|---|---|
| value | string | A GGUF or MLX catalog name, alias, URI, file path, or model directory. | |
| cacheDir | string | "" | The GGUF download directory, or empty to use the configured per-user cache. |
Returns: string
Needs: fileRead, fileWrite, network
(source)
printLocalCatalog
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
mlxServerModels(baseUrl: string = ""): string[] | nullList 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:
| Name | Type | Default | Description |
|---|---|---|---|
| baseUrl | string | "" | The server's OpenAI-compatible base URL, or empty for the configured mlx endpoint. |
Returns: string[] | null
Needs: network
(source)
mlxServerRunning
mlxServerRunning(baseUrl: string = ""): booleanCheck whether the configured MLX endpoint answers the model-list probe.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| baseUrl | string | "" | The server's OpenAI-compatible base URL, or empty for the configured mlx endpoint. |
Returns: boolean
Needs: network
(source)
refreshCatalog
refreshCatalog(url: string = ""): RefreshResultRefresh 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:
| Name | Type | Default | Description |
|---|---|---|---|
| url | string | "" | Leave empty to use AGENCY_MODEL_CATALOG_URL, then client.modelCatalogUrl, then the built-in catalog URL. |
Returns: RefreshResult
Needs: fileRead, fileWrite, network
(source)