Files
LocalAI/pkg/mcp/localaitools/tools.go
Richard Palethorpe eb32cd9073 feat(realtime): eager blocking pipeline warm-up + /backend/load API (#10662)
Realtime sessions previously lazy-loaded each pipeline sub-model (VAD,
transcription, LLM, TTS) on first use, so every cold session paid a
per-request model-load stall and load errors only surfaced mid-stream.

Warm the whole pipeline eagerly and blockingly at session start
(including the voice-gate speaker-recognition model, which an enforced
gate blocks each utterance on; compaction's summary_model stays lazy
since it only runs off the response path):
- Add backend.PreloadModel / PreloadModelByName as the single load path
  for every modality (no transcription special-case; backend-omitted
  configs are deprecated).
- The realtime session blocks on Model.Warmup and returns a
  model_load_error to the client if any stage fails to load;
  updateSession warms in the background. Opt out per pipeline with
  pipeline.disable_warmup, exposed as a UI toggle via the
  config-metadata registry.

Add a LocalAI-native POST /backend/load (and /v1/backend/load) that
pre-loads a model -- expanding realtime pipelines into their sub-models
-- as the inverse of /backend/shutdown. There is one preload engine
(backend.PreloadStages): the realtime Warmup methods, /backend/load and
the --load-to-memory startup flag all use it, so --load-to-memory now
also expands pipeline models and records load-failure traces. Pipeline
sub-model alias resolution is likewise shared
(ModelConfigLoader.LoadResolvedModelConfig). Surface the endpoint
everywhere an admin manages models:
- MCP admin tool load_model (httpapi + inproc clients, safety/catalog
  prompts, catalog/dispatch tests).
- "Load into memory" action in the React models UI.
- Swagger regenerated; docs moved to the general backend-monitor page
  since it is not realtime-specific.

Fix a Traces UI crash ("json: unsupported value: -Inf"): audio-snippet
RMS/peak now floor at a finite dBFS, and backend-trace data is sanitized
to drop non-finite floats before marshaling. The sanitizer is
copy-on-write -- it runs on every RecordBackendTrace, so containers are
only re-allocated on the paths that actually changed.

Migrate core/http/openresponses_test.go onto the prebuilt mock-backend
the rest of the http suite already uses -- it was the last spec still
pointing at a real HuggingFace model, so it 404'd wherever no vision
backend was built -- and fix its item_reference specs to send the
spec's "id" field instead of "item_id", which the handler never
accepted.

Assisted-by: Claude:claude-opus-4-8 Claude Code

Signed-off-by: Richard Palethorpe <io@richiejp.com>
2026-07-03 18:00:37 +02:00

51 lines
2.1 KiB
Go

package localaitools
// Tool names exposed by the LocalAI Assistant MCP server. Use these
// constants — never bare strings — when registering tools, asserting the
// catalog in tests, or referencing tool names from other packages. The
// embedded skill prompts under prompts/ keep the bare strings because
// go:embed-ed markdown can't reference Go constants; TestPromptsContain
// SafetyAnchors guards that those strings stay aligned.
const (
// Read-only tools.
ToolGallerySearch = "gallery_search"
ToolListInstalledModels = "list_installed_models"
ToolListGalleries = "list_galleries"
ToolGetJobStatus = "get_job_status"
ToolGetModelConfig = "get_model_config"
ToolListBackends = "list_backends"
ToolListKnownBackends = "list_known_backends"
ToolSystemInfo = "system_info"
ToolListNodes = "list_nodes"
ToolVRAMEstimate = "vram_estimate"
ToolGetBranding = "get_branding"
ToolGetUsageStats = "get_usage_stats"
ToolGetPIIEvents = "get_pii_events"
ToolGetMiddlewareStatus = "get_middleware_status"
ToolGetRouterDecisions = "get_router_decisions"
// Mutating tools — guarded by Options.DisableMutating and the
// LLM-side safety prompt (see prompts/10_safety.md).
ToolInstallModel = "install_model"
ToolImportModelURI = "import_model_uri"
ToolDeleteModel = "delete_model"
ToolEditModelConfig = "edit_model_config"
ToolReloadModels = "reload_models"
ToolLoadModel = "load_model"
ToolInstallBackend = "install_backend"
ToolUpgradeBackend = "upgrade_backend"
ToolToggleModelState = "toggle_model_state"
ToolToggleModelPinned = "toggle_model_pinned"
ToolSetBranding = "set_branding"
ToolSetAlias = "set_alias"
// ToolListAliases is read-only but lives here so the alias tools stay
// grouped; the catalog tests assert its read-only placement.
ToolListAliases = "list_aliases"
)
// DefaultServerName is the MCP Implementation.Name surfaced when
// Options.ServerName is empty. Use the constant when you want a stable
// reference across packages (e.g. test fixtures, CLI defaults).
const DefaultServerName = "localai-admin"