feat(agent): add LM Studio as first-class provider (salvage #17061)#17102
Merged
Conversation
bced623 to
36131c5
Compare
- Remove dead _lmstudio_loaded_context attribute from run_agent.py (set but never read — the loaded context is pushed to context_compressor.update_model which is the actual consumer) - Cache empty reasoning options with 60s TTL to avoid per-turn HTTP probe for non-reasoning LM Studio models. Non-empty results cached permanently. - Extract _lmstudio_server_root(), _lmstudio_request_headers(), and _lmstudio_fetch_raw_models() shared helpers in models.py — eliminates URL-strip + auth-header + HTTP-call duplication across probe_lmstudio_models, ensure_lmstudio_model_loaded, and lmstudio_model_reasoning_options - Revert runtime_provider.py base_url precedence change: preserve the established contract (saved config.base_url > env var > default) for all api_key providers - Remove unnecessary config version bump 22→23 - Fix TUI test: relax target_model assertion to avoid module-cache flake - AUTHOR_MAP: added rugved@lmstudio.ai → rugvedS07
36131c5 to
ca8f414
Compare
17 tasks
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Salvage of #17061 by @rugvedS07 — promotes LM Studio from a
"custom"provider alias to a first-class provider with JIT model loading, reasoning effort negotiation, and no-auth support.Cherry-picked all 5 contributor commits onto current
mainwith follow-up fixes from self-review.What this PR does
From the contributor (#17061)
PROVIDER_REGISTRY,HERMES_OVERLAYS, aliases (lmstudio,lm-studio,lm_studio) now resolve to"lmstudio"instead of"custom"/api/v1/modelsendpoint (filters embedding models)POST /api/v1/models/load— automatically loads the selected model with at least 64K context if not already loaded with sufficient context, capped atmax_context_lengthcapabilities.reasoning.allowed_optionsfrom LM Studio and clamps the user's reasoning config to what the model supports. Sharedresolve_lmstudio_effort()keeps transport and summary paths in syncLMSTUDIO_NOAUTH_PLACEHOLDERfor users running LM Studio without auth enabled/modelautocomplete with cached LM Studio model list (30s TTL, gated on LM Studio config)hermes statusshows LM Studio reachability and model countcontext_lengthanytime)Follow-up fixes (from self-review)
_lmstudio_loaded_contextset but never read inrun_agent.pycontext_compressor.update_model()is the actual consumermodels.py_lmstudio_server_root(),_lmstudio_request_headers(),_lmstudio_fetch_raw_models()shared helperstest_make_agent_passes_resolved_providertarget_modelassertion to avoid module-cache ordering issuerugved@lmstudio.airugvedS07Scoped out from the original PR
Config version bump 22→23 removed. The original PR added a migration that wrote
LM_API_KEY=dummy-lm-api-keyto.envwhenprovider: lmstudiowas set in config.yaml. This is unnecessary —resolve_api_key_provider_credentials()already substitutesLMSTUDIO_NOAUTH_PLACEHOLDERat runtime when no key is found. The migration would write a fake credential to.env(which is for secrets only), confuse users who inspect it, and create a maintenance asymmetry if the placeholder value ever changes. The runtime fallback covers all code paths (CLI, gateway, TUI, cron, auxiliary_client).runtime_provider.pybase URL precedence change reverted. The original PR changed the base URL resolution for allapi_keyproviders (not just LM Studio) — flipping priority fromconfig > env > defaulttoenv > config > defaultwhen bothmodel.base_urlin config AND the provider-specific env var (e.g.GLM_BASE_URL,LM_BASE_URL,KIMI_BASE_URL) are set. This affected ~30 providers (ZAI, MiniMax, Kimi, DeepSeek, HF, NVIDIA, etc.) for the sake of one LM Studio edge case. Reverted to preserve the established contract — LM Studio works correctly with the original logic sinceresolve_api_key_provider_credentialsalready incorporatesLM_BASE_URLintocreds["base_url"], and savedmodel.base_urlfrom config properly overrides the registry default.API stability
All LM Studio endpoints used are officially documented v1 API (stable since LM Studio 0.4.0):
GET /api/v1/models— model listing with capabilitiesPOST /api/v1/models/loadwithcontext_lengthparamcapabilities.reasoning.allowed_options— documented since v0.3.16No competing agent (Continue, Cline, OpenCode, Aider) implements JIT model loading or reasoning negotiation — this is novel.
Test plan
Based on PR #17061 by @rugvedS07.